Skip to content

Commit 0102dd2

Browse files
committedFeb 7, 2025·
Fix backwards compatibility for set/getPedControlState (Fixes #3992)
1 parent dce38ee commit 0102dd2

File tree

2 files changed

+57
-5
lines changed

2 files changed

+57
-5
lines changed
 

‎Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp

+54-3
Original file line numberDiff line numberDiff line change
@@ -1247,10 +1247,31 @@ int CLuaPedDefs::GetPedClothes(lua_State* luaVM)
12471247
return 1;
12481248
}
12491249

1250-
bool CLuaPedDefs::GetPedControlState(CClientPed* const ped, const std::string control) noexcept
1250+
bool CLuaPedDefs::GetPedControlState(std::variant<CClientPed*, std::string> first, std::optional<std::string> maybeControl)
12511251
{
1252-
bool state;
1252+
CClientPed* ped{};
1253+
std::string control{};
1254+
1255+
if (std::holds_alternative<CClientPed*>(first))
1256+
{
1257+
if (!maybeControl.has_value())
1258+
throw std::invalid_argument("Expected control name at argument 2");
1259+
1260+
ped = std::get<CClientPed*>(first);
1261+
control = maybeControl.value();
1262+
}
1263+
else if (std::holds_alternative<std::string>(first))
1264+
{
1265+
ped = CStaticFunctionDefinitions::GetLocalPlayer();
1266+
control = std::get<std::string>(first);
1267+
}
1268+
else
1269+
{
1270+
throw std::invalid_argument("Expected ped or control name at argument 1");
1271+
}
12531272

1273+
bool state;
1274+
12541275
if (!CStaticFunctionDefinitions::GetPedControlState(*ped, control, state))
12551276
return false;
12561277

@@ -1803,8 +1824,38 @@ int CLuaPedDefs::RemovePedClothes(lua_State* luaVM)
18031824
return 1;
18041825
}
18051826

1806-
bool CLuaPedDefs::SetPedControlState(CClientPed* const ped, const std::string control, const bool state) noexcept
1827+
bool CLuaPedDefs::SetPedControlState(std::variant<CClientPed*, std::string> first, std::variant<std::string, bool> second, std::optional<bool> maybeState)
18071828
{
1829+
CClientPed* ped{};
1830+
std::string control{};
1831+
bool state{};
1832+
1833+
if (std::holds_alternative<CClientPed*>(first))
1834+
{
1835+
if (!std::holds_alternative<std::string>(second))
1836+
throw std::invalid_argument("Expected control name at argument 2");
1837+
1838+
if (!maybeState.has_value())
1839+
throw std::invalid_argument("Expected state boolean at argument 3");
1840+
1841+
ped = std::get<CClientPed*>(first);
1842+
control = std::get<std::string>(second);
1843+
state = maybeState.value();
1844+
}
1845+
else if (std::holds_alternative<std::string>(first))
1846+
{
1847+
if (!std::holds_alternative<bool>(second))
1848+
throw std::invalid_argument("Expected state boolean at argument 2");
1849+
1850+
ped = CStaticFunctionDefinitions::GetLocalPlayer();
1851+
control = std::get<std::string>(first);
1852+
state = std::get<bool>(second);
1853+
}
1854+
else
1855+
{
1856+
throw std::invalid_argument("Expected ped or control name at argument 1");
1857+
}
1858+
18081859
return CStaticFunctionDefinitions::SetPedControlState(*ped, control, state);
18091860
}
18101861

‎Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class CLuaPedDefs : public CLuaDefs
6565
static bool UpdateElementRpHAnim(lua_State* const luaVM, CClientEntity* entity);
6666
LUA_DECLARE_OOP(GetPedBonePosition);
6767
LUA_DECLARE(GetPedClothes);
68-
static bool GetPedControlState(CClientPed* const ped, const std::string control) noexcept;
68+
static bool GetPedControlState(std::variant<CClientPed*, std::string> first, std::optional<std::string> maybeControl);
6969
LUA_DECLARE(GetPedAnalogControlState);
7070
LUA_DECLARE(IsPedSunbathing);
7171
LUA_DECLARE(IsPedDoingGangDriveby);
@@ -96,7 +96,8 @@ class CLuaPedDefs : public CLuaDefs
9696
static bool IsPedReloadingWeapon(CClientPed* const ped) noexcept;
9797
LUA_DECLARE(AddPedClothes);
9898
LUA_DECLARE(RemovePedClothes);
99-
static bool SetPedControlState(CClientPed* const ped, const std::string control, const bool state) noexcept;
99+
static bool SetPedControlState(std::variant<CClientPed*, std::string> first, std::variant<std::string, bool> second,
100+
std::optional<bool> maybeState);
100101
LUA_DECLARE(SetPedAnalogControlState);
101102
LUA_DECLARE(SetPedDoingGangDriveby);
102103
static bool SetPedFightingStyle(CClientEntity* const entity, const unsigned int style);

0 commit comments

Comments
 (0)
Please sign in to comment.