Triggers |
---|
What is a trigger exactly? What can I do with triggers? Colour a line to make it stand out (eg. colour chat channels in blue) Colour individual words to make them stand out (eg. colour your character's name) Highlight lines or words in bold, italic or underline Gag annoying players by discarding lines which contain messages from them Omit uninteresting things from the log file Play a sound when certain things happen Call a script routine to handle special events Send a response back to the MUD (eg. "wield sword" when you are attacked) Make editing attributes in a MUSH or MUCK easier 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: Normal, with wildcards 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 999 asterisks, each representing some "unknown" text that might vary from line-to-line (eg. the name of someone or something). For example: To match on pages:
Trigger:
To match on emotes:
Trigger:
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.) 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:
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:
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:
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 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:
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:
This example assumes the player's name is Caeth. Trigger scripts Triggers can execute script commands by simply putting the command into the "send" box and selecting "send to script". However for more complex scripts you can put scripts into your script file (see scripting configuration tab for the world) and then call the script from the trigger. To do this put the name of the script subroutine into the trigger's script box. The script subroutine must have three arguments (four for Lua), as follows: Name of the trigger The matching line An array of the first 10 wildcards (Lua - all wildcards) Lua only - a table of all the styles in the line An example script in the VBscript language would be:
Wildcard 10 is the entire matching sequence, which is not necessarily the same as the matching line in the case of regular expressions. Other wildcards can be accessed by using the GetTriggerWildcard script routine (for example, named wildcards, or wildcards over number 9). For Lua, wildcard 10 is the tenth wildcard, wildcard 11 is the eleventh wildcard and so on. All wildcards are returned in the Lua wildcards table. Wildcard subscript 0 is the entire matching line. Also in Lua named wildcards are returned in the wildcards table keyed by name. For Lua, the fourth argument (which you can optionally supply) is returned with a table of each style run for the triggered line. Inside that table (which starts at 1 for the first style) is a table per style. Per style, you will get four entries: textcolour - the RGB colour of the text in that style run backcolour - the RGB colour of the background colour in that style run text - the text of that style run length - the length of that style run style - style flags (or'ed together): bold=1, underline=2, blink=4. Wildcards A powerful feature in matching triggers or aliases is the ability to specify "wildcards" which are variable information that might change from time to time. For example:
In this case the asterisk represents the name of the unknown attacker. Using the wildcard in the "send" box ... To use this unknown quantity you can refer to it as %1 (for the first wildcard) in the "send" box, like this:
The second wildcard is %2, and so on. Wildcard %0 is a special case which represents the entire matching text. For wildcards above 9 you can use this syntax:
The number in the angled brackets can be from 0 to 999. Also, if you use regular expressions, you can name wildcards, like this:
This names the wildcard as "target". You can then use this name in a similar way:
Trigger evaluation Normally when a trigger matches, no further matching is done, for the main world, or the current plugin. That way a match "deals with" the current situation (eg. if your character is hungry). However if you check "keep evaluating" then further triggers in the list are evaluated as well. Regardless of the "keep evaluating" flag, triggers in other plugins are still processed, as each plugin is supposed to be independent. However a script can call the StopEvaluatingTriggers if it needs to stop further evaluation, either in the current plugin, or all plugins. This lets a script decide, at run-time, whether or not it handled the situation. See Also ... Topics
Aliases
Commands
(ConfigureTriggers) Define triggers
Dialogs
Edit trigger
Functions
(AddTrigger) Adds a trigger
(Help topic: general=triggers) |
Enter a search string to find matching documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.