diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index b5f56406e0e..f9d33480ecc 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -2306,18 +2306,18 @@ bool CStaticFunctionDefinitions::SetPedDoingGangDriveby(CClientEntity& Entity, b bool CStaticFunctionDefinitions::SetPedFightingStyle(CClientEntity& Entity, unsigned char ucStyle) { + // Is valid style? + if (ucStyle < 4 || ucStyle > 16) + return false; + RUN_CHILDREN(SetPedFightingStyle(**iter, ucStyle)) if (IS_PED(&Entity) && Entity.IsLocalEntity()) { CClientPed& Ped = static_cast(Entity); if (Ped.GetFightingStyle() != ucStyle) { - // Is valid style - if (ucStyle >= 4 && ucStyle <= 16) - { - Ped.SetFightingStyle(static_cast(ucStyle)); - return true; - } + Ped.SetFightingStyle(static_cast(ucStyle)); + return true; } } return false; @@ -2507,17 +2507,6 @@ bool CStaticFunctionDefinitions::SetPedOnFire(CClientEntity& Entity, bool bOnFir return false; } -bool CStaticFunctionDefinitions::SetPedArmor(CClientPed& Ped, float fArmor) -{ - if (Ped.IsLocalEntity()) - { - Ped.SetArmor(fArmor); - return true; - } - - return false; -} - bool CStaticFunctionDefinitions::SetPedOxygenLevel(CClientEntity& Entity, float fOxygen) { if (IS_PED(&Entity)) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 14215533e3e..4776be6ca1e 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -188,7 +188,6 @@ class CStaticFunctionDefinitions static bool RemovePedFromVehicle(CClientPed* pPed); static bool WarpPedIntoVehicle(CClientPed* pPed, CClientVehicle* pVehicle, unsigned int uiSeat); static bool SetPedOxygenLevel(CClientEntity& Entity, float fOxygen); - static bool SetPedArmor(CClientPed& Ped, float fArmor); // Extra Clothes functions static bool GetBodyPartName(unsigned char ucID, SString& strOutName); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index c3e25dbaeac..919bb1b1db4 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -10,6 +10,8 @@ *****************************************************************************/ #include "StdInc.h" +#include "lua/CLuaFunctionParser.h" + #define MIN_CLIENT_REQ_REMOVEPEDFROMVEHICLE_CLIENTSIDE "1.3.0-9.04482" #define MIN_CLIENT_REQ_WARPPEDINTOVEHICLE_CLIENTSIDE "1.3.0-9.04482" @@ -75,7 +77,7 @@ void CLuaPedDefs::LoadFunctions() {"setPedControlState", SetPedControlState}, {"setPedAnalogControlState", SetPedAnalogControlState}, {"setPedDoingGangDriveby", SetPedDoingGangDriveby}, - {"setPedFightingStyle", SetPedFightingStyle}, + {"setPedFightingStyle", ArgumentParser}, {"setPedLookAt", SetPedLookAt}, {"setPedHeadless", SetPedHeadless}, {"setPedFrozen", SetPedFrozen}, @@ -86,7 +88,7 @@ void CLuaPedDefs::LoadFunctions() {"warpPedIntoVehicle", WarpPedIntoVehicle}, {"removePedFromVehicle", RemovePedFromVehicle}, {"setPedOxygenLevel", SetPedOxygenLevel}, - {"setPedArmor", SetPedArmor}, + {"setPedArmor", ArgumentParser}, {"givePedWeapon", GivePedWeapon}, {"isPedReloadingWeapon", IsPedReloadingWeapon}, }; @@ -1762,19 +1764,13 @@ int CLuaPedDefs::SetPedDoingGangDriveby(lua_State* luaVM) return 1; } -int CLuaPedDefs::SetPedFightingStyle(lua_State* luaVM) +bool CLuaPedDefs::SetPedFightingStyle(CClientEntity* const entity, const unsigned int style) { - CClientEntity* pEntity; - unsigned char ucStyle; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pEntity); - argStream.ReadNumber(ucStyle); - - if (argStream.HasErrors()) - return luaL_error(luaVM, argStream.GetFullErrorMessage()); + // Is valid style? + if (style < 4 || style > 16) + throw std::invalid_argument("Style can only be between 4 and 16"); - lua_pushboolean(luaVM, CStaticFunctionDefinitions::SetPedFightingStyle(*pEntity, ucStyle)); - return 1; + return CStaticFunctionDefinitions::SetPedFightingStyle(*entity, style); } int CLuaPedDefs::SetPedLookAt(lua_State* luaVM) @@ -2198,21 +2194,13 @@ int CLuaPedDefs::SetPedMoveAnim(lua_State* luaVM) return 1; } -int CLuaPedDefs::SetPedArmor(lua_State* luaVM) +bool CLuaPedDefs::SetPedArmor(CClientPed* const ped, const float armor) { - CClientPed* pPed; - float fArmor; - CScriptArgReader argStream(luaVM); - argStream.ReadUserData(pPed); - argStream.ReadNumber(fArmor); - - if (argStream.HasErrors()) - { - return luaL_error(luaVM, argStream.GetFullErrorMessage()); - } + if (!ped->IsLocalEntity()) + return false; - lua_pushboolean(luaVM, CStaticFunctionDefinitions::SetPedArmor(*pPed, fArmor)); - return 1; + ped->SetArmor(armor); + return true; } int CLuaPedDefs::SetPedOxygenLevel(lua_State* luaVM) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 925a55a620e..85d8c8415f1 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -71,7 +71,7 @@ class CLuaPedDefs : public CLuaDefs LUA_DECLARE(SetPedAnimationProgress); LUA_DECLARE(SetPedAnimationSpeed); LUA_DECLARE(SetPedMoveAnim); - LUA_DECLARE(SetPedArmor); + static bool SetPedArmor(CClientPed* const ped, const float armor); LUA_DECLARE(SetPedWeaponSlot); LUA_DECLARE(GivePedWeapon); LUA_DECLARE(IsPedReloadingWeapon); @@ -80,7 +80,7 @@ class CLuaPedDefs : public CLuaDefs LUA_DECLARE(SetPedControlState); LUA_DECLARE(SetPedAnalogControlState); LUA_DECLARE(SetPedDoingGangDriveby); - LUA_DECLARE(SetPedFightingStyle); + static bool SetPedFightingStyle(CClientEntity* const entity, const unsigned int style); LUA_DECLARE(SetPedLookAt); LUA_DECLARE(SetPedHeadless); LUA_DECLARE(SetPedFrozen);