Skip to content

Execute restricted Lua script effect

Ellypse edited this page May 31, 2019 · 1 revision

The workflow effect "Execute restricted Lua script" allows you to write and execute a custom Lua script in a restricted environment in which you can access Lua standard libraries and Extended workflow functions, but cannot access WoW API functions.

Note : This article is written for Total RP 3 : Extended version 1.1 or later

Disclaimer

This effect is only intended for use by players who know how to code in Lua, and in cases where classic workflows cannot do what you're looking for. It is heavier on performance as the script has to be recompiled every time, and makes it harder for other players to understand how the item works.

Please make an issue ticket if something you're looking for cannot be done easily without a script, as it might be beneficial for everyone to tackle the cause of it in the addon's source code.

Effects

To use an effect, you need to use the function effect("effect_key", args, [effect_arg1, effect_arg2, ...]). args is required as is, as it contains the script scope. To find the effect key and potential effect arguments, you need to look into the addon code.

Effects are separated in multiple files depending on what they're affecting.

  • Basic effects are in script/script_effects.lua
  • Inventory effects are in inventory/inventory_effects.lua
  • Quest effects are in quest/quest_effects.lua
  • Cutscene effects are in dialogues/dialogues.lua
  • Document effects are in document/document.lua

In those files, you will either find an EFFECTS table, or need to look for the registerEffects calls. Either of these have the effect key as a table key, and arguments in args or cArgs.

For instance, to send a signal of ID "myID" and value "myVal", you need to write effect("signal_send", args, "myID", "myVal").

Operands

To use an operand, you need to use the function op("operand_key", args, [operand_arg1, operand_arg2, ...]). args is required as is, as it contains the script scope. To find the operand key and potential operand arguments, you need to look into the addon code.

Operands are all regrouped into script/script_operands.lua. This file contains an OPERANDS table, in which the table keys are the operand keys, and the arguments are in args.

For instance, to get the player's health, you need to write op("unit_health", args, "player").

Variables

You can manipulate Extended variables in restricted Lua scripts. Two functions are at your disposal for this purpose : getVar(args, source, varName) to get a variable value (as a string), and setVar(args, source, varName, varValue) to set a variable value.

  • args is required as is, as it contains the script scope.
  • Source can be either "w" for a workflow source, "o" for an object source, or "c" for an active campaign source.
  • varName is the name of the variable.
  • varValue is the value you want to set for your variable (for setVar).

For instance, you can get the value for the variable boss_health in your active campaign using getVar(args, "c", "boss_health"), and set it to 50 using setVar(args, "c", "boss_health", 50).