From b22ed0c59551bd3c9cbe74c36633ea05b9642415 Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:07:40 +0100 Subject: [PATCH 1/6] Client game_sa --- Client/game_sa/CPedSA.cpp | 6 +++--- Client/game_sa/CPedSA.h | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Client/game_sa/CPedSA.cpp b/Client/game_sa/CPedSA.cpp index 3818e0cb4d1..79c00d37fff 100644 --- a/Client/game_sa/CPedSA.cpp +++ b/Client/game_sa/CPedSA.cpp @@ -259,14 +259,14 @@ void CPedSA::SetHealth(float fHealth) GetPedInterface()->fHealth = fHealth; } -float CPedSA::GetArmor() +float CPedSA::GetArmor() noexcept { return GetPedInterface()->fArmor; } -void CPedSA::SetArmor(float fArmor) +void CPedSA::SetArmor(float armor) noexcept { - GetPedInterface()->fArmor = fArmor; + GetPedInterface()->fArmor = armor; } float CPedSA::GetOxygenLevel() diff --git a/Client/game_sa/CPedSA.h b/Client/game_sa/CPedSA.h index 99898354729..110fabea960 100644 --- a/Client/game_sa/CPedSA.h +++ b/Client/game_sa/CPedSA.h @@ -313,8 +313,8 @@ class CPedSA : public virtual CPed, public virtual CPhysicalSA float GetHealth(); void SetHealth(float fHealth); - float GetArmor(); - void SetArmor(float fArmor); + float GetArmor() noexcept; + void SetArmor(float armor) noexcept; float GetOxygenLevel(); void SetOxygenLevel(float fOxygen); From b413c2feb0497442e783e9995aedeaeecdd22d16 Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:08:02 +0100 Subject: [PATCH 2/6] Client logic --- Client/mods/deathmatch/logic/CClientGame.cpp | 6 +-- Client/mods/deathmatch/logic/CClientPed.cpp | 45 +++++++++---------- Client/mods/deathmatch/logic/CClientPed.h | 14 +++--- .../mods/deathmatch/logic/CClientPlayer.cpp | 6 +-- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/Client/mods/deathmatch/logic/CClientGame.cpp b/Client/mods/deathmatch/logic/CClientGame.cpp index f195dceaadb..e8603934722 100644 --- a/Client/mods/deathmatch/logic/CClientGame.cpp +++ b/Client/mods/deathmatch/logic/CClientGame.cpp @@ -4371,7 +4371,7 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage, { float fPreviousHealth = pDamagedPed->m_fHealth; float fCurrentHealth = pDamagedPed->GetGamePlayer()->GetHealth(); - float fPreviousArmor = pDamagedPed->m_fArmor; + float fPreviousArmor = pDamagedPed->m_armor; float fCurrentArmor = pDamagedPed->GetGamePlayer()->GetArmor(); // Have we taken any damage here? @@ -4407,7 +4407,7 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage, { // Reget values in case they have been changed during onClientPlayerDamage event (Avoid AC#1 kick) fPreviousHealth = pDamagedPed->m_fHealth; - fPreviousArmor = pDamagedPed->m_fArmor; + fPreviousArmor = pDamagedPed->m_armor; } pDamagedPed->GetGamePlayer()->SetHealth(fPreviousHealth); pDamagedPed->GetGamePlayer()->SetArmor(fPreviousArmor); @@ -4453,7 +4453,7 @@ bool CClientGame::ApplyPedDamageFromGame(eWeaponType weaponUsed, float fDamage, // Update our stored health/armor pDamagedPed->m_fHealth = fCurrentHealth; - pDamagedPed->m_fArmor = fCurrentArmor; + pDamagedPed->m_armor = fCurrentArmor; ElementID damagerID = INVALID_ELEMENT_ID; if (pInflictingEntity && !pInflictingEntity->IsLocalEntity()) diff --git a/Client/mods/deathmatch/logic/CClientPed.cpp b/Client/mods/deathmatch/logic/CClientPed.cpp index c849a0b8a73..5637800213d 100644 --- a/Client/mods/deathmatch/logic/CClientPed.cpp +++ b/Client/mods/deathmatch/logic/CClientPed.cpp @@ -129,7 +129,7 @@ void CClientPed::Init(CClientManager* pManager, unsigned long ulModelID, bool bI m_uiOccupiedVehicleSeat = 0xFF; m_bHealthLocked = false; m_bDontChangeRadio = false; - m_bArmorLocked = false; + m_armorLocked = false; m_ulLastOnScreenTime = 0; m_pLoadedModelInfo = NULL; m_pOutOfVehicleWeaponSlot = WEAPONSLOT_MAX; // WEAPONSLOT_MAX = invalid @@ -157,7 +157,7 @@ void CClientPed::Init(CClientManager* pManager, unsigned long ulModelID, bool bI m_bVisible = true; m_bUsesCollision = true; m_fHealth = 100.0f; - m_fArmor = 0.0f; + m_armor = 0.0f; m_bDead = false; m_bWorldIgnored = false; m_fCurrentRotation = 0.0f; @@ -1793,29 +1793,28 @@ void CClientPed::InternalSetHealth(float fHealth) } } -float CClientPed::GetArmor() +float CClientPed::GetArmor() const noexcept { - if (m_bArmorLocked) - return m_fArmor; + if (m_armorLocked) + return m_armor; if (m_pPlayerPed) - { return m_pPlayerPed->GetArmor(); - } - return m_fArmor; + + return m_armor; } -void CClientPed::SetArmor(float fArmor) +void CClientPed::SetArmor(float armor) noexcept { - // If our armor is locked, dont allow any change - if (m_bArmorLocked) + if (m_armorLocked) return; + armor = std::clamp(armor, 0.0f, 100.0f); + if (m_pPlayerPed) - { - m_pPlayerPed->SetArmor(fArmor); - } - m_fArmor = fArmor; + m_pPlayerPed->SetArmor(armor); + + m_armor = armor; } void CClientPed::LockHealth(float fHealth) @@ -1824,10 +1823,10 @@ void CClientPed::LockHealth(float fHealth) m_fHealth = fHealth; } -void CClientPed::LockArmor(float fArmor) +void CClientPed::LockArmor(float armor) noexcept { - m_bArmorLocked = true; - m_fArmor = fArmor; + m_armorLocked = true; + m_armor = armor; } float CClientPed::GetOxygenLevel() @@ -2772,9 +2771,9 @@ void CClientPed::StreamedInPulse(bool bDoStandardPulses) } // Is our armor locked? - if (m_bArmorLocked) + if (m_armorLocked) { - m_pPlayerPed->SetArmor(m_fArmor); + m_pPlayerPed->SetArmor(m_armor); } // In a vehicle? @@ -3623,7 +3622,7 @@ void CClientPed::_CreateModel() m_pPlayerPed->SetVisible(m_bVisible); m_pPlayerPed->SetUsesCollision(m_bUsesCollision); m_pPlayerPed->SetHealth(m_fHealth); - m_pPlayerPed->SetArmor(m_fArmor); + m_pPlayerPed->SetArmor(m_armor); m_pPlayerPed->SetLighting(m_fLighting); WorldIgnore(m_bWorldIgnored); @@ -4225,10 +4224,10 @@ bool CClientPed::PerformChecks() // The player should not be able to gain any health/armor without us knowing.. // meaning all health/armor giving must go through SetHealth/SetArmor. if ((m_fHealth > 0.0f && m_pPlayerPed->GetHealth() > m_fHealth + FLOAT_EPSILON) || - (m_fArmor < 100.0f && m_pPlayerPed->GetArmor() > m_fArmor + FLOAT_EPSILON)) + (m_armor < 100.0f && m_pPlayerPed->GetArmor() > m_armor + FLOAT_EPSILON)) { g_pCore->GetConsole()->Printf("healthCheck: %f %f", m_pPlayerPed->GetHealth(), m_fHealth); - g_pCore->GetConsole()->Printf("armorCheck: %f %f", m_pPlayerPed->GetArmor(), m_fArmor); + g_pCore->GetConsole()->Printf("armorCheck: %f %f", m_pPlayerPed->GetArmor(), m_armor); return false; } // Perform the checks in CGame diff --git a/Client/mods/deathmatch/logic/CClientPed.h b/Client/mods/deathmatch/logic/CClientPed.h index f76f69d17a7..576c967ad4d 100644 --- a/Client/mods/deathmatch/logic/CClientPed.h +++ b/Client/mods/deathmatch/logic/CClientPed.h @@ -267,17 +267,17 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule float GetHealth(); void SetHealth(float fHealth); void InternalSetHealth(float fHealth); - float GetArmor(); - void SetArmor(float fArmor); + float GetArmor() const noexcept; + void SetArmor(float armor) noexcept; float GetOxygenLevel(); void SetOxygenLevel(float fOxygen); void LockHealth(float fHealth); - void LockArmor(float fArmor); + void LockArmor(float armor) noexcept; void UnlockHealth() noexcept { m_bHealthLocked = false; }; - void UnlockArmor() noexcept { m_bArmorLocked = false; }; + void UnlockArmor() noexcept { m_armorLocked = false; }; bool IsHealthLocked() const noexcept { return m_bHealthLocked; }; - bool IsArmorLocked() const noexcept { return m_bArmorLocked; }; + bool IsArmorLocked() const noexcept { return m_armorLocked; }; bool IsDying(); bool IsDead(); @@ -619,7 +619,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule bool m_bRadioOn; unsigned char m_ucRadioChannel; bool m_bHealthLocked; - bool m_bArmorLocked; + bool m_armorLocked; unsigned long m_ulLastOnScreenTime; CClientVehiclePtr m_pOccupiedVehicle; CClientVehiclePtr m_pOccupyingVehicle; @@ -678,7 +678,7 @@ class CClientPed : public CClientStreamElement, public CAntiCheatModule bool m_bVisible; bool m_bUsesCollision; float m_fHealth; - float m_fArmor; + float m_armor; bool m_bDead; bool m_bWorldIgnored; float m_fCurrentRotation; diff --git a/Client/mods/deathmatch/logic/CClientPlayer.cpp b/Client/mods/deathmatch/logic/CClientPlayer.cpp index e924c294936..4669e2ef715 100644 --- a/Client/mods/deathmatch/logic/CClientPlayer.cpp +++ b/Client/mods/deathmatch/logic/CClientPlayer.cpp @@ -311,13 +311,13 @@ void CClientPlayer::DischargeWeapon(eWeaponType weaponType, const CVector& vecSt // CPlayerPed has post damage health/armor float fPreviousHealth = pBackupDamagedPlayer->m_fHealth; - float fPreviousArmor = pBackupDamagedPlayer->m_fArmor; + float fPreviousArmor = pBackupDamagedPlayer->m_armor; // Calculate how much damage should be applied to health/armor - float fArmorDamage = std::min(fBackupDamage, pBackupDamagedPlayer->m_fArmor); + float fArmorDamage = std::min(fBackupDamage, pBackupDamagedPlayer->m_armor); float fHealthDamage = std::min(fBackupDamage - fArmorDamage, pBackupDamagedPlayer->m_fHealth); - float fNewArmor = pBackupDamagedPlayer->m_fArmor - fArmorDamage; + float fNewArmor = pBackupDamagedPlayer->m_armor - fArmorDamage; float fNewHealth = pBackupDamagedPlayer->m_fHealth - fHealthDamage; // Ensure CPlayerPed has post damage health/armor From 751341286e5bcdd268fd4303781997e33d4f14dc Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:08:12 +0100 Subject: [PATCH 3/6] Client defs --- .../logic/luadefs/CLuaCompatibilityDefs.cpp | 2 +- .../deathmatch/logic/luadefs/CLuaPedDefs.cpp | 29 ++++++------------- .../deathmatch/logic/luadefs/CLuaPedDefs.h | 2 +- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp index 7dea8f95bf5..b482a92a278 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp @@ -37,7 +37,7 @@ void CLuaCompatibilityDefs::LoadFunctions() {"getPlayerTotalAmmo", CLuaPedDefs::GetPedTotalAmmo}, {"getPedWeaponMuzzlePosition", CLuaPedDefs::GetPedWeaponMuzzlePosition}, {"getPlayerOccupiedVehicle", CLuaPedDefs::GetPedOccupiedVehicle}, - {"getPlayerArmor", CLuaPedDefs::GetPedArmor}, + {"getPlayerArmor", ArgumentParserWarn}, {"getPlayerSkin", CLuaElementDefs::GetElementModel}, {"isPlayerChoking", CLuaPedDefs::IsPedChoking}, {"isPlayerDucked", CLuaPedDefs::IsPedDucked}, diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 34040db19e1..5c16634606d 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -87,7 +87,7 @@ void CLuaPedDefs::LoadFunctions() {"getPedStat", GetPedStat}, {"getPedOxygenLevel", GetPedOxygenLevel}, - {"getPedArmor", GetPedArmor}, + {"getPedArmor", ArgumentParserWarn}, {"isPedBleeding", ArgumentParser}, {"getPedContactElement", GetPedContactElement}, @@ -784,26 +784,9 @@ int CLuaPedDefs::OOP_GetPedTargetCollision(lua_State* luaVM) return 1; } -int CLuaPedDefs::GetPedArmor(lua_State* luaVM) +float CLuaPedDefs::GetPedArmor(CClientPed* const ped) noexcept { - // Verify the argument - CClientPed* pPed = NULL; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPed); - - if (!argStream.HasErrors()) - { - // Grab the armor and return it - float fArmor = pPed->GetArmor(); - lua_pushnumber(luaVM, fArmor); - return 1; - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - // Failed - lua_pushboolean(luaVM, false); - return 1; + return ped->GetArmor(); } int CLuaPedDefs::GetPedStat(lua_State* luaVM) @@ -2395,6 +2378,12 @@ int CLuaPedDefs::SetPedMoveAnim(lua_State* luaVM) bool CLuaPedDefs::SetPedArmor(CClientPed* const ped, const float armor) { + if (armor < 0.0f) + throw std::invalid_argument("Armor must be greater than or equal to 0"); + + if (armor > 100.0f) + throw std::invalid_argument("Armor must be less than or equal to 100"); + ped->SetArmor(armor); return true; } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 0d9cc3500c7..89d0cb94fbd 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -38,7 +38,7 @@ class CLuaPedDefs : public CLuaDefs LUA_DECLARE(GetPedStat); LUA_DECLARE(GetPedOccupiedVehicle); LUA_DECLARE(GetPedOccupiedVehicleSeat); - LUA_DECLARE(GetPedArmor); + static float GetPedArmor(CClientPed* const ped) noexcept; LUA_DECLARE(IsPedChoking); LUA_DECLARE(IsPedDucked); LUA_DECLARE(IsPedInVehicle); From 16567062d31f3c1ca8708f88215582ffb61e1cb2 Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:08:17 +0100 Subject: [PATCH 4/6] Client SDK --- Client/sdk/game/CPed.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Client/sdk/game/CPed.h b/Client/sdk/game/CPed.h index fb66f4d56a3..b67148c2c0b 100644 --- a/Client/sdk/game/CPed.h +++ b/Client/sdk/game/CPed.h @@ -195,7 +195,7 @@ class CPed : public virtual CPhysical virtual float GetHealth() = 0; virtual void SetHealth(float fHealth) = 0; virtual float GetArmor() = 0; - virtual void SetArmor(float fArmor) = 0; + virtual void SetArmor(float armor) = 0; virtual float GetOxygenLevel() = 0; virtual void SetOxygenLevel(float fOxygen) = 0; virtual bool AddProjectile(eWeaponType eWeapon, CVector vecOrigin, float fForce, CVector* target, CEntity* targetEntity) = 0; From 589b74968607f8bdc6eef4f0f3329e260cd2d340 Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:08:34 +0100 Subject: [PATCH 5/6] Server logic --- Server/mods/deathmatch/logic/CPed.cpp | 4 +- Server/mods/deathmatch/logic/CPed.h | 6 +-- .../logic/CStaticFunctionDefinitions.cpp | 53 +++++++++---------- .../logic/CStaticFunctionDefinitions.h | 4 +- 4 files changed, 32 insertions(+), 35 deletions(-) diff --git a/Server/mods/deathmatch/logic/CPed.cpp b/Server/mods/deathmatch/logic/CPed.cpp index ba50c25caab..3be03316d30 100644 --- a/Server/mods/deathmatch/logic/CPed.cpp +++ b/Server/mods/deathmatch/logic/CPed.cpp @@ -38,7 +38,7 @@ CPed::CPed(CPedManager* pPedManager, CElement* pParent, unsigned short usModel) m_bWearingGoggles = false; m_fHealth = 0.0f; - m_fArmor = 0.0f; + m_armor = 0.0f; memset(&m_fStats[0], 0, sizeof(m_fStats)); m_fStats[24] = 569.0f; // default max_health @@ -239,7 +239,7 @@ bool CPed::ReadSpecialData(const int iLine) m_fHealth = 100.0f; // Grab the "armor" data - GetCustomDataFloat("armor", m_fArmor, true); + GetCustomDataFloat("armor", m_armor, true); // Grab the "interior" data if (GetCustomDataInt("interior", iTemp, true)) diff --git a/Server/mods/deathmatch/logic/CPed.h b/Server/mods/deathmatch/logic/CPed.h index f50aed2ae4e..063744484bb 100644 --- a/Server/mods/deathmatch/logic/CPed.h +++ b/Server/mods/deathmatch/logic/CPed.h @@ -193,8 +193,8 @@ class CPed : public CElement float GetMaxHealth(); float GetHealth() { return m_fHealth; } void SetHealth(float fHealth) { m_fHealth = fHealth; } - float GetArmor() { return m_fArmor; } - void SetArmor(float fArmor) { m_fArmor = fArmor; } + float GetArmor() const noexcept { return m_armor; } + void SetArmor(float armor) noexcept { m_armor = std::clamp(armor, 0.0f, 100.0f); } float GetPlayerStat(unsigned short usStat) { return (usStat < NUM_PLAYER_STATS) ? m_fStats[usStat] : 0; } void SetPlayerStat(unsigned short usStat, float fValue) @@ -317,7 +317,7 @@ class CPed : public CElement bool m_bWearingGoggles; bool m_bIsOnFire; float m_fHealth; - float m_fArmor; + float m_armor; SFixedArray m_fStats; CPlayerClothes* m_pClothes; bool m_bHasJetPack; diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index bd58cd84880..1db7dcc0618 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -3518,11 +3518,11 @@ bool CStaticFunctionDefinitions::RedirectPlayer(CElement* pElement, const char* } // ***************** PED GET FUNCS ***************** // -bool CStaticFunctionDefinitions::GetPedArmor(CPed* pPed, float& fArmor) +bool CStaticFunctionDefinitions::GetPedArmor(CPed* const ped, float& armor) { - assert(pPed); + assert(ped); - fArmor = pPed->GetArmor(); + armor = ped->GetArmor(); return true; } @@ -3675,39 +3675,36 @@ bool CStaticFunctionDefinitions::IsPedFrozen(CPed* pPed, bool& bIsFrozen) } // ************** PED SET FUNCS ************** // -bool CStaticFunctionDefinitions::SetPedArmor(CElement* pElement, float fArmor) +bool CStaticFunctionDefinitions::SetPedArmor(CElement* pElement, float armor) { assert(pElement); - // Make sure it's above 0 - if (fArmor >= 0.0f) - { - RUN_CHILDREN(SetPedArmor(*iter, fArmor)) + if (armor < 0.0f) + return false; - if (IS_PED(pElement)) - { - CPed* pPed = static_cast(pElement); - if (pPed->IsSpawned()) - { - // Limit it to 100.0 - if (fArmor > 100.0f) - fArmor = 100.0f; + RUN_CHILDREN(SetPedArmor(*iter, armor)) - pPed->SetArmor(fArmor); + if (!IS_PED(pElement)) + return false; - unsigned char ucArmor = static_cast(fArmor * 1.25); + CPed* ped = static_cast(pElement); - // Tell everyone - CBitStream BitStream; - BitStream.pBitStream->Write(ucArmor); - BitStream.pBitStream->Write(pPed->GenerateSyncTimeContext()); - m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(pPed, SET_PED_ARMOR, *BitStream.pBitStream)); - return true; - } - } - } + if (!ped->IsSpawned()) + return false; - return false; + if (armor > 100.0f) + armor = 100.0f; + + ped->SetArmor(armor); + + std::uint8_t armorUnsigned = static_cast(armor * 1.25); + + CBitStream stream; + stream.pBitStream->Write(armorUnsigned); + stream.pBitStream->Write(ped->GenerateSyncTimeContext()); + m_pPlayerManager->BroadcastOnlyJoined(CElementRPCPacket(ped, SET_PED_ARMOR, *stream.pBitStream)); + + return true; } bool CStaticFunctionDefinitions::KillPed(CElement* pElement, CElement* pKiller, unsigned char ucKillerWeapon, unsigned char ucBodyPart, bool bStealth) diff --git a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 1bf1beb45ad..93859842c1a 100644 --- a/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Server/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -163,7 +163,7 @@ class CStaticFunctionDefinitions // Ped get funcs static CPed* CreatePed(CResource* pResource, unsigned short usModel, const CVector& vecPosition, float fRotation = 0.0f, bool bSynced = true); - static bool GetPedArmor(CPed* pPed, float& fArmor); + static bool GetPedArmor(CPed* const ped, float& armor); static bool GetPedRotation(CPed* pPed, float& fRotation); static bool IsPedDead(CPed* pPed, bool& bDead); static bool IsPedDucked(CPed* pPed, bool& bDucked); @@ -193,7 +193,7 @@ class CStaticFunctionDefinitions static bool GetOriginalWeaponPropertyFlag(eWeaponProperty eProperty, eWeaponType eWeapon, eWeaponSkill eSkillLevel, bool& bEnable); // Ped set funcs - static bool SetPedArmor(CElement* pElement, float fArmor); + static bool SetPedArmor(CElement* pElement, float armor); static bool KillPed(CElement* pElement, CElement* pKiller = NULL, unsigned char ucKillerWeapon = 0xFF, unsigned char ucBodyPart = 0xFF, bool bStealth = false); static bool SetPedRotation(CElement* pElement, float fRotation, bool bNewWay); From 8294aaa7c4f6ce46673ee630a01ad79ca887caf5 Mon Sep 17 00:00:00 2001 From: Nico <122193236+Nico8340@users.noreply.github.com> Date: Sun, 26 Jan 2025 20:08:39 +0100 Subject: [PATCH 6/6] Server defs --- .../logic/luadefs/CLuaCompatibilityDefs.cpp | 4 +- .../deathmatch/logic/luadefs/CLuaPedDefs.cpp | 54 +++++-------------- .../deathmatch/logic/luadefs/CLuaPedDefs.h | 4 +- 3 files changed, 16 insertions(+), 46 deletions(-) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp index 0336b375b04..7f0a0718155 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp @@ -31,7 +31,7 @@ void CLuaCompatibilityDefs::LoadFunctions() {"getVehicleIDFromName", CLuaVehicleDefs::GetVehicleModelFromName}, {"getVehicleNameFromID", CLuaVehicleDefs::GetVehicleNameFromModel}, {"getPlayerWeaponSlot", CLuaPedDefs::GetPedWeaponSlot}, - {"getPlayerArmor", CLuaPedDefs::GetPedArmor}, + {"getPlayerArmor", ArgumentParserWarn}, {"getPlayerRotation", CLuaPedDefs::GetPedRotation}, {"isPlayerChoking", CLuaPedDefs::IsPedChoking}, {"isPlayerDead", CLuaPedDefs::IsPedDead}, @@ -46,7 +46,7 @@ void CLuaCompatibilityDefs::LoadFunctions() {"getPlayerFightingStyle", CLuaPedDefs::GetPedFightingStyle}, {"getPlayerGravity", CLuaPedDefs::GetPedGravity}, {"getPlayerContactElement", CLuaPedDefs::GetPedContactElement}, - {"setPlayerArmor", CLuaPedDefs::SetPedArmor}, + {"setPlayerArmor", ArgumentParserWarn}, {"setPlayerWeaponSlot", CLuaPedDefs::SetPedWeaponSlot}, {"killPlayer", CLuaPedDefs::KillPed}, {"setPlayerRotation", CLuaPedDefs::SetPedRotation}, diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 366daac57b8..a49e21ac463 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -24,7 +24,7 @@ void CLuaPedDefs::LoadFunctions() // Ped get functions {"getPedWeaponSlot", GetPedWeaponSlot}, - {"getPedArmor", GetPedArmor}, + {"getPedArmor", ArgumentParserWarn}, {"getPedRotation", GetPedRotation}, {"isPedChoking", IsPedChoking}, {"isPedDead", IsPedDead}, @@ -51,7 +51,7 @@ void CLuaPedDefs::LoadFunctions() {"isPedReloadingWeapon", ArgumentParser}, // Ped set functions - {"setPedArmor", SetPedArmor}, + {"setPedArmor", ArgumentParserWarn}, {"setPedWeaponSlot", SetPedWeaponSlot}, {"killPed", KillPed}, {"setPedRotation", SetPedRotation}, @@ -638,27 +638,12 @@ int CLuaPedDefs::GetPedTotalAmmo(lua_State* luaVM) return 1; } -int CLuaPedDefs::GetPedArmor(lua_State* luaVM) +float CLuaPedDefs::GetPedArmor(CPed* const ped) { - CPed* pPed; - - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPed); - - if (!argStream.HasErrors()) - { - float fArmor; - if (CStaticFunctionDefinitions::GetPedArmor(pPed, fArmor)) - { - lua_pushnumber(luaVM, fArmor); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + float armor; + CStaticFunctionDefinitions::GetPedArmor(ped, armor); - lua_pushboolean(luaVM, false); - return 1; + return armor; } int CLuaPedDefs::GetPedOccupiedVehicle(lua_State* luaVM) @@ -1018,30 +1003,15 @@ int CLuaPedDefs::GetPedContactElement(lua_State* luaVM) return 1; } -int CLuaPedDefs::SetPedArmor(lua_State* luaVM) +bool CLuaPedDefs::SetPedArmor(CPed* const ped, const float armor) { - CElement* pElement; - float fArmor; + if (armor < 0.0f) + throw std::invalid_argument("Armor must be greater than or equal to 0"); - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pElement); - argStream.ReadNumber(fArmor); - - if (!argStream.HasErrors()) - { - LogWarningIfPlayerHasNotJoinedYet(luaVM, pElement); - - if (CStaticFunctionDefinitions::SetPedArmor(pElement, fArmor)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + if (armor > 100.0f) + throw std::invalid_argument("Armor must be less than or equal to 100"); - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetPedArmor(ped, armor); } int CLuaPedDefs::KillPed(lua_State* luaVM) diff --git a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 35922472987..c4fb324fe77 100644 --- a/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Server/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -28,7 +28,7 @@ class CLuaPedDefs : public CLuaDefs // Ped get functions LUA_DECLARE(CreatePed); - LUA_DECLARE(GetPedArmor); + static float GetPedArmor(CPed* const ped); LUA_DECLARE(GetPedRotation); LUA_DECLARE(IsPedChoking); LUA_DECLARE(IsPedDead); @@ -56,7 +56,7 @@ class CLuaPedDefs : public CLuaDefs static bool IsPedReloadingWeapon(CPed* const ped) noexcept; // Ped set functions - LUA_DECLARE(SetPedArmor); + static bool SetPedArmor(CPed* const ped, const float armor); LUA_DECLARE(KillPed); LUA_DECLARE(SetPedRotation); LUA_DECLARE(SetPedStat);