Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions Client/mods/deathmatch/logic/CClientPed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4673,12 +4673,20 @@ float CClientPed::GetDistanceFromGround()
return (vecPosition.fZ - fGroundLevel);
}

bool CClientPed::IsOnGround()
bool CClientPed::IsOnGround(bool checkVehicles)
{
CVector vecPosition;
GetPosition(vecPosition);
float fGroundLevel = static_cast<float>(g_pGame->GetWorld()->FindGroundZFor3DPosition(&vecPosition));
return (vecPosition.fZ > fGroundLevel && (vecPosition.fZ - fGroundLevel) <= 1.0f);

if (DefinitelyLessThan(vecPosition.fZ, fGroundLevel))
return false;

bool isOnGround = DefinitelyLessThan((vecPosition.fZ - fGroundLevel), 1.0f) || EssentiallyEqual((vecPosition.fZ - fGroundLevel), 1.0f);
if (!isOnGround && checkVehicles && m_pPlayerPed)
return m_pPlayerPed->IsStandingOnEntity();

return isOnGround;
}

bool CClientPed::IsClimbing()
Expand Down
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/CClientPed.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule

void SetInWater(bool bIsInWater) { m_bIsInWater = bIsInWater; };
bool IsInWater();
bool IsOnGround();
bool IsOnGround(bool checkVehicles = false);

bool IsClimbing();
bool IsRadioOn() const noexcept { return m_bRadioOn; };
Expand Down
4 changes: 3 additions & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,13 +914,15 @@ int CLuaPedDefs::IsPedOnGround(lua_State* luaVM)
{
// Verify the argument
CClientPed* pPed = NULL;
bool checkVehicles = false;
CScriptArgReader argStream(luaVM);
argStream.ReadUserData(pPed);
argStream.ReadBool(checkVehicles, false);

if (!argStream.HasErrors())
{
// Find out whether he's on the ground or not and return it
bool bOnGround = pPed->IsOnGround();
bool bOnGround = pPed->IsOnGround(checkVehicles);
lua_pushboolean(luaVM, bOnGround);
return 1;
}
Expand Down
21 changes: 21 additions & 0 deletions Shared/sdk/SharedUtil.Math.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,25 @@ namespace SharedUtil
{
return std::fabs(a - b) <= epsilon;
}

inline bool ApproximatelyEqual(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
{
return std::fabs(a - b) <= std::max(std::fabs(a), std::fabs(b)) * epsilon;
}

inline bool EssentiallyEqual(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
{
return std::fabs(a - b) <= std::min(std::fabs(a), std::fabs(b)) * epsilon;
}

inline bool DefinitelyGreaterThan(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
{
return (a - b) > std::max(std::fabs(a), std::fabs(b)) * epsilon;
}

inline bool DefinitelyLessThan(float a, float b, float epsilon = std::numeric_limits<float>().epsilon()) noexcept
{
return (b - a) > std::max(std::fabs(a), std::fabs(b)) * epsilon;
}

} // namespace SharedUtil
Loading