Total RP 3: Extended

Total RP 3: Extended

903k Downloads

Some operands aren't working properly

Ricorei opened this issue ยท 3 comments

commented

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.

https://github.com/Total-RP/Total-RP-3-Extended/blob/master/totalRP3_Extended/script/Operands/UnitOperands.lua

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.

commented

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.

commented

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.

commented

Most effects don't pass a table but this one in particular does because of the potential for multiple operand arguments on top of the variable effect arguments.