diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index fdb7a897a8..469a0d895e 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1710,42 +1710,39 @@ bool CStaticFunctionDefinitions::GetPedClothes(CClientPed& Ped, unsigned char uc return false; } -bool CStaticFunctionDefinitions::GetPedControlState(CClientPed& Ped, const char* szControl, bool& bState) +bool CStaticFunctionDefinitions::GetPedControlState(CClientPed& const ped, const std::string_view control, bool& state) noexcept { - if (&Ped == GetLocalPlayer()) - { - return GetControlState(szControl, bState); - } + if (&ped == GetLocalPlayer()) + return GetControlState(control.data(), state); - if (Ped.GetType() == CCLIENTPLAYER) + if (ped.GetType() == CCLIENTPLAYER) { - CControllerState cs; - Ped.GetControllerState(cs); - bool bOnFoot = (!Ped.GetRealOccupiedVehicle()); - bState = CClientPad::GetControlState(szControl, cs, bOnFoot); - float fState = 0; - unsigned int uiIndex; - // Check it's Analog - if (CClientPad::GetAnalogControlIndex(szControl, uiIndex)) + CControllerState controller; + ped.GetControllerState(controller); + + bool foot = !ped.GetRealOccupiedVehicle(); + state = CClientPad::GetControlState(control.data(), controller, foot); + + float analog = 0; + std::uint32_t index; + + if (CClientPad::GetAnalogControlIndex(control.data(), index)) { - if (CClientPad::GetAnalogControlState(szControl, cs, bOnFoot, fState, false)) + if (CClientPad::GetAnalogControlState(control.data(), controller, foot, analog, false)) { - bState = fState > 0; + state = analog > 0; return true; } } - // or binary. else { - bState = CClientPad::GetControlState(szControl, cs, bOnFoot); + state = CClientPad::GetControlState(control.data(), controller, foot); return true; } } - if (Ped.m_Pad.GetControlState(szControl, bState)) - { + if (ped.m_Pad.GetControlState(control.data(), state)) return true; - } return false; } @@ -2366,24 +2363,13 @@ bool CStaticFunctionDefinitions::RemovePedClothes(CClientEntity& Entity, unsigne return false; } -bool CStaticFunctionDefinitions::SetPedControlState(CClientEntity& Entity, const char* szControl, bool bState) +bool CStaticFunctionDefinitions::SetPedControlState(CClientPed& const ped, const std::string_view control, const bool state) noexcept { - RUN_CHILDREN(SetPedControlState(**iter, szControl, bState)) - if (IS_PED(&Entity)) - { - CClientPed& Ped = static_cast(Entity); - - if (&Ped == GetLocalPlayer()) - { - return SetControlState(szControl, bState); - } + if (&ped == GetLocalPlayer()) + return SetControlState(control.data(), state); - if (Ped.m_Pad.SetControlState(szControl, bState)) - { - return true; - } - } - return false; + if (ped.m_Pad.SetControlState(control.data(), state)) + return true; } bool CStaticFunctionDefinitions::SetPedDoingGangDriveby(CClientEntity& Entity, bool bGangDriveby) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 17d4fa7edf..7bbd928840 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h @@ -137,7 +137,7 @@ class CStaticFunctionDefinitions static bool IsPedDoingTask(CClientPed& Ped, const char* szTaskName, bool& bIsDoingTask); static bool GetPedBonePosition(CClientPed& Ped, eBone bone, CVector& vecPosition); static bool GetPedClothes(CClientPed& Ped, unsigned char ucType, SString& strOutTexture, SString& strOutModel); - static bool GetPedControlState(CClientPed& Ped, const char* szControl, bool& bState); + static bool GetPedControlState(CClientPed& const ped, const std::string_view control, bool& state) noexcept; static bool GetPedAnalogControlState(CClientPed& Ped, const char* szControl, float& fState, bool bRawInput); static bool IsPedDoingGangDriveby(CClientPed& Ped, bool& bDoingGangDriveby); static bool GetPedFightingStyle(CClientPed& Ped, unsigned char& ucStyle); @@ -174,7 +174,7 @@ class CStaticFunctionDefinitions static bool SetPedMoveAnim(CClientEntity& Entity, unsigned int iMoveAnim); static bool AddPedClothes(CClientEntity& Entity, const char* szTexture, const char* szModel, unsigned char ucType); static bool RemovePedClothes(CClientEntity& Entity, unsigned char ucType); - static bool SetPedControlState(CClientEntity& Entity, const char* szControl, bool bState); + static bool SetPedControlState(CClientPed& const ped, const std::string_view control, const bool state) noexcept; static bool SetPedAnalogControlState(CClientEntity& Entity, const char* szControl, float fState); static bool SetPedDoingGangDriveby(CClientEntity& Entity, bool bGangDriveby); static bool SetPedFightingStyle(CClientEntity& Entity, unsigned char ucStyle); diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp index 7dea8f95bf..e64dbe8d4b 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaCompatibilityDefs.cpp @@ -67,8 +67,8 @@ void CLuaCompatibilityDefs::LoadFunctions() {"isPlayerDead", CLuaPedDefs::IsPedDead}, {"guiEditSetCaratIndex", CLuaGUIDefs::GUIEditSetCaretIndex}, {"guiMemoSetCaratIndex", CLuaGUIDefs::GUIMemoSetCaretIndex}, - {"setControlState", CLuaPedDefs::SetPedControlState}, - {"getControlState", CLuaPedDefs::GetPedControlState}, + {"setControlState", ArgumentParserWarn}, + {"getControlState", ArgumentParserWarn}, {"setCameraShakeLevel", ArgumentParserWarn}, {"getCameraShakeLevel", ArgumentParserWarn}, }; diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 34040db19e..64542e5082 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -45,7 +45,7 @@ void CLuaPedDefs::LoadFunctions() {"setPedAnimationProgress", SetPedAnimationProgress}, {"setPedAnimationSpeed", SetPedAnimationSpeed}, {"setPedWalkingStyle", SetPedMoveAnim}, - {"setPedControlState", SetPedControlState}, + {"setPedControlState", ArgumentParserWarn}, {"setPedAnalogControlState", SetPedAnalogControlState}, {"setPedDoingGangDriveby", SetPedDoingGangDriveby}, {"setPedFightingStyle", ArgumentParser}, @@ -75,7 +75,7 @@ void CLuaPedDefs::LoadFunctions() {"getPedAnimationSpeed", ArgumentParser}, {"getPedAnimationLength", ArgumentParser}, {"getPedWalkingStyle", GetPedMoveAnim}, - {"getPedControlState", GetPedControlState}, + {"getPedControlState", ArgumentParserWarn}, {"getPedAnalogControlState", GetPedAnalogControlState}, {"isPedDoingGangDriveby", IsPedDoingGangDriveby}, {"getPedFightingStyle", GetPedFightingStyle}, @@ -1264,33 +1264,14 @@ int CLuaPedDefs::GetPedClothes(lua_State* luaVM) return 1; } -int CLuaPedDefs::GetPedControlState(lua_State* luaVM) +bool CLuaPedDefs::GetPedControlState(CClientPed* const ped, const std::string_view control) noexcept { - // Verify the argument - CClientPed* pPed = CStaticFunctionDefinitions::GetLocalPlayer(); - SString strControl = ""; - CScriptArgReader argStream(luaVM); + bool state; - if (argStream.NextIsUserData()) - { - argStream.ReadUserData(pPed); - } - argStream.ReadString(strControl); - - if (!argStream.HasErrors()) - { - bool bState; - if (CStaticFunctionDefinitions::GetPedControlState(*pPed, strControl, bState)) - { - lua_pushboolean(luaVM, bState); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); + if (!CStaticFunctionDefinitions::GetPedControlState(*ped, control, state)) + return false; - lua_pushboolean(luaVM, false); - return 1; + return state; } int CLuaPedDefs::GetPedAnalogControlState(lua_State* luaVM) @@ -1839,34 +1820,9 @@ int CLuaPedDefs::RemovePedClothes(lua_State* luaVM) return 1; } -int CLuaPedDefs::SetPedControlState(lua_State* luaVM) +bool CLuaPedDefs::SetPedControlState(CClientPed* const ped, const std::string_view control, const bool state) noexcept { - // Verify the argument - CClientEntity* pEntity = CStaticFunctionDefinitions::GetLocalPlayer(); - SString strControl = ""; - bool bState = false; - CScriptArgReader argStream(luaVM); - - if (argStream.NextIsUserData()) - { - argStream.ReadUserData(pEntity); - } - argStream.ReadString(strControl); - argStream.ReadBool(bState); - - if (!argStream.HasErrors()) - { - if (CStaticFunctionDefinitions::SetPedControlState(*pEntity, strControl, bState)) - { - lua_pushboolean(luaVM, true); - return 1; - } - } - else - m_pScriptDebugging->LogCustom(luaVM, argStream.GetFullErrorMessage()); - - lua_pushboolean(luaVM, false); - return 1; + return CStaticFunctionDefinitions::SetPedControlState(*ped, control, state); } int CLuaPedDefs::SetPedDoingGangDriveby(lua_State* luaVM) diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index 0d9cc3500c..a7c2b1d8d7 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h @@ -65,7 +65,7 @@ class CLuaPedDefs : public CLuaDefs static bool UpdateElementRpHAnim(lua_State* const luaVM, CClientEntity* entity); LUA_DECLARE_OOP(GetPedBonePosition); LUA_DECLARE(GetPedClothes); - LUA_DECLARE(GetPedControlState); + static bool GetPedControlState(CClientPed* const ped, const std::string_view control) noexcept; LUA_DECLARE(GetPedAnalogControlState); LUA_DECLARE(IsPedSunbathing); LUA_DECLARE(IsPedDoingGangDriveby); @@ -96,7 +96,7 @@ class CLuaPedDefs : public CLuaDefs static bool IsPedReloadingWeapon(CClientPed* const ped) noexcept; LUA_DECLARE(AddPedClothes); LUA_DECLARE(RemovePedClothes); - LUA_DECLARE(SetPedControlState); + static bool SetPedControlState(CClientPed* const ped, const std::string_view control, const bool state) noexcept; LUA_DECLARE(SetPedAnalogControlState); LUA_DECLARE(SetPedDoingGangDriveby); static bool SetPedFightingStyle(CClientEntity* const entity, const unsigned int style);