Triggers | Commands | Control Flow | 'If' Checks | Variables | VNUMs |
The backbone of all MPROGs are the triggers. They are procedure calls placed in the mud code which provide the context for what is going on around the mobile. So, if something happens in the mobile's room and a trigger is activated then a list of commands is sent to the interpreter making it do an appropriate function (hence the MPROG).
Here is a list of trigger types:
ACT | BRIBE | DEATH | DELAY |
ENTRY | EXALL | EXIT | FIGHT |
GIVE | GRALL | GREET | HPCNT |
KILL | RANDOM | SPEECH | SURR |
For Further explaination of these see 'help MPROG_TRIGGER_(name)' (i.e. 'help MPROG_TRIGGER_ACT')
Keyword: 'act'
Argument: string
The argument is a phrase, a text string. The trigger is activated whenever the phrase or string is seen by the mobile.
NOTE: Most general trigger. Applies to almost every event which happens in the mud. Anytime the function act() is called with a message to be delivered TO_CHAR,TO_VICT,TO_ROOM,etc. the act can be triggered. Basically this will trigger on almost everything you'll ever want. Output of "say", "shout" and "emote" do not trigger this event.
Keyword: 'bribe'
Argument: number
The argument is any positive integer number.
NOTE: This trigger is activated whenever money is given to the mobile. If the amount given exceeds the number, then process the commands. Note again, that an argument of '1' would act as a default response. Also note that if the script is not triggered (because of too little money having been given), the mobile still keeps the money....
ROM 2.4 NOTE: Since ROM 2.4 has two different types of currency (gold and silver coins) for bribe trigger the amount to be given is converted to silver coins with the rate of 1 gold = 100 silver. Thus, the number in the argument should be the expected amount in silver coins.
Keyword: 'death'
Argument: number
The argument is a percent 1 - 100
NOTE: When the mobile dies, if the random percentage is less than the argument the mobile performs the MOBprogram commands rather than the usual death_cry() sequence. This is done before the corpse is made, so the commands can be considered the mobiles last gasp. It could perhaps destroy the items it was holding (see MPROG_MOB_REMOVE and MPROG_MOB_JUNK), or create some (see MPROG_MOB_OLOAD), or cast a spell (see MPROG_MOB_CAST) on the killer and the room, or even goto a new location (see MPROG_MOB_GOTO) and die there (with a text message, the corpse would seem to vanish) The position of the mobile is set to STANDING, and so it can do all the normal commands, without worrying about being DEAD. However, even if the mobile restores itself to full hitpoints, it will still die.
This is not a way to immortal mobiles. However, the last thing this mobile does could be to goto some vacant room, load a fresh version of itself, drop all its items, force the new mobile to get all the items and wear them, send the new mobile back to the character who killed it and force the new mobile to attack that character. Along with a text message which said the mobile restored itself, this might be a convincing effect (note that your kitten could turn into a dragon this way, too).
Keyword: 'delay'
Argument: number
The argument is a percentage chance.
NOTE: This trigger activates when the delay of a mobile (set with the MPROG_MOB_DELAY command) expires. This trigger can be used to create staged mobile behavior, for example, a guardian could see a player entering a room, give a warning and activate a delay. If the player is still present when the delay expires, the guard would attack the player (see also MPROG_MOB_REMEMBER). A mobile can have several delay triggers, but every time the delay timer expires, all the triggers are checked and the first successful one executed.
Keyword: 'entry'
Argument: number
The argument is a percentage chance.
NOTE: The opposite of greet trigger. Whenver the mobile itself enters a new room, this can be triggered. Useful for looking around, or waving or other things that real PCs do when they arrive at a crowded room. IMPORTANT: In an entry program, the mobile can only refer to a random pc ($r in if checks) -- there's no way to know how many PCs exist in the room the mobile enters! Also, you must check visibility of the target in your program.
Keyword: 'exit'
Argument: number
Argument is the exit number (0:north 1:east 2:south 3:west)
NOTE: The opposite of entry trigger. This is activated when PC tries to leave a room through an exit indicated by the argument, and the mobile sees the person leave. Useful for having a single guardian to watch several exits. An exit trigger works better than an entry trigger, since you can refer to a specific PC instead of a random PC. IMPORTANT: If this event is triggered, the victim will not move through the exit. If necessary, you must move the character yourself in your program (see MPROG_MOB_TRANSFER and MPROG_MOB_GTRANSFER). Also, this event is not triggered when a character flees from combat or the mobile is not in its default position.
Keyword: 'exall'
Argument: number
Argument is the exit number (0 = north etc.)
The same as exit trigger, but it can be triggered even if the mobile cannot see the person trying to leave the room or if the mobile is busy (see MPROG_TRIGGER_EXALL).
Keyword: 'fight'
Argument: number
The argument is a percentage.
NOTE: Useful for giving mobiles combat attitude. It is checked every PULSE_VIOLENCE when the mobile is fighting. Can be used to cast spells (see MPROG_MOB_CAST), curse at the opponent, or whatever. Only the first successful one will be processed to save time. Also, this means that the mobile wont get lucky and 1. curse, cast a fireball and 2. spit on the player, cast another fireball in the same pulse.
Keyword: 'give'
Argument: string or object vnum
The argument is either a string containing words to be matched against the keywords of the object, or the word "all"; e.g. argument "long sword" will match to objects "long bow" and "small sword". Alternatively, the argument can be the virtual number of a single object.
NOTE: This is triggered whenever something is given to the mobile. Best used for quests. Since the first successful trigger is the only one of this type which is processed, having an "all" argument in the script at the end of the MOBprogram list is essentially a default response.
Keyword: 'grall'
Argument: number
Again a percentage argument.
NOTE: Like greet, but it can be triggered even if the mobile didn't see the arrival (i.e. sneak, invis, etc) or is busy. Most useful for faking teleport rooms or for impassable guardians (see MOB_TRIGGER_GREET).
Keyword: 'greet'
Argument: number
Again a percentage argument.
NOTE: Whenever someone enters the room with the mobile, and the mobile saw the person enter, this is checked. Good for shopkeepers who want to welcome customers, or for pseudo-aggressive mobiles which need to discriminate on who they attack. Greet trigger activates only when the mobile is not busy (fighting, sitting, sleeping etc.). If you want to be sure to catch all players, use grall.
Keyword: 'hpcnt'
Argument: number
The argument is a percentage.
NOTE: Is activated at each PULSE_VIOLENCE when the mobile is fighting. It checks to see if the hitpoints of the mobile are below the given percentage. Multiple hpcnt triggers should be listed in increasing order of percent since a 40% will always be activated before a 20% and, only the first successful trigger is performed (see also MOB FLEE).
Keyword: 'kill'
Argument: number
The argument is a percent once again.
NOTE: This trigger is checked whenever a PC attacks the mobile. The check occurs only ONCE, in the beginning of combat. Useful for summoning assistance, etc. (see MPROG_MOB_MLOAD).
Keyword: 'random'
Argument: number
The argument is a number betweeen 0 and 99 inclusive.
NOTE: This trigger is checked at each PULSE_MOBILE and if the argument is greater than a percentage roll the trigger is activated. This will happen even if there is no PC in the room with the mob, but there must be players in the same area. It is useful to give mobiles a bit of a personality. For instance a janitor who stops to spit tobacco, or complain about the hours, or wonder why there are no woman janitors on muds, or a fido which barks or growls or pees on the curb is much more alive than one which just sits there scavenging.
Note that this trigger is checked only when there are players in the area. If you want this event to be triggered always, you must set the ACT_UPDATE_ALWAYS flag of the mobile.
Keyword: 'speech'
Argument: string
NOTE: This is only triggered when the phrase is contained in a message which has been said by a PC in the same room as the mob. The PC restriction is not necessary, but makes infinite loops between two talking mobiles impossible. It also makes it impossible for two NPC's to stand and discuss the weather however.
IMPORTANT: It should be noted that the phrase is case sensitive. If you look at manors mostly, the speech mprog for their invitations is set twice, once lowercase and again in uppercase. If you have a phrase set to 'Hi', and do say 'hi', even though the game will capitalize it to 'Hi' it will not work since the real phrase was 'hi'.
Keyword: 'surr'
Argument: number
The argument is a percentage.
NOTE: This trigger activates when the mobile is fighting and the opponent issues a "surrender" command. When triggered, both parties will cease fighting, and the mobile can accept the surrender (perhaps taking all equipment from the character with MOB REMOVE). Note that if the mobile does not accept the surrender, it must resume fighting with MOB KILL.
If a character surrenders and the mobile does not have a surrender trigger, or the trigger does not activate, the fight resumes normally.
To make things come alive, variables are needed. These are represented in the MOBprograms by using a dollar sign convention as in the socials. When the mud command is processed, these variables are expanded into the values shown below. Usually, it is best to use the short descriptions of mobiles and the names of players when speaking to them, but if you are performing an action to someone almost always you want the name. The title field for players is an extra that probably wont often be used.
$i the first of the names of the mobile itself.
$I the short description of the mobile itself.
$n the name of whomever caused the trigger to happen.
$N the name and title of whomever caused the trigger to happen.
$t the name of a secondary character target (i.e A smiles at B)
$T the short description, or name and title of target (NPC vs PC)
$r the name of a random PC in the room with the mobile
$R the short description, or name and title of the random PC
$q the name of the MOBprogram target (see MPROG_MOB_REMEMBER)
$Q the short description of the MOBprogram target
$j he,she,it based on sex of $i.
$e he,she,it based on sex of $n.
$E he,she,it based on sex of $t.
$J he,she,it based on sex of $r.
$k him,her,it based on sex of $i.
$m him,her,it based on sex of $n.
$M him,her,it based on sex of $t.
$K him,her,it based on sex of $r.
$l his,hers,its based on sex of $i.
$s his,hers,its based on sex of $n.
$S his,hers,its based on sex of $t.
$L his,hers,its based on sex of $r.
$o the first of the names of the primary object (i.e A drops B)
$O the short description of the primary object
$p the first of the names of the secondary object (i.e A puts B in C)
$P the short description of the secondary object
In place of any legal mud command in a MOBprogram, one can substitute a flow of control command. Here is the syntax for a flow of control command.
"if" " " {if_check_1} {argument} {operator} {value} NewLine
"or" " " {if_check_2} {argument} {operator} {value} NewLine
"or" " " {if_check_N} {argument} {operator} {value} NewLine
. . .
"and" " " {if_check_N} {argument} {operator} {value} NewLine
"and" " " {if_check_N} {argument} {operator} {value} NewLine
. . .
{program_command_1} NewLine
{program_command_2} NewLine
. . .
"break" NewLine
. . .
{program_command_N} NewLine
"else" NewLine
{program_command_1} NewLine
{program_command_2} NewLine
. . .
"break" NewLine
. . .
{program_command_N} NewLine
"endif" NewLine
Basically, it is: an 'if' line, followed by zero or more 'or' lines, followed by zero of more 'and' lines ('and' and 'or' lines can be in any order) followed by zero or more legal mud commands, which may contain a 'break' line, possibly followed by an 'else' line , followed by zero or more legal mud commands, which may contain a 'break' line, followed by an 'endif' line.
An IF_CHECK is a string which describes under what context to compare things.
The ARGUMENT is the reference point from which the LHS of an expression comes.
The OPERATOR indicates how the LHS and RHS are going to be compared.
The VALUE is the RHS of the expression to be compared by the operator.
The BREAK command bails out of the entire MOBprogram regardless of the level if nesting. (END is a synonym for BREAK).
The provided list of if_checks and their arguments are below. They should all be fairly obvious in what they do, but some of the more obtuse deserve a slight explanation. Any '==' operator can be replaced with any of the available ones described above. The argument $* refers to any of the variables which make sense for that if_check (i.e. for an if_check which is referencing a person the only valid variables would be $i, $n, $t, $r or $q). A value type of string is a sequence of characters. It does not need to be included in quotes or anything like that (i.e. if name $n fido ).
There are five types of if checks:
Type 1: Keyword and value
rand num Is random percentage less than or equal to num
mobhere vnum Is a NPC with this vnum in the room
mobhere name Is a NPC with this name in the room
objhere vnum Is an object with this vnum in the room
objhere name Is an object with this name in the room
mobexists name Does NPC 'name' exist somewhere in the world
objexists name Does object 'name' exist somewhere in the world
Type 2: Keyword, comparison and value
people == integer Is the number of people in the room equal to integer
players == integer Is the number of PCs in the room equal to integer
mobs == integer Is the number of NPCs in the room equal to integer
clones == integer Is the number of NPCs in the room with the same
vnum as the NPC who activated the program equal to integer
order == integer Is the order (of several similar NPCs) of the NPC
who activated the trigger equal to integer
hour == integer Is the hour (game time) equal to integer
Type 3: Keyword and actor
isnpc $* Is $* an NPC
ispc $* Is $* a PC
isgood $* Does $* have a good alignment
isneutral $* Does $* have a neutral alignment
isevil $* Does $* have an evil alignment
isimmort $* Is $* an immortal (level of $* > LEVEL_HERO)
ischarm $* Is $* affected by charm
isfollow $* Is $* a follower with their master in the room
isactive $* Is $*'s position > POS_SLEEPING
isdelay $* Does $* have a delayed MOBprogram pending
isvisible $* Is $* visible to NPC who activated the program
hastarget $* Does $* have a MOBprogram target in the room
istarget $* Is $* the target of NPC who activated the program
Type 4: Keyword, actor and value
affected $* 'affect' Is $* affected by 'affect'
act $* 'act' Is $*'s ACT bit 'act' set
off $* 'off' Is $*'s OFF bit 'off' set
imm $* 'imm' Is $*'s IMM bit 'imm' set
carries $* 'name' Is $* carrying object 'name'
wears $* 'name' Is $* wearing object 'name'
has $* 'type' Does $* have object of item_type 'type'
uses $* 'type' Is $* wearing object of item_type 'type'
name $* 'name' Is $*'s name 'name'
pos $* 'position' Is $*'s position 'position' (sleeping etc.)
clan $* 'name' Does $* belong to clan 'name'
race $* 'name' Is $* of race 'name'
class $* 'name' Is $*'s class 'name'
objtype $* 'type' Is $*'s item_type 'type'
Type 5: Keyword, actor, comparison and value
vnum $* == integer Is $*'s virtual number equal to integer
hpcnt $* == integer Is $*'s hitpoint percentage equal to integer
room $* == integer Is vnum of the room $* is in equal to integer
sex $* == integer Is $*'s sex equal to integer
level $* == integer Is $*'s level equal to integer
align $* == integer Is $*'s alignment equal to integer
money $* == integer Does $* have money (in silver) equal to integer
objval# $* == integer Is $*->value[#] equal to integer (# from 0-4)
rank $* == integer Is $* equal to rank level 1 - 10 (10 being mayor)
temple $* == integer Is $* equal to vnum of temple's recall room.
MOBcommands are special commands that allow mobiles to perform immortal-like actions within a MOBprogram (transferring players or loading items, for example). Most MOBcommands are wiz commands which have been changed to allow for mobiles to perform the commands. All MOBcommands are preceded with the word 'MOB' on the command line.
ASOUND | AT | CALL | CANCEL |
CAST | DAMAGE | DELAY | ECHO |
ECHOAROUND | ECHOAT | FLEE | FORCE |
FORGET | GECHO | GFORCE | GOTO |
GTRANSFER | JUNK | KILL | MLOAD |
OLOAD | OTRANSFER | PURGE | REMEMBER |
REMOVE | TRANSFER | VFORCE | ZECHO |
To see further explainations type help MPROG_MOB_(name) (i.e. help MPROG_MOB_ASOUND)
Syntax: MOB ASOUND [string]
ASOUND prints the text string to the rooms around the mobile in the same manner as a death cry. This is really useful for powerful aggressives and is also nice for wandering minstrels or mobiles like that in concept. It does not print the string in the room with the mobile.
Syntax: MOB AT [location] [command]
Perfoms the command at the designated location. Very useful for doing magic slight of hand tricks that leave players dumbfounded.. such as metamorphing mobiles, or guard summoning, or corpse vanishing.
Syntax: MOB CALL [vnum] {victim} {target1} {target2}
This command lets you call MOBprograms from within a running one (i.e. to call a MOBprogram subroutine). The first parameter is the vnum of the program to execute, the second is the victim's name (for example $n), and the third and fourth are optional object names. All other parameters except vnum can be replaced with word 'null' indicating ignored parameter. MOBprograms can be called recursively, but as a safety measure, parser allows only 5 recursions.
Syntax: MOB CANCEL
MOB CANCEL resets the delay timer. see (MPROG_MOB_CALL)
Syntax: MOB CAST [spell] [target]
Causes a mobile to cast the specified spell. Target must be a variable or name.
Syntax: MOB DAMAGE [victim|'all'] [min] [max] {lethal}
Causes unconditional damage to the victim. Specifying "all" as victim causes damage to all characters in the room except the mobile. Min and max parameters define the minimum and maximum amounts of damage caused. By default, the damage is non-lethal, but by supplying the optional 'lethal' parameter, the damage can kill the victim. This command is silent, you must echo all messages yourself in the program. Useful for implementing special attacks for mobiles.
Syntax: MOB DELAY
MOB DELAY sets the time in PULSE_MOBILE after which the mobile's delay trigger is activated. If the mobile has a program defined for delay trigger, the program is executed when the timer expires.
Syntax: MOB ECHO [string]
MOB ECHO displays the string to everyone in the room. ECHOAT displays the string to the victim only.
Syntax: MOB ECHOAROUND [victim] [string]
MOB ECHOAROUND displays the string to everyone in the room except the victim.
Syntax: MOB ECHOAT [victim] [string]
MOB ECHOAT displays the string to the victim only.
Syntax: MOB FLEE
Causes a mobile to unconditionally flee from combat. Can be used for example with the hit point percentage trigger to simulate "wimpy" behavior.
Syntax: MOB FORCE [victim|'all'] [command]
Forces the victim to do the designated command. The victim is not told that they are forced, they just do the command so usually some mob echo message is nice. You can force players to remove belongings and give them to you, etc. The player sees the normal command messages (such as removing the item and giving it away.) Again, if the victim is "all" then everyone in the mobiles room does the command.
Syntax: MOB FORGET
MOB FORGET clears the target $q. Note that if the first time the mobile runs a program, $q is automatically set to the player who triggered the event (see also MPROG_MOB_REMEMBER).
Syntax: MOB GECHO [string]
GECHO prints the string to all players in the game.
Syntax: MOB GFORCE [victim] [command]
MOB GFORCE works like force except that it affects the group the victim belongs to (see MPROG_MOB_FORCE).
Syntax: MOB GOTO [location]
Moves the mobile to the room, mobile, object requested. It makes no message of its departure or of its entrance, so these must be supplied with echo commands if they are desired.
Syntax: MOB GTRANSFER [victim] [location]
MOB GTRANSFER works like transfer, except that the group the victim belongs to is transferred with the victim (see also MPROG_MOB_TRANSFER).
Syntax: MOB JUNK [object]
Destroys the object refered to in the mobile's inventory. It prints no message to the world and you can do things like junk all.bread or junk all. This is nice for having janitor mobiles clean out their inventory if they are carrying too much.
Syntax: MOB KILL [victim]
Lets a mobile kill a player without having to murder. Lots of MOBprograms end up with MOB KILL $n commands floating around. It works on both mobiles and players.
Syntax: MOB MLOAD [vnum]
MLOAD creates a mobile and places it in the same room with the mobile.
Syntax: MOB OLOAD [vnum] [level] {'room'|'wear'}
OLOAD loads the object into the inventory of the mobile. Even if the item is non-takable, the mobile will receive it in the inventory. This lets a mobile distribute a quest item or load a key or something. The optional 3rd parameter can be specified; 'room' means to load the object to the room, 'wear' means to force the mobile to wear the object loaded (useful for equipping mobiles on the fly).
Syntax: MOB OTRANSFER [object] [location]
Otransfer transfers an object in the room (see also MPROG_MOB_TRANSFER).
Syntax: MOB PURGE [argument]
Destroys the argument from the room of the mobile. Without an argument the result is the cleansing of all NPC's and items from the room with the exception of the mobile itself. However, MOB PURGE $i will indeed purge the mobile, but it MUST be the last command the mobile tries to do, otherwise the mud cant reference the acting mobile trying to do the commands and bad things happen. Especially do not use in conjuction with the DEATH trigger.
Syntax: MOB REMEMBER [victim]
This command enables the mobile to remember a player for future reference in a MOBprogram. The player can subsequently be referred as '$q' in programs activated by the mobile. Most commonly this command is used in delayed programs, where the mobile has to remember the player who triggered the original event, for example to continue conversation.
Syntax: MOB REMOVE [victim] [vnum|'all']
Lets the mobile strip an object of given vnum from the victim. Objects removed are destroyed. If the vnum is replaced with "all", the whole inventory of the victim is destroyed. This command is probably most useful for extracting quest items from a player after a quest has been completed.
Syntax: MOB TRANSFER [victim|'all'] [location]
Sends the victim to the destination or to the room of the mobile as a default. if the victim is "all" then all the characters in the room of the mobile are transfered to the destination. Good for starting quests or things like that. There is no message given to the player that it has been transfered and the player doesnt do a look at the new room unless the mob forces them to.
Syntax: MOB VFORCE [vnum] [command]
MOB VFORCE affects all mobiles with given vnum in the game world. This is useful for, for example, purging certain type of NPCs from the game (by forcing them to purge themselves).
Syntax: MOB ZECHO [string]
ZECHO prints the string to all players in the same area with the mobile.
A VNUM is the MOBprogram (Mprog) virtual number that identifies the program. The number must be unique across area files (like mobile and object vnums). The commands in the mprog can be any legal mud command, or a control flow command (if, else, or, and).