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.

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.

Script Data

Each script receives the current stripped line and a Mudlet-style matches table.

-- Regex pattern: ^You receive (\d+) gold
echo("<gold>Gold: <reset>" .. matches[2])

-- Full matched text is matches[1]
echo("Line was: " .. line)

Variables

Global assignments write PlayMUD.online variables and autosave them with the rest of the profile. Variable writes are buffered until the worker finishes.

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

vars.backup_target = target

Use normal command variables as {target} outside Lua.

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>")

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

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

echo() output does not launch triggers. Echo colors persist between echo 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.

Action limits for sends, echoes, highlights, stored values, and run time are configured in web/src/modules/lua/config.js.

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