Skip to Content
API ReferenceTriggers, Aliases & Timers

Triggers, Aliases & Timers

Functions for automation: responding to MUD output, creating shortcuts, and timed actions.


Triggers

Triggers automatically execute code when specific text patterns appear in MUD output.

addTrigger

Add a trigger that fires when text matches a pattern.

local triggerId = addTrigger(pattern, callback, options?)
ParameterTypeRequiredDescription
patternstringYesPattern to match
callbackfunctionYesFunction to call on match
optionstableNoOptions table (see below)

Options Table:

OptionTypeDefaultDescription
typestring”substring”Match type: “substring”, “wildcard”, “regex”, “exact”
enabledbooleantrueWhether trigger is active
prioritynumber50Trigger priority (lower = higher priority)
oneShotbooleanfalseRemove trigger after first match
keepEvaluatingbooleantrueContinue evaluating other triggers
omitFromOutputbooleanfalseHide matching line from output
caseSensitivebooleanfalseCase-sensitive matching
matchRawTextbooleanfalseMatch raw text (with ANSI codes)
groupstringnilGroup name for batch operations
colorizetablenilHighlight matches with colors

Callback Parameters:

The callback receives the matched line and any captured groups:

function(line, wildcards) -- line: the full matched line -- wildcards: table of captured groups (for regex patterns) end

Example:

-- Simple substring trigger addTrigger("You are hungry", function() send("eat bread") end) -- Regex trigger with captures addTrigger("(\\w+) tells you '(.+)'", function(line, matches) local sender = matches[1] local message = matches[2] print("Tell from " .. sender .. ": " .. message) utilprint("$G[Tell] $C" .. sender .. "$w: " .. message) -- Green "[Tell]", Cyan sender end, { type = "regex" }) -- One-shot trigger (removes itself after firing) addTrigger("Welcome to the game", function() send("look") print("Auto-looked on login!") utilprint("$Y[Login] $wAuto-look triggered") end, { oneShot = true }) -- Priority trigger (fires before others) addTrigger("DANGER:", function() send("flee") end, { priority = 10 }) -- Wildcard trigger (matches * and ? patterns) addTrigger("* gives you *", function(line, matches) local giver = matches[1] local item = matches[2] print("Received " .. item .. " from " .. giver) utilprint("$G[Received] $w" .. item .. " from $C" .. giver) -- Cyan giver name end, { type = "wildcard" }) -- Regex HP tracking addTrigger("HP: (\\d+)/(\\d+)", function(line, matches) local hp = tonumber(matches[1]) local maxHp = tonumber(matches[2]) setVariable("hp", hp) setVariable("maxhp", maxHp) end, { type = "regex" })

removeTrigger

Remove a trigger by its ID.

removeTrigger(triggerId)
ParameterTypeRequiredDescription
triggerIdstringYesThe trigger ID returned from addTrigger

Example:

local myTrigger = addTrigger("some pattern", function() -- handler end) -- Later, remove it removeTrigger(myTrigger)

enableTrigger

Enable a disabled trigger.

enableTrigger(triggerId)
ParameterTypeRequiredDescription
triggerIdstringYesThe trigger ID

Example:

enableTrigger(combatTrigger)

disableTrigger

Disable a trigger without removing it.

disableTrigger(triggerId)
ParameterTypeRequiredDescription
triggerIdstringYesThe trigger ID

Example:

-- Disable during safe areas disableTrigger(combatTrigger)

findTriggerByName

Find a trigger by its name.

local trigger = findTriggerByName(name)
ParameterTypeRequiredDescription
namestringYesThe trigger name

Returns: {id: string, name: string, enabled: boolean} or nil


toggleTriggerByName

Enable or disable a trigger by its name.

local success = toggleTriggerByName(name, enabled)
ParameterTypeRequiredDescription
namestringYesThe trigger name
enabledbooleanYesWhether to enable or disable

Returns: boolean - Whether the operation succeeded


toggleTriggerGroup

Enable or disable all triggers in a group.

local success = toggleTriggerGroup(groupName, enabled)
ParameterTypeRequiredDescription
groupNamestringYesThe group name
enabledbooleanYesWhether to enable or disable

Returns: boolean - Whether the operation succeeded

Example:

-- Add triggers to a group addTrigger("combat pattern 1", handler1, { group = "combat" }) addTrigger("combat pattern 2", handler2, { group = "combat" }) -- Disable all combat triggers at once toggleTriggerGroup("combat", false) -- Re-enable later toggleTriggerGroup("combat", true)

Aliases

Aliases intercept user input and transform or execute code based on patterns.

addAlias

Add an alias that matches user input.

local aliasId = addAlias(pattern, replacement, callback?)
ParameterTypeRequiredDescription
patternstringYesPattern to match in user input
replacementstringYesReplacement text or command
callbackfunctionNoOptional callback function

Example:

-- Simple text replacement addAlias("^nn$", "north;north") -- "nn" expands to "north;north" -- Alias with wildcards addAlias("^go (.+)$", "speedwalk $1") -- "go tavern" becomes "speedwalk tavern" -- Alias with callback addAlias("^heal (.+)$", "", function(matches) local target = matches[1] send("cast 'cure light wounds' " .. target) print("Healing " .. target .. "...") utilprint("$G[Heal] $wCasting on " .. target) end)

removeAlias

Remove an alias by its ID.

removeAlias(aliasId)
ParameterTypeRequiredDescription
aliasIdstringYesThe alias ID returned from addAlias

findAliasByName

Find an alias by its name.

local alias = findAliasByName(name)
ParameterTypeRequiredDescription
namestringYesThe alias name

Returns: {id: string, name: string, enabled: boolean} or nil


toggleAliasByName

Enable or disable an alias by its name.

local success = toggleAliasByName(name, enabled)
ParameterTypeRequiredDescription
namestringYesThe alias name
enabledbooleanYesWhether to enable or disable

Returns: boolean - Whether the operation succeeded


Timers

Timers execute code after a delay or at regular intervals.

addTimer

Add a timer that fires after an interval.

local timerId = addTimer(interval, callback, repeating?)
ParameterTypeRequiredDefaultDescription
intervalnumberYes-Interval in milliseconds
callbackfunctionYes-Function to execute
repeatingbooleanNofalseWhether to repeat

Example:

-- One-shot timer (fires once after 5 seconds) addTimer(5000, function() print("5 seconds have passed!") utilprint("$Y[Timer] $w5 seconds elapsed") end) -- Repeating timer (fires every 10 seconds) local autoSaveTimer = addTimer(10000, function() send("save") print("Auto-saved!") utilprint("$G[Save] $wAuto-saved!") end, true) -- Repeating timer for status updates (every minute) addTimer(60000, function() send("score") end, true)

removeTimer

Remove a timer by its ID.

removeTimer(timerId)
ParameterTypeRequiredDescription
timerIdstringYesThe timer ID returned from addTimer

Example:

local myTimer = addTimer(5000, callback, true) -- Stop the timer removeTimer(myTimer)

findTimerByName

Find a timer by its name.

local timer = findTimerByName(name)
ParameterTypeRequiredDescription
namestringYesThe timer name

Returns: {id: string, name: string, enabled: boolean} or nil


toggleTimerByName

Enable or disable a timer by its name.

local success = toggleTimerByName(name, enabled)
ParameterTypeRequiredDescription
namestringYesThe timer name
enabledbooleanYesWhether to enable or disable

Returns: boolean - Whether the operation succeeded


JavaScript-Style Timers

Convenience functions that match JavaScript’s timer API.

setTimeout

Execute a function after a delay (one-shot timer).

local timerId = setTimeout(callback, delay)
ParameterTypeRequiredDescription
callbackfunctionYesFunction to execute
delaynumberYesDelay in milliseconds

Returns: string - Timer ID for cancellation

Example:

-- Execute after 2 seconds setTimeout(function() print("Timer fired!") utilprint("$Y[Timeout] $wTimer fired!") end, 2000) -- Store ID for potential cancellation local timerId = setTimeout(function() send("look") end, 5000)

clearTimeout

Cancel a timeout before it fires.

clearTimeout(timerId)
ParameterTypeRequiredDescription
timerIdstringYesThe timer ID from setTimeout

Example:

local timerId = setTimeout(function() send("delayed command") end, 5000) -- Cancel it before it fires clearTimeout(timerId)

Complete Automation Example

-- Automation plugin print("Loading automation...") -- Auto-heal when health is low addTrigger("HP: (\\d+)/(\\d+)", function(line, matches) local hp = tonumber(matches[1]) local maxHp = tonumber(matches[2]) local percent = (hp / maxHp) * 100 if percent < 30 then colourNote("red", "", "!!! LOW HEALTH !!!") send("drink healing potion") end end, { type = "regex" }) -- Auto-loot after kill addTrigger("is DEAD", function() setTimeout(function() send("get all corpse") end, 500) end) -- Combat triggers local function attackHandler(line) print("Under attack!") utilprint("$R[Combat] $wUnder attack!") end addTrigger("attacks you", attackHandler, { group = "combat" }) addTrigger("swings at you", attackHandler, { group = "combat" }) -- Quick movement: /run north (runs 5 times) addAlias("^run (.+)$", "", function(matches) local direction = matches[1] for i = 1, 5 do send(direction) end end) -- Quick attack: /kk goblin addAlias("^kk (.+)$", "", function(matches) toggleTriggerGroup("combat", true) send("kill " .. matches[1]) end) -- Auto-save every 5 minutes addTimer(300000, function() send("save") print("Auto-saved!") utilprint("$w[Save] Auto-saved") end, true) -- Status check every minute addTimer(60000, function() send("score") end, true) print("Automation loaded!")
Last updated on