Skip to content

Commit 88c3240

Browse files
committed
Fix isPedOnGround
1 parent a79a764 commit 88c3240

File tree

7 files changed

+42
-4
lines changed

7 files changed

+42
-4
lines changed

Client/game_sa/CPedSA.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA
421421
void SetFightingStyle(eFightingStyle style, std::uint8_t styleExtra = 6) override;
422422

423423
CEntity* GetContactEntity() const override;
424+
bool IsStandingOnEntity() const override { return GetPedInterface()->pContactEntity != nullptr; };
424425

425426
int GetRunState() const override { return GetPedInterface()->moveState; }
426427

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4649,12 +4649,20 @@ float CClientPed::GetDistanceFromGround()
46494649
return (vecPosition.fZ - fGroundLevel);
46504650
}
46514651

4652-
bool CClientPed::IsOnGround()
4652+
bool CClientPed::IsOnGround(bool checkVehicles)
46534653
{
46544654
CVector vecPosition;
46554655
GetPosition(vecPosition);
46564656
float fGroundLevel = static_cast<float>(g_pGame->GetWorld()->FindGroundZFor3DPosition(&vecPosition));
4657-
return (vecPosition.fZ > fGroundLevel && (vecPosition.fZ - fGroundLevel) <= 1.0f);
4657+
4658+
if (definitelyLessThan(vecPosition.fZ, fGroundLevel))
4659+
return false;
4660+
4661+
bool isOnGround = definitelyLessThan((vecPosition.fZ - fGroundLevel), 1.0f) || essentiallyEqual((vecPosition.fZ - fGroundLevel), 1.0f);
4662+
if (!isOnGround && checkVehicles && m_pPlayerPed)
4663+
return m_pPlayerPed->IsStandingOnEntity();
4664+
4665+
return isOnGround;
46584666
}
46594667

46604668
bool CClientPed::IsClimbing()

Client/mods/deathmatch/logic/CClientPed.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule
374374

375375
void SetInWater(bool bIsInWater) { m_bIsInWater = bIsInWater; };
376376
bool IsInWater();
377-
bool IsOnGround();
377+
bool IsOnGround(bool checkVehicles = false);
378378

379379
bool IsClimbing();
380380
bool IsRadioOn() const noexcept { return m_bRadioOn; };

Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -914,13 +914,15 @@ int CLuaPedDefs::IsPedOnGround(lua_State* luaVM)
914914
{
915915
// Verify the argument
916916
CClientPed* pPed = NULL;
917+
bool checkVehicles = false;
917918
CScriptArgReader argStream(luaVM);
918919
argStream.ReadUserData(pPed);
920+
argStream.ReadBool(checkVehicles, false);
919921

920922
if (!argStream.HasErrors())
921923
{
922924
// Find out whether he's on the ground or not and return it
923-
bool bOnGround = pPed->IsOnGround();
925+
bool bOnGround = pPed->IsOnGround(checkVehicles);
924926
lua_pushboolean(luaVM, bOnGround);
925927
return 1;
926928
}

Client/sdk/game/CPed.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class CPed : public virtual CPhysical
253253
virtual void SetFightingStyle(eFightingStyle style, std::uint8_t styleExtra) = 0;
254254

255255
virtual CEntity* GetContactEntity() const = 0;
256+
virtual bool IsStandingOnEntity() const = 0;
256257

257258
virtual int GetRunState() const = 0;
258259

Shared/mods/deathmatch/logic/Utils.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1107,3 +1107,23 @@ CVector ConvertEulerRotationOrder(const CVector& a_vRotation, eEulerRotationOrde
11071107
return a_vRotation;
11081108
}
11091109
}
1110+
1111+
bool approximatelyEqual(float a, float b, float epsilon)
1112+
{
1113+
return std::fabs(a - b) <= std::max(std::fabs(a), std::fabs(b)) * epsilon;
1114+
}
1115+
1116+
bool essentiallyEqual(float a, float b, float epsilon)
1117+
{
1118+
return std::fabs(a - b) <= std::min(std::fabs(a), std::fabs(b)) * epsilon;
1119+
}
1120+
1121+
bool definitelyGreaterThan(float a, float b, float epsilon)
1122+
{
1123+
return (a - b) > std::max(std::fabs(a), std::fabs(b)) * epsilon;
1124+
}
1125+
1126+
bool definitelyLessThan(float a, float b, float epsilon)
1127+
{
1128+
return (b - a) > std::max(std::fabs(a), std::fabs(b)) * epsilon;
1129+
}

Shared/mods/deathmatch/logic/Utils.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,9 @@ void DeletePointersAndClearList(T& elementList)
336336
delete *iter;
337337
}
338338
}
339+
340+
// Comparing floating point numbers
341+
bool approximatelyEqual(float a, float b, float epsilon = FLOAT_EPSILON);
342+
bool essentiallyEqual(float a, float b, float epsilon = FLOAT_EPSILON);
343+
bool definitelyGreaterThan(float a, float b, float epsilon = FLOAT_EPSILON);
344+
bool definitelyLessThan(float a, float b, float epsilon = FLOAT_EPSILON);

0 commit comments

Comments
 (0)