Some operands aren't working properly
Ricorei opened this issue ยท 3 comments
Operands like unit_id aren't returning a proper value, often nil, when using Restricted Lua Code.
Using
effect("var_operand", args, "o_playerID", "w", "unit_id", "player");
Or
op("unit_id", args, "player")
Returns nil in both cases. It only works if set through a variable dynamic value.
Using another operand like "random" works, and "unit_health" works for op function but not with an effect.
local unitIdOperand = Operand("unit_id", {
["UnitID"] = "TRP3_API.utils.str.getUnitID"
})
local unitNpcIdOperand = Operand("unit_npc_id", {
["getUnitNPCID"] = "TRP3_API.utils.str.getUnitNPCID",
});
TRP3_API.utils.str not being initialized properly could be the culprit.
There was indeed an issue with the operand function not properly receiving the appropriate environment. This is now fixed for next version.
The variable dynamic value effect however does not have the issue, the problem lies in the call. The last argument must be a table as some operands can have more than one argument provided, and as such the right call is effect("var_operand", args, "o_playerID", "w", "unit_id", {"player"});
. I agree it's treacherous, and it might be worth looking if there's a way to change the behaviour without breaking retrocompatibility in the future.
Oh quite indeed, there is a plural here I should have noticed : local operandArgs = args[4];
Though, I got the information from the Wiki.
https://github.com/Total-RP/Total-RP-3-Extended/wiki/Execute-restricted-Lua-script-effect
For instance, to send a signal of ID "myID" and value "myVal", you need to write effect("signal_send", args, "myID", "myVal").
For instance, to get the player's health, you need to write op("unit_health", args, "player").
And there is no mention of any table here which got me confused. If it works like this I have at least a way to avoid the workflow ui and use it directly in Lua before the next version. Thank you.