[saco] Implement/match CEntity::GetDistanceFromLocalPlayerPed()

* Update CLocalPlayer constructor
* Update `CLocalPlayer::ResetAllSyncAttributes()`
This commit is contained in:
RD42
2024-08-07 19:01:32 +08:00
parent c0b2e2689b
commit 669437e30b
4 changed files with 42 additions and 5 deletions

View File

@ -230,6 +230,39 @@ void CEntity::TeleportTo(float x, float y, float z)
//-----------------------------------------------------------
float CEntity::GetDistanceFromLocalPlayerPed()
{
MATRIX4X4 matFromPlayer;
MATRIX4X4 matThis;
float fSX,fSY,fSZ;
CPlayerPed *pLocalPlayerPed = pGame->FindPlayerPed();
CLocalPlayer *pLocalPlayer=NULL;
if(!pLocalPlayerPed) return 10000.0f;
GetMatrix(&matThis);
if(pNetGame) {
pLocalPlayer = pNetGame->GetPlayerPool()->GetLocalPlayer();
if(pLocalPlayer && (pLocalPlayer->IsSpectating() || pLocalPlayer->IsInRCMode())) {
pGame->GetCamera()->GetMatrix(&matFromPlayer);
} else {
pLocalPlayerPed->GetMatrix(&matFromPlayer);
}
} else {
pLocalPlayerPed->GetMatrix(&matFromPlayer);
}
fSX = (matThis.pos.X - matFromPlayer.pos.X) * (matThis.pos.X - matFromPlayer.pos.X);
fSY = (matThis.pos.Y - matFromPlayer.pos.Y) * (matThis.pos.Y - matFromPlayer.pos.Y);
fSZ = (matThis.pos.Z - matFromPlayer.pos.Z) * (matThis.pos.Z - matFromPlayer.pos.Z);
return (float)sqrt(fSX + fSY + fSZ);
}
//-----------------------------------------------------------
float CEntity::GetDistanceFromPoint(float X, float Y, float Z)
{
MATRIX4X4 matThis;

View File

@ -25,6 +25,7 @@ public:
void GetBoundRect(PFRECT Rect); // unused
UINT GetModelIndex();
void TeleportTo(float x, float y, float z);
float GetDistanceFromLocalPlayerPed();
float GetDistanceFromPoint(float X, float Y, float Z);
BOOL IsStationary();

View File

@ -10,7 +10,7 @@ CLocalPlayer::CLocalPlayer()
field_147 = GetTickCount();
field_137 = GetTickCount();
field_13B = GetTickCount();
field_1D0 = 0;
m_bInRCMode = FALSE;
field_2E2 = 0;
field_2D6 = GetTickCount();
field_2F6 = 0;
@ -24,7 +24,7 @@ CLocalPlayer::CLocalPlayer()
field_13F = GetTickCount();
field_117 = field_10F;
field_11B = field_10F;
field_108 = 0;
m_bIsSpectating = FALSE;
field_30F = 0;
field_310 = -1;
field_306 = 0;
@ -51,7 +51,7 @@ void CLocalPlayer::ResetAllSyncAttributes()
field_2FE = 0;
field_1CF = 0;
field_FA = -1;
field_1D0 = 0;
m_bInRCMode = FALSE;
field_318 = -1;
field_11F = -1;
field_121 = -1;

View File

@ -23,7 +23,7 @@ public:
int field_FC;
int field_100;
CPlayerPed *m_pPlayerPed;
int field_108;
BOOL m_bIsSpectating;
char field_10C;
short field_10D;
DWORD field_10F;
@ -59,7 +59,7 @@ public:
char _gap1CB[4];
char field_1CF;
int field_1D0;
BOOL m_bInRCMode;
char _gap1D4[258];
@ -94,6 +94,9 @@ public:
void Say(PCHAR szText);
BOOL IsSpectating() { return m_bIsSpectating; };
BOOL IsInRCMode() { return m_bInRCMode; };
};
//----------------------------------------------------------