WizardsOfLua¶
Provides access to the global Wizards of Lua mod configuration, including dynamic command management at runtime.
These settings reflect the default values at server startup. All values are reset to their default value when the
server is restarted or when /wol startup is executed.
To customize them, use a startup.lua script. This script runs during the server's initialization phase and allows programmatic configuration of global settings.
Example: Set log output to the console during startup
Fields¶
global: table — Read-Only¶
A shared table for cross-spell state during the current server runtime. The reference is read-only, but the table contents are mutable. Any spell can write to this table and any other spell can read the changes at any time. The table is cleared on server restart or when /wol startup runs.
log: LogTarget — Read/Write¶
Controls where log(...) outputs are sent.
version: string — Read-Only¶
The version of the installed Wizards of Lua mod.
Methods¶
listCommands() → list: CommandSpec[ ]¶
Lists all currently registered dynamic commands with their specs and code.
Returns their definitions, so you can iterate and display them in Lua.
Example
local all = WizardsOfLua.listCommands()
for i, cmd in ipairs(all) do
print(i, cmd.id, "→", cmd.pattern, "(level " .. cmd.level .. ")")
end
Returns
- list: CommandSpec[ ] — The definitions of all dynamic commands.
removeCommand(id: string) → success: boolean¶
Unregisters a previously registered dynamic command.
Removes the dynamic command with the given id that was added via WizardsOfLua.setCommand.
Example
local removed = WizardsOfLua.removeCommand("my.cmd")
if not removed then
print("No such dynamic command: my.cmd")
end
Parameters
- id: string — The id of the dynamic command to remove
Returns
- success: boolean —
trueif the command existed and was unregistered;falseotherwise
setCommand(command: CommandSpec)¶
Registers a new dynamic command, or replaces an existing dynamic command that has the same id.
Note: Dynamic commands are available only at the end of the current server tick. Yield one tick (e.g. sleep(1)) before invoking a newly registered command.
Example
WizardsOfLua.setCommand( {
id = "coins.add",
level = 0,
pattern = "coins add amount:%i to list:%players",
code = [[
for i,e in ipairs(args.list) do
local c = e.extra.coins or 0
c = c + args.amount
e:putExtra({coins=c})
print(e.name.." has now "..c.." coins.")
end
]]
})
Parameters
- command: CommandSpec — The definition of the command.