Skip to content

Commit 257f4cd

Browse files
authored
Fix isPedOnGround (#4317)
1 parent 88ca35e commit 257f4cd

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

Client/mods/deathmatch/logic/CClientPed.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4673,12 +4673,20 @@ float CClientPed::GetDistanceFromGround()
46734673
return (vecPosition.fZ - fGroundLevel);
46744674
}
46754675

4676-
bool CClientPed::IsOnGround()
4676+
bool CClientPed::IsOnGround(bool checkVehicles)
46774677
{
46784678
CVector vecPosition;
46794679
GetPosition(vecPosition);
46804680
float fGroundLevel = static_cast<float>(g_pGame->GetWorld()->FindGroundZFor3DPosition(&vecPosition));
4681-
return (vecPosition.fZ > fGroundLevel && (vecPosition.fZ - fGroundLevel) <= 1.0f);
4681+
4682+
if (DefinitelyLessThan(vecPosition.fZ, fGroundLevel))
4683+
return false;
4684+
4685+
bool isOnGround = DefinitelyLessThan((vecPosition.fZ - fGroundLevel), 1.0f) || EssentiallyEqual((vecPosition.fZ - fGroundLevel), 1.0f);
4686+
if (!isOnGround && checkVehicles && m_pPlayerPed)
4687+
return m_pPlayerPed->IsStandingOnEntity();
4688+
4689+
return isOnGround;
46824690
}
46834691

46844692
bool CClientPed::IsClimbing()

Client/mods/deathmatch/logic/CClientPed.h

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

381381
void SetInWater(bool bIsInWater) { m_bIsInWater = bIsInWater; };
382382
bool IsInWater();
383-
bool IsOnGround();
383+
bool IsOnGround(bool checkVehicles = false);
384384

385385
bool IsClimbing();
386386
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
}

Shared/sdk/SharedUtil.Math.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,25 @@ namespace SharedUtil
118118
{
119119
return std::fabs(a - b) <= epsilon;
120120
}
121+
122+
inline bool ApproximatelyEqual(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
123+
{
124+
return std::fabs(a - b) <= std::max(std::fabs(a), std::fabs(b)) * epsilon;
125+
}
126+
127+
inline bool EssentiallyEqual(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
128+
{
129+
return std::fabs(a - b) <= std::min(std::fabs(a), std::fabs(b)) * epsilon;
130+
}
131+
132+
inline bool DefinitelyGreaterThan(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
133+
{
134+
return (a - b) > std::max(std::fabs(a), std::fabs(b)) * epsilon;
135+
}
136+
137+
inline bool DefinitelyLessThan(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
138+
{
139+
return (b - a) > std::max(std::fabs(a), std::fabs(b)) * epsilon;
140+
}
141+
121142
} // namespace SharedUtil

0 commit comments

Comments
 (0)