Skip to content

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

WizardsOfLua.log = "console"

Fields

version: string Read-Only

The version of the installed Wizards of Lua mod.

log: string Read/Write

Controls where log(...) outputs are sent. Valid options are:

  • "source": Output is sent to the spell's command source.

  • "operators": Output is broadcast to all server operators.

  • "console": Output is printed to the Minecraft server console.

  • "none": Output is discarded.

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.

Methods

setCommand(command: table)

Registers a new dynamic command.

The command table must contain:

  • id (string): unique identifier (and permission node).

  • level (number|nil): required operator level (0–4). Default is 0.

  • pattern (string): command syntax with %-placeholders.

  • code (string): Lua snippet to run when invoked.

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

Name Type Description
command table A spec table as described above.

See also

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

Name Type Description
id string The id of the dynamic command to remove

Returns

  • boolean — success true if the command existed and was unregistered; false otherwise

listCommands() list: {id:string, level:number, pattern:string, code:string}[]

Lists all currently registered dynamic commands with their specs and code.

Returns an array of tables { id=…, level=…, pattern=…, code=… }, 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

  • {id:string, level:number, pattern:string, code:string}[] — list A list of all dynamic command definitions