Skip to content

Make getPedControlState and setPedControlState functions backward compatible #4008

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

Closed
wants to merge 2 commits into from

Conversation

Nico8340
Copy link
Contributor

@Nico8340 Nico8340 commented Feb 7, 2025

Makes getPedControlState and setPedControlState functions backward compatible again after #3964 broke them, and fixes #3992

@@ -1710,38 +1710,38 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't use references for small types. string_view and bool are small types

Comment on lines +1826 to +1865
bool CLuaPedDefs::SetPedControlState(const std::variant<CClientPed*, std::string_view> first, const std::variant<std::string_view, bool> second, const std::optional<bool> third) noexcept
{
CClientPed* ped;
std::string_view control;
bool state;

if (std::holds_alternative<CClientPed*>(first))
{
ped = std::get<CClientPed*>(first);

if (std::holds_alternative<std::string_view>(second))
{
control = std::get<std::string_view>(second);

if (third)
state = *third;
else
return false;
}
else if (std::holds_alternative<bool>(second))
state = std::get<bool>(second);
else
return false;
}
else if (std::holds_alternative<std::string_view>(first))
{
ped = CStaticFunctionDefinitions::GetLocalPlayer();
control = std::get<std::string_view>(first);

if (std::holds_alternative<bool>(second))
state = std::get<bool>(second);
else if (third)
state = *third;
else
return false;
}

if (!ped)
return false;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a mess. And has no error messages for bad usage. I can write setPedControlState("string1", "fire", false) and get silent false. Maybe it's better to keep the old parser here. What do you think?

@botder
Copy link
Member

botder commented Feb 7, 2025

This PR is overengineered, you could've just edited the Lua function defs + throwing for wrong usage.

@botder
Copy link
Member

botder commented Feb 7, 2025

Issue was fixed in 0102dd2

@botder botder closed this Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

getPedControlState is broken
3 participants