Triggers

MUD Client triggers explained: Contains, Regex and Variable updated, multi-line patterns, examples to copy, and a checklist for a trigger that will not fire.


A trigger watches the text the game sends and runs an action when a line matches. Triggers answer greetings, eat when you are hungry, file tells into the Messages panel, hide spam, colour your enemies' names and warn you when your health is low. This guide covers how a trigger matches, a set of examples to copy, and what to check when one does not fire. It works the same on macOS and Windows.

Making a trigger

Open the Scripting window with the Aliases button in the toolbar (on Windows also Tools > Scripting), switch to the Triggers tab and click +. A trigger has:

The Regex tester checks a pattern against a line you paste in, and while you edit a regex the game text highlights what it would match.

The MUD Client trigger editor on Windows, testing a pattern against a line as you type

Contains, Regex or Variable updated

Contains fires when the pattern appears anywhere in the text. It is the simplest choice for a fixed message:

Regex treats the pattern as a regular expression, so it can match text that changes and hand the changing parts to the action. Each pair of brackets is a capture group: textOf(1) is the first, textOf(2) the second, and textOf(0) the whole match.

Variable updated fires when a value changes instead of when text arrives: a GMCP value such as Char.Vitals.hp, or a timer started with startTimer reaching zero. The GMCP triggers guide covers it.

How MUD Client reads the text

Two details explain most surprises.

A trigger can see several lines at once. When the game sends a burst of text, each trigger is handed everything that arrived since it last matched, not one line at a time. In a regex, ^ and $ match at the start and end of every line, but . also matches a line break. So (.*) can run past the end of its line into the lines below. To capture "the rest of the line", use ([^\n]*) instead:

Each piece of text fires a trigger once. After a trigger matches, it carries on from where its match ended, so the same line never fires the same trigger twice. Several matches in one burst each run the action.

Examples

File tells in the Messages panel

addComm(textOf(1) + ' tells you: ' + textOf(2));
playSound('tell');

playSound plays tell.wav or tell.mp3 from the sounds folder in your world's folder; see timers, toasts and sounds.

Catch a message that spans two lines

Put \n in the pattern where the line breaks. This waits for both lines before firing:

log('Killed ' + textOf(1) + ' for ' + textOf(2) + ' xp');

Colour a name

highlight recolours the matched text before it is shown. Colours can be names, hex values or a 256-colour index.

highlight('red', '');

Hide spam

gag removes the matched line so it never appears.

gag();

substitute('...') replaces the matched text instead of hiding it.

Warn when health is low

With a prompt like HP: 120/400 >, a regex trigger can read the numbers and send a notification, using debounce so a run of prompts warns you once rather than on every line:

var hp = parseInt(textOf(1), 10);
var max = parseInt(textOf(2), 10);
if (hp < max / 4 && debounce('lowhp', 30)) {
  notify('Low health: ' + hp + '/' + max);
}

If your game sends vitals over GMCP, a Variable updated trigger on Char.Vitals.hp does the same without a prompt; the status bar guide shows HP as a gauge.

Keep colours in a captured line

MUD Client matches the words of a line, not its colours, so a pattern cannot ask for "red text". When the colours matter, capture the line and use coloredOf(n) instead of textOf(n): it returns the captured text with its original colours.

When a trigger does not fire

Work down this list:

  1. Is it enabled? Check the Enabled box, and type #suspensions to see whether a script has paused it with suspendTriggers.
  2. Does the pattern match the real line? Copy the line from the game into the Regex tester. Extra spaces, a full stop, or a colour code you cannot see are the usual culprits. Use \s+ between words if the game sometimes sends two spaces or a tab.
  3. Contains or Regex? In Contains, characters like ., ( and ? are plain text. In Regex they are special, so a literal full stop is \. and a literal bracket is \(.
  4. Start of line. With Match from start of line on, or a pattern starting with ^, text in front of the match stops it. Turn the option off, or drop the ^, to test.
  5. Case. With Case specific on, You and you are different.
  6. It fires, but with the wrong text. Turn on Debugging to see what each capture held. A (.*) that swallowed the next line is the most common cause; use ([^\n]*).
  7. The action has an error. MUD Client reports a script that fails, along with the error. log('got here') in the action writes to the console, so you can see how far it ran.

Related

All guides · FAQ