Register to post in forums, or Log in to your existing account
 

 Related 
Contents
Triggers
  #ACTION
  #ALARM
  #CONDITION
  #EVENT
  #FIRE
  #MXPTRIG
  #NOINPUT
  #ONINPUT
  #RAISEEVENT
  #REGEX
  #SENDSB
  #SETPROMPT
  #TEMP
  #TRIGGER
  %alarm
  %state
  Create/Modify Settings
  Introduction to Triggers
  Multistate triggers
  Pattern Matching
  Trigger Tester
  Trigger Types
  Triggers
Feature Reference
  Aliases
  Macros
  Variables
  Functions
  Classes
  Triggers
    Pattern Matching
    Auto Login
    Trigger Types
    Trigger Tester
    Multistate triggers
  Buttons
  Gauges
  Paths
  Menus
  Events
  Modules
  Windows
  Packages
  Shared Package Library
  Package Editor
  Docked Windows
  Customizeable Toolbars
  Sessions
  Expressions
  Automapper Module
  Database Module
  Syntax Checking
  Tab Completion
  Status items
  Preferences
  Simutronics Support
  Pueblo Emulation
  Keyboard shortcuts
  MXP
  Threads
  ATCP
  Script Debugger
  Timestamps
  Lua Scripting
Related Links:
  %match
  %regex
  #T+
  Terminology
  Feature Summary
  Auto Login
  Overriding the Mapper
  #WAITFOR
Triggers [[cmud_triggers]] 
Triggers are one of the most powerful and important features within CMUD. A Trigger contains a Pattern and a Script. When the text received from the MUD matches the Pattern, then the Script is executed. Triggers are also called Actions in other clients.

Triggers allow you to automate common actions on your MUD. They also provide quicker response to a dangerous situation. For example:

#TRIGGER {You are low on health!} {heal me}

could be used to match the text "You are low on health!" received from the MUD and immediately execute the script "heal me" faster than you could probably type this.

Of course, most MUDs do not provide such an easy text message to trigger on...that would be too easy. And MUDs don't like to make automation of your character easy. In fact, on some MUDs, using triggers might be illegal. However, most MUDs allow triggers as long as you are still sitting in front of the keyboard and actively playing. Many MUDs have rules against unattended triggers, such as running scripts overnight to auto-level your character or perform similar actions. Always check with the MUD you are playing to learn their rules so that you don't get your character banned for doing something wrong.

Wildcards

Just matching specific text from the MUD is nice, but sometimes the text from the MUD varies depending upon the situation. For example, let's say you are really evil and want to kill any character that enters your room. Many MUDs will display a message when another character enters your room, such as:

Zugg enters the room.

Now, if we had to create a different trigger for every different character that could enter the room, that wouldn't be very fun. In CMUD, you can use a variety of Pattern Matching characters within your pattern. For example, the %w wildcard will match any word. So you could create a trigger like this:

#TRIGGER {%w enters the room.} {kill ??}

But what do we use in the kill command? Is there a way to extract the text that was matched by the %w wildcard? Of course. Any "subpattern" can be saved to one of the %1..%99 argument variables by simply placing parenthesis around the part of the pattern you want to save. In the above example, we would put parenthesis around the %w to save the matched text into %1 and then use %1 in the kill command:

#TRIGGER {(%w) enters the room.} {kill %1}

CMUD counts the ( parenthesis to determine the %1..%99 number that the matched text should be stored. You can even nest () within each other to save complex subpatterns.

You can also save matched text to Named subpatterns. Simple place the $name: just after the (. For example:

#TRIGGER {($target:%w) enters the room.} {kill $target}

The named subpattern must start with a $ character (because it actually creates a Local variable). And there must not be any space between the ( and the $ characters.

Instead of using the CMUD pattern matching wildcard characters, you can also use normal Perl Regular Expressions. Simply select the Regular Expression option in the Advanced panel of the Edit Triggers screen, or use the #REGEX command instead of the #TRIGGER command to define the trigger on the command line. There is an excellent Regular Expressions Information site on the Internet where you can learn about the power of these kinds of patterns. However, in general a CMUD Pattern will be easier to understand than a Regular Expression. But since CMUD Patterns are compiled into regular expressions, they both have the same speed within CMUD.
Viewer Comments [0 - Post your comments]

Jump to:  

© 2009 Zugg Software. Hosted by Wolfpaw.net