-
-
Notifications
You must be signed in to change notification settings - Fork 454
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
Conversation
@@ -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 |
There was a problem hiding this comment.
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
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; | ||
|
There was a problem hiding this comment.
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?
This PR is overengineered, you could've just edited the Lua function defs + throwing for wrong usage. |
Issue was fixed in 0102dd2 |
Makes
getPedControlState
andsetPedControlState
functions backward compatible again after #3964 broke them, and fixes #3992