Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unintended behavior for ped control states #3964

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ void CLuaCompatibilityDefs::LoadFunctions()
{"isPlayerDead", CLuaPedDefs::IsPedDead},
{"guiEditSetCaratIndex", CLuaGUIDefs::GUIEditSetCaretIndex},
{"guiMemoSetCaratIndex", CLuaGUIDefs::GUIMemoSetCaretIndex},
{"setControlState", CLuaPedDefs::SetPedControlState},
{"getControlState", CLuaPedDefs::GetPedControlState},
{"setControlState", ArgumentParserWarn<false, CLuaPedDefs::SetPedControlState>},
{"getControlState", ArgumentParserWarn<false, CLuaPedDefs::GetPedControlState>},
{"setCameraShakeLevel", ArgumentParserWarn<false, CLuaCameraDefs::SetCameraDrunkLevel>},
{"getCameraShakeLevel", ArgumentParserWarn<false, CLuaCameraDefs::GetCameraDrunkLevel>},
};
Expand Down
62 changes: 9 additions & 53 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void CLuaPedDefs::LoadFunctions()
{"setPedAnimationProgress", SetPedAnimationProgress},
{"setPedAnimationSpeed", SetPedAnimationSpeed},
{"setPedWalkingStyle", SetPedMoveAnim},
{"setPedControlState", SetPedControlState},
{"setPedControlState", ArgumentParserWarn<false, SetPedControlState>},
{"setPedAnalogControlState", SetPedAnalogControlState},
{"setPedDoingGangDriveby", SetPedDoingGangDriveby},
{"setPedFightingStyle", ArgumentParser<SetPedFightingStyle>},
Expand Down Expand Up @@ -75,7 +75,7 @@ void CLuaPedDefs::LoadFunctions()
{"getPedAnimationSpeed", ArgumentParser<GetPedAnimationSpeed>},
{"getPedAnimationLength", ArgumentParser<GetPedAnimationLength>},
{"getPedWalkingStyle", GetPedMoveAnim},
{"getPedControlState", GetPedControlState},
{"getPedControlState", ArgumentParserWarn<false, GetPedControlState>},
{"getPedAnalogControlState", GetPedAnalogControlState},
{"isPedDoingGangDriveby", IsPedDoingGangDriveby},
{"getPedFightingStyle", GetPedFightingStyle},
Expand Down Expand Up @@ -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.data(), state))
return false;

lua_pushboolean(luaVM, false);
return 1;
return state;
}

int CLuaPedDefs::GetPedAnalogControlState(lua_State* luaVM)
Expand Down Expand Up @@ -1839,34 +1820,9 @@ int CLuaPedDefs::RemovePedClothes(lua_State* luaVM)
return 1;
}

int CLuaPedDefs::SetPedControlState(lua_State* luaVM)
bool CLuaPedDefs::SetPedControlState(CClientEntity* const entity, 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(*entity, control.data(), state);
}

int CLuaPedDefs::SetPedDoingGangDriveby(lua_State* luaVM)
Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaPedDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(CClientEntity* const entity, const std::string_view control, const bool state) noexcept;
Nico8340 marked this conversation as resolved.
Show resolved Hide resolved
LUA_DECLARE(SetPedAnalogControlState);
LUA_DECLARE(SetPedDoingGangDriveby);
static bool SetPedFightingStyle(CClientEntity* const entity, const unsigned int style);
Expand Down
Loading