P

PlayMUD.online

Lua triggers

Lua Triggers

Use Lua scripts after fast MUD-line matching.

Lua triggers run in a browser worker. PlayMUD.online first checks a simple match mode, then runs the Lua script only when that line matches. Normal triggers still run first.

Where To Find Them

Open Automation and click Add Lua Trigger. Lua triggers can be placed in folders with other automation items.

A Lua trigger must compile before it can be enabled. If a parent folder is disabled, the trigger will not run even if the trigger itself is checked.

Match Modes

Incoming text is ANSI-stripped before matching. Choose the cheapest mode that fits the job.

  • contains matches text anywhere in the line.
  • starts with matches the beginning of the line.
  • ends with matches the end of the line.
  • exact matches the whole trimmed line.
  • regex enables JavaScript regular expressions and capture groups.

The case toggle controls whether text matching and regex matching are case-sensitive.

First Example

This trigger watches for a line like You receive 42 gold and prints a small colored note.

Pattern: ^You receive (\d+) gold
Match: regex

local amount = matches[2]
echo("<gold>Gold gained:<reset> " .. amount)

matches[1] is the whole matched line. matches[2] is the first captured part, which is the number inside (\d+). The word local means this temporary value is only used inside this run. The .. joins text together.

Line And Matches

Every Lua trigger receives two useful values: line, which is the current MUD line, and matches, which holds the matched text pieces.

echo("The full line was: " .. line)
echo("The matched text was: " .. matches[1])

Variables

Use vars.name for saved variables. Saved variables can be used later in normal commands with braces, such as {target}.

vars.target = "orc"
echo("Target is " .. vars.target)

This stores orc in a saved variable named target. Later, a normal command like kill {target} becomes kill orc.

Use normal command variables as {target} outside Lua.

Temporary State

Use state.name for values that should last while this browser session is active, but do not need to be saved with your profile.

state.last_gold_line = line
state.gold_seen = (state.gold_seen or 0) + 1
echo("Gold lines seen: " .. state.gold_seen)

The expression state.gold_seen or 0 means "use the old count if it exists, otherwise start at zero."

Actions

send("look")
send("look", 1) -- silent local echo

echo("<green>Green text<reset> normal text")
echo("<#12FA00>TrueColor<reset>")
echo("<bg:#202000>background<reset>")

gag()
sub("<green>Replacement line<reset>")

highlight("yellow")
highlight("white", "dark_blue")

timer(5, [[ echo("<green>Five seconds later<reset>") ]])

echo() output does not launch triggers. gag() removes the matched MUD line. sub(text) removes the matched line and inserts formatted echo-style text in its place.

Echo colors persist between echo-style calls during one Lua event, then reset when the script ends. See the Echo Colors reference for names and TrueColor syntax.

timer(seconds, luaSource) schedules a one-shot browser-side Lua run. It returns an id that can be passed to killTimer(id). Use remainingTime(id) to check seconds left for an active timer.

Allowed Runtime

The Lua environment exposes common pure Lua helpers, plus string, table, math, and os.time(). Browser and system APIs such as require, package, io, debug, DOM access, fetch, and storage are not exposed to user scripts.

Live trigger runs have a CPU watchdog. If a script hangs, PlayMUD.online terminates that worker, disables only that Lua trigger, and writes the timeout to the Activity tab.

PlayMUD.online has built-in limits for sends, echoes, highlights, stored values, and run time so one script cannot overwhelm the client.

Because actions are returned from the worker after the script finishes, send(), echo(), gag(), sub(), and highlight() are applied in script order after a successful run.