[Home] [Downloads] [Search] [Help/forum]

Fun with Triggers

Triggers are a very powerful aspect of using MUSHclient, however they can be a bit daunting at first. This page describes how to use them.


What is a trigger exactly?

Triggers match on something received from the MUD. They trigger some sort of action by MUSHclient, hence their name.

They have a counterpart that matches on what you type, called an "alias".


What can I do with triggers?


How do I get a trigger to match?

You normally match on incoming text, but you can also match on the colour of an incoming line.

There are two sorts of matches you can do:

  1. Normal, with wildcards
  2. Regular expression

Normal matching

A normal trigger (ie. with "regular expression" not checked) just matches on literally what is entered in the "Trigger" box, with optional wildcards represented by asterisks. You can have up to 9 asterisks, each representing some "unknown" text that might vary from line-to-line (eg. the name of someone or something).

Examples:

To match on Trigger
Rhayctred pages: I saw Ibydan down by the river.
* pages: *
From afar, Ocalef sighs
From afar, *
Fray says, See you later
* says, *
<newbie> Wiciramar says, "hi everyone"
<*> * says, "*"
CHAT: messages
CHAT: *
GAME: messages
GAME: *
(any line with "Mireatha" in it)
*Mireatha*

One restriction on normal triggers is that you can't match on the "*" character itself, as it is a wildcard symbol. To do that, you would need to use a regular expression (see below), and "escape" the "*" by putting a backslash in front of it.

For example, to match a line starting with an asterisk, you could match on this (with a regular expression):

^\*

Regular expression

Regular expressions are a bit more complex, but give you more power over what you match on.

A couple of simple rules:

^
Matches the start of the line
$
Matches the end of the line
.
Matches any character
*
Matches zero or more of the previous character or set (so, ".*" matches any number of anything)
+
Matches one or more of the previous character or set (eg. "be+d" matches "bed", "beed", "beeed" and so on.)
?
Matches zero or one of the previous character or set (eg. "dogs?" matches "dog" or "dogs")
\d
Matches any decimal digit
\D
Matches any character that is not a decimal digit
\s
Matches any whitespace character
\S
Matches any character that is not a whitespace character
\w
Matches any "word" character.
\W
Matches any "non-word" character
\b
Word boundary
\B
Not a word boundary
[abc]

A set of characters. Matches anything inside the square brackets, in this case, "a", "b" or "c"

Sets can include ranges of characters, eg. [A-Z] will match from "A" to "Z".

Sets can also include the special sequences above, eg. [\dA-F] would match a decimal digit, or "A" to "F".

[^abc]
A set of characters. Matches anything that is not inside the square brackets, in this case, anything except "a", "b" or "c"
\\
Matches "\"
\[
Matches "[" (backslash followed by anything that is not a letter or number just matches that character)

Definitions

A "word" character is any letter or digit or the underscore character, that is, any character which can be part of a Perl "word".

A word boundary is a position in the subject string where the current character and the previous character do not both match \w or \W (i.e. one matches \w and the other matches \W), or the start or end of the string if the first or last character matches \w, respectively.

Examples:

To match on Trigger
Any line with numbers in it
[0-9]+

or


\d+
A line starting with "Nick"
^Nick
A line ending with "dungeon"
dungeon$
Rhayctred pages: I saw Ibydan down by the river.
^.+ pages\: .+$
From afar, Ocalef sighs
^From afar, .+$
Fray says, See you later
^.+ says, .+$
<newbie> Wiciramar says, "hi everyone"
^\<.+\> .+ says, \".+\"$
CHAT: messages
^CHAT:.+$
GAME: messages
^GAME:.+$

(any line with "Mireatha" in it)

Will only colour the word "Mireatha"

Mireatha

(any line with "Mireatha" in it)

Will colour the whole line.

^.*Mireatha.*$

The interesting thing about regular expressions is that they can be made to match only a single word (for colouring purposes). Thus, a simple regular expression "dog" will match the word "dog", and if you have the trigger set to change the colour, then only the colour of the word "dog" will change. If the word "dog" is likely to appear more than once in a particular paragraph, then you should also check "repeat on same line" so that all instances are coloured.


Making regular expressions check for alternatives

Another powerful thing you can do with regular expressions is to look for "this" or "that".

For instance, if you want to make a trigger warn you if one of Cigowyr, Herrach, Crael or Wiceadric has paged you, you can match like this:

^(Cigowyr|Herrach|Crael|Wiceadric) pages\: .+$

The "|" symbol means "or", so the expression matches on one name or another. You can extend this idea to matching on whether they page or say something, like this:

^(Cigowyr|Herrach|Crael|Wiceadric) (pages\:|says,) .+$

You probably want to check "ignore case" in case their name is given as "cigowyr" rather than "Cigowyr".

How to gag annoying players

Simply set up a regular expression like the one above (substituting the relevant player names, of course), and then check "omit from output". Any paragraphs matching that trigger will be discarded from your output window.

If you want to let them know you have them gagged you could put something like this in the "Send" box:

page %1 = I am ignoring you.

Note - it might be unwise to set up an "auto-response" like the one above, because it could be used as the basis of a Denial Of Service (DOS) attack. If two players each set up an auto-response like that, then they will get into a loop, as the response from one player triggers the response from the other, and so on. Especially if they have "omit from output" set, they will not even be aware that they are causing a great overhead for the MUD, as it continually sends the messages backwards and forwards between the two players.

What you could do to guard against this would be to make the trigger call a script routine, and in the script count how many times it has been called. After (say) 20 times it could notify you (using world.note) or disable the trigger, so you could take corrective action (like complaining to an admin about the other player).


Matching on colours

You can use a trigger to match on the colour of an incoming line, rather than its contents. First you must specify some text to match on, even if it is just "*" (everything). Then select from the combo box what foreground and background colour you want (eg. red on green). You can also check "bold", "italic" or "inverse". The default is any colour, any style.

This is useful in MUDs that display room names, for instance, in white, and if a creature attacks you, in red.


Matching on everything except a word

In some cases, you might want to match on everything except one word. For example, in SMAUG both room names and exits are displayed in white on black. You could detect room names by setting the match string like this:

Trigger: ^(?!Exits:).*$
Match: white on black, bold
Regular expression: Checked

The expression "(?!Exits:)" means not the word "Exits:".

Another real-life example was where a player wanted to congratulate other players when they reached another level, but not congratulate himself. He could do that like this:

Trigger: ^(?!Caeth )(\w*) has risen to .*$
Regular expression: Checked
Send: say Congratulations %1!

This example assumes the player's name is Caeth.


[Back] [Home]
Written by Nick Gammon - 5K

Comments to Gammon Software support

[Best viewed with any browser - 2K]    Internet Contents Rating Association (ICRA) - 2K    [Hosted at HostDash]

Page updated on Tuesday, 6 December 2005