Register forum user name Search FAQ

MUSHclient scripting

Description of MUSHclient world function: world.AddTrigger


Name AddTrigger
Type Method
Summary Adds a trigger
Prototype long AddTrigger(BSTR TriggerName, BSTR MatchText, BSTR ResponseText, long Flags, short Colour, short Wildcard, BSTR SoundFileName, BSTR ScriptName);
Description

Adds a trigger to the list of triggers. If you want to specify the sequence number of the trigger, or where the response text is to be sent to, use AddTriggerEx.

For AddTrigger they default to:
Sequence: 100
Send to: world

Name: name of this trigger - may be empty (see rules for names below)
Match_text: what to match on
Response_text: what to send back to the world
Flags: various flags, see list below
Colour: what colour to draw triggered text, see list below
Wildcard: Copy which wildcard to the clipboard (0 = none), otherwise 1 to 10.
SoundFileName: Which sound file to play
ScriptName: Which script subroutine to execute

Flags

The flags can be one or more of the constants below. For example, to omit from log and omit from output, the flags would be 6. Preferably use the constant declarations in your script file, and "OR" them together. E.g.

VBscript: eOmitFromLog or eOmitFromOutput
JScript: eOmitFromLog | eOmitFromOutput

VBscript:

const eEnabled = 1 ' enable trigger
const eOmitFromLog = 2 ' omit from log file
const eOmitFromOutput = 4 ' omit trigger from output
const eKeepEvaluating = 8 ' keep evaluating
const eIgnoreCase = 16 ' ignore case when matching
const eTriggerRegularExpression = 32 ' trigger uses regular expression
const eExpandVariables = 512 ' expand variables like @direction
const eReplace = 1024 ' replace existing trigger of same name
const eTemporary = 16384 ' temporary - do not save to world file
const eTriggerOneShot = 32768 ' one shot - delete after firing

JScript:

var eEnabled = 1; // enable trigger
var eOmitFromLog = 2; // omit from log file
var eOmitFromOutput = 4; // omit trigger from output
var eKeepEvaluating = 8; // keep evaluating
var eIgnoreCase = 16; // ignore case when matching
var eTriggerRegularExpression = 32; // trigger uses regular expression
var eExpandVariables = 512; // expand variables like @direction
var eReplace = 1024; // replace existing trigger of same name
var eTemporary = 16384; // temporary - do not save to world file
var eTriggerOneShot = 32768; // one shot - delete after firing

PerlScript constants:

my $eEnabled = 1; # enable trigger
my $eOmitFromLog = 2; # omit from log file
my $eOmitFromOutput = 4; # omit trigger from output
my $eKeepEvaluating = 8; # keep evaluating
my $eIgnoreCase = 16; # ignore case when matching
my $eTriggerRegularExpression = 32; # trigger uses regular expression
my $eExpandVariables = 512; # expand variables like @direction
my $eReplace = 1024; # replace existing trigger of same name
my $eTemporary = 16384; # temporary - do not save to world file
my $eTriggerOneShot = 32768; # one shot - delete after firing

Colours

VBscript:

const NOCHANGE = -1
const custom1 = 0
const custom2 = 1
const custom3 = 2
const custom4 = 3
const custom5 = 4
const custom6 = 5
const custom7 = 6
const custom8 = 7
const custom9 = 8
const custom10 = 9
const custom11 = 10
const custom12 = 11
const custom13 = 12
const custom14 = 13
const custom15 = 14
const custom16 = 15

JScript:

var NOCHANGE = -1;
var custom1 = 0;
var custom2 = 1;
var custom3 = 2;
var custom4 = 3;
var custom5 = 4;
var custom6 = 5;
var custom7 = 6;
var custom8 = 7;
var custom9 = 8;
var custom10 = 9;
var custom11 = 10;
var custom12 = 11;
var custom13 = 12;
var custom14 = 13;
var custom15 = 14;
var custom16 = 15;

PerlScript:

my $NOCHANGE = -1;
my $custom1 = 0;
my $custom2 = 1;
my $custom3 = 2;
my $custom4 = 3;
my $custom5 = 4;
my $custom6 = 5;
my $custom7 = 6;
my $custom8 = 7;
my $custom9 = 8;
my $custom10 = 9;
my $custom11 = 10;
my $custom12 = 11;
my $custom13 = 12;
my $custom14 = 13;
my $custom15 = 14;
my $custom16 = 15;


* Rules for names

Names of triggers, aliases, timers and variables must follow these rules:

a. Start with a letter (A-Z)
b. Be followed by letters (A-Z), numbers (0-9) or the underscore character (_)

VBscript example
world.addtrigger "monster", "* attacks", "flee", 1, 14, 0, "", ""
Jscript example
world.AddTrigger("monster", "* attacks", "flee", 1, 14, 0, "", "");
PerlScript example
$world->AddTrigger("monster", "* attacks", "flee", 1, 14, 0, "", "");
Python example
world.AddTrigger("monster", "* attacks", "flee", 1, 14, 0, "", "")
Lua example
AddTrigger("monster", "* attacks", "flee", trigger_flag.Enabled , custom_colour.Custom15, 0, "", "")
Lua notes
The script name is optional.

The trigger flags are built into the "trigger_flag" table, as follows:

Enabled = 1
OmitFromLog = 2
OmitFromOutput = 4
KeepEvaluating = 8
IgnoreCase = 16
RegularExpression = 32
ExpandVariables = 512
Replace = 1024
Temporary = 16384
LowercaseWildcard = 2048
OneShot = 32768

The colour names for custom colours are built into the "custom_colour" table, as follows:

NoChange = -1
Custom1 = 0
Custom2 = 1
Custom3 = 2
Custom4 = 3
Custom5 = 4
Custom6 = 5
Custom7 = 6
Custom8 = 7
Custom9 = 8
Custom10 = 9
Custom11 = 10
Custom12 = 11
Custom13 = 12
Custom14 = 13
Custom15 = 14
Custom16 = 15
CustomOther = 16
Returns eInvalidObjectLabel: The trigger name is not valid
eTriggerAlreadyExists: A trigger of that name already exists
eTriggerCannotBeEmpty: The "match_text" cannot be empty
eScriptNameNotLocated: The script name cannot be located in the script file
eBadRegularExpression: The regular expression could not be evaluated
eOK: added OK

See also ...

Function Description
AddTriggerEx Adds a trigger - extended arguments
DeleteGroup Deletes a group of triggers, aliases and timers
DeleteTrigger Deletes a trigger
DeleteTriggerGroup Deletes a group of triggers
EnableGroup Enables/disables a group of triggers, aliases and timers
EnableTrigger Enables or disables a trigger
EnableTriggerGroup Enables/disables a group of triggers
GetTrigger Gets details about a named trigger
GetTriggerInfo Gets details about a named trigger
GetTriggerList Gets the list of triggers
GetTriggerOption Gets the value of a named trigger option
ImportXML Imports configuration data in XML format
IsTrigger Tests to see if a trigger exists
SetTriggerOption Sets the value of a named trigger option

Search for script function

Enter a word or phrase in the box below to narrow the list down to those that match.

The function name, prototype, summary, and description are searched.

Search for:   

Leave blank to show all functions.


Return codes

Many functions return a "code" which indicates the success or otherwise of the function.

You can view a list of the return codes


Function prototypes

The "prototype" part of each function description lists exactly how the function is called (what arguments, if any, to pass to it).

You can view a list of the data types used in function prototypes


View all functions

[Back]

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.