diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp index 111fe7413d8..da1288e387a 100644 --- a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp +++ b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp @@ -1710,25 +1710,25 @@ bool CStaticFunctionDefinitions::GetPedClothes(CClientPed& Ped, unsigned char uc return false; } -bool CStaticFunctionDefinitions::GetPedControlState(CClientPed& const ped, const std::string control, bool& state) noexcept +bool CStaticFunctionDefinitions::GetPedControlState(CClientPed& ped, const std::string_view& control, bool& state) noexcept { if (&ped == GetLocalPlayer()) - return GetControlState(control.c_str(), state); + return GetControlState(control.data(), state); if (ped.GetType() == CCLIENTPLAYER) { CControllerState controller; ped.GetControllerState(controller); - bool foot = !ped.GetRealOccupiedVehicle(); - state = CClientPad::GetControlState(control.c_str(), controller, foot); + const bool foot = !ped.GetRealOccupiedVehicle(); + state = CClientPad::GetControlState(control.data(), controller, foot); float analog = 0; std::uint32_t index; - if (CClientPad::GetAnalogControlIndex(control.c_str(), index)) + if (CClientPad::GetAnalogControlIndex(control.data(), index)) { - if (CClientPad::GetAnalogControlState(control.c_str(), controller, foot, analog, false)) + if (CClientPad::GetAnalogControlState(control.data(), controller, foot, analog, false)) { state = analog > 0; return true; @@ -1736,12 +1736,12 @@ bool CStaticFunctionDefinitions::GetPedControlState(CClientPed& const ped, const } else { - state = CClientPad::GetControlState(control.c_str(), controller, foot); + state = CClientPad::GetControlState(control.data(), controller, foot); return true; } } - if (ped.m_Pad.GetControlState(control.c_str(), state)) + if (ped.m_Pad.GetControlState(control.data(), state)) return true; return false; @@ -2363,13 +2363,15 @@ bool CStaticFunctionDefinitions::RemovePedClothes(CClientEntity& Entity, unsigne return false; } -bool CStaticFunctionDefinitions::SetPedControlState(CClientPed& const ped, const std::string control, const bool state) noexcept +bool CStaticFunctionDefinitions::SetPedControlState(CClientPed& ped, const std::string_view& control, const bool state) noexcept { if (&ped == GetLocalPlayer()) - return SetControlState(control.c_str(), state); + return SetControlState(control.data(), state); - if (ped.m_Pad.SetControlState(control.c_str(), state)) + if (ped.m_Pad.SetControlState(control.data(), state)) return true; + + return false; } bool CStaticFunctionDefinitions::SetPedDoingGangDriveby(CClientEntity& Entity, bool bGangDriveby) diff --git a/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h b/Client/mods/deathmatch/logic/CStaticFunctionDefinitions.h index 89459aa9e2f..65f56af7b60 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& const ped, const std::string control, bool& state) noexcept; + static bool GetPedControlState(CClientPed& 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(CClientPed& const ped, const std::string control, const bool state) noexcept; + static bool SetPedControlState(CClientPed& 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/CLuaPedDefs.cpp b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp index 339cfa00c6a..882aed11900 100644 --- a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp +++ b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp @@ -1247,11 +1247,31 @@ int CLuaPedDefs::GetPedClothes(lua_State* luaVM) return 1; } -bool CLuaPedDefs::GetPedControlState(CClientPed* const ped, const std::string control) noexcept +bool CLuaPedDefs::GetPedControlState(const std::variant first, const std::optional second) noexcept { - bool state; + bool state; + CClientPed* ped; + std::string_view control; - if (!CStaticFunctionDefinitions::GetPedControlState(*ped, control, state)) + if (std::holds_alternative(first)) + { + ped = std::get(first); + + if (!second) + return false; + + control = *second; + } + else if (std::holds_alternative(first)) + { + ped = CStaticFunctionDefinitions::GetLocalPlayer(); + control = std::get(first); + } + + if (!ped) + return false; + + if (!CStaticFunctionDefinitions::GetPedControlState(*ped, std::string(control), state)) return false; return state; @@ -1803,8 +1823,46 @@ int CLuaPedDefs::RemovePedClothes(lua_State* luaVM) return 1; } -bool CLuaPedDefs::SetPedControlState(CClientPed* const ped, const std::string control, const bool state) noexcept +bool CLuaPedDefs::SetPedControlState(const std::variant first, const std::variant second, const std::optional third) noexcept { + CClientPed* ped; + std::string_view control; + bool state; + + if (std::holds_alternative(first)) + { + ped = std::get(first); + + if (std::holds_alternative(second)) + { + control = std::get(second); + + if (third) + state = *third; + else + return false; + } + else if (std::holds_alternative(second)) + state = std::get(second); + else + return false; + } + else if (std::holds_alternative(first)) + { + ped = CStaticFunctionDefinitions::GetLocalPlayer(); + control = std::get(first); + + if (std::holds_alternative(second)) + state = std::get(second); + else if (third) + state = *third; + else + return false; + } + + if (!ped) + return false; + return CStaticFunctionDefinitions::SetPedControlState(*ped, control, state); } diff --git a/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h b/Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h index cd16ecdb210..63f48e5cd8c 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); - static bool GetPedControlState(CClientPed* const ped, const std::string control) noexcept; + static bool GetPedControlState(const std::variant first, const std::optional second) 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); - static bool SetPedControlState(CClientPed* const ped, const std::string control, const bool state) noexcept; + static bool SetPedControlState(const std::variant first, const std::variant second, const std::optional third) noexcept; LUA_DECLARE(SetPedAnalogControlState); LUA_DECLARE(SetPedDoingGangDriveby); static bool SetPedFightingStyle(CClientEntity* const entity, const unsigned int style);