Mob Triggers
AddTrigger Command
The addtrigger command is defined as a separate command. This is because the mob command may not be used outside of a trigger.
addtrigger <name> <type> <call> [<trigger>]
Adds a trigger to the mob. Use <name> to give the trigger an unique name. Non unique names will be rejected. Also numbers are allowed names. This name can be used to delete the trigger later. Type is the trigger type, like “greet”, “grall”, “bribe”, “kill”, etc. Trigger types are described later. <call> is an TCL-script that should be executed. Normally this will be the name of a procedure to execute. The <trigger> gives the trigger condition. This should be a TCL command (or script) that returns a boolean. If the boolean is true, the <call> script will be executed. If no trigger condition is given, the call script will always be executed.
The <trigger>-script may generate variables that then can be used in the <call> script. The <trigger> script has also access to all other functionality you would normally have in a TCL-mobprog.
Trigger Types
Triggers are fairly easy to add, but this basic list should hold for most needs. Their names, argument list syntaxes, and translation into more articulate English are given below. Some triggers generate a trigger value. This value can be accessed with the [trig] command or trough the $::t variable. The trig command has a lot of routines for easy access to these trigger values.
mob triggers Command Reference
- act
- bribe
- buy
- combat
- entry
- exit
- give
- greet
- hunting
- interpret
- leave
- load
- lookat
- recall
- spec
- speech
- sun/day
- time
- weather
trigger act
The trigger value is the non parsed text string. When someone smiles it would be: $n smiles happily.
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.
trigger bribe
This trigger is activated whenever money is given to the mobile. Normally you would use the trig compare command to check the amount of money given. Note that if the script is not triggered (because of too little or much money having been given), the mobile still keeps the money.
trigger prebuy
This trigger is tested after the normal checks if an object can be bought at the shop and before the haggle and deduction of money. If it returns FALSE, the deal is off and the command is finished. If it returns TRUE the objects will be actually bought.
trigger buy
This trigger is tested with just before the object is transfered to the player. It can return 0: Player is not allowed to buy it, 1: Player is allowed to buy it and 2: The player is allowed to buy it but the shopkeeper doesn't give it yet.
trigger postbuy
This trigger is tested with just before the end of the command, now this is time to give a receipt or something else. This is the only trigger possible for petshop-keepers.
trigger pre_attack
The trigger fires when somebody is trying to start a fight. If the trigger returns false, a fight will NOT break out. Take care, for the opposite is not true: returning true will not guarantee a fight!
trigger kill
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 room mload).
trigger fight
Useful for giving mobiles combat attitude. It is checked every PULSE_VIOLENCE when the mobile is fighting. Can be used to cast spells (see 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.
trigger hpcnt
Is activated at each PULSE_VIOLENCE when the mobile is fighting. The normal use it to use the trig hpcnt command to check if the number of hitpoints of the mobile are below a 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).
trigger death
When the mobile dies the mobile performs the mobprog 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 mob remove), or create some (see mob oload), or cast a spell (see mob cast) on the killer and the room, or even goto a new location (see 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).
trigger killed
This is the same as the "death" trigger, but then based on the view of the person/mob who made the kill instead of the mob being killed.
trigger surrender
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.
If the trigger returns FALSE, the fighting will continue. If the trigger returns TRUE, the mob will accept the surrender.
trigger entry
The opposite of greet trigger. Whenever 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.
In an entry program, the mobile can only refer to a random PC -- 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.
trigger exit
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. Normally you can use the trig exits command to check the trigger value.
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 char goto or char group { char goto <location>}). Also, this event is not triggered when a character flees from combat or the mobile is not in its default position.
trigger exall
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.
trigger give
Normally you could use the trig give command to check for the object, but you could also write your own TCL-script to check if the object is the one you want.
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 mobprog list is essentially a default response.
trigger greet
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.
trigger grall
Like greet, but it can be triggered even if the mobile didn't see the arrival (i.e. sneak, invisible, etc) or is busy. Most useful for faking teleport rooms or for impassable guardians.
trigger walked
This trigger is tested the moment the mob has found its pey/room.
trigger notfound
This trigger is tested the moment the mob is not hunting anymore because the room or prey has not been found.
trigger interpret_unknown
This trigger is tested every time a character is entered a command which wasn't recognized as a valid command.
NOTE: Both mobs and players can trigger this trigger.
trigger pre_interpret
This trigger is tested when a character is going to execute a valid command but the command hasn't been executed yet. If the procedure returns a TRUE, the command is blocked.
NOTE: Both mobs and players can trigger this trigger.
trigger post_interpret
This trigger is tested every time a character a valid command is executed.
NOTE: Both mobs and players can trigger this trigger.
trigger pre_social
This trigger is tested when a character is going to execute a social but the social hasn't been executed yet. If the procedure returns a TRUE, the social is blocked.
NOTE: Both mobs and players can trigger this trigger.
trigger social
This trigger is tested every time a character a social is executed.
NOTE: Both mobs and players can trigger this trigger.
trigger leave
Works just like the exit trigger, but it doesn't prevent the player from leaving the room.
trigger leall
The same as leave 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.
trigger load
Happens when a mob is loaded and placed into a room. Note that this trigger doesn't go off for pets loaded during the loading of the player.
trigger pre_lookat
This trigger is tested before a person looks at a mob. If it returns FALSE, the look will not continue. If it returns 'true' the look will continue.
trigger lookat
This trigger is tested after a person looks at a mob.
trigger pre_recall
This trigger is tested before a player is going to recall. If it returns FALSE, the recall will not continue.
trigger recall
This trigger is tested just before the player is disappearing from the room.
trigger recall_to
This trigger is tested after a player successfully recalled.
trigger pre_spec
Triggers before a special action is taken by a mob. eg. trash being picked up by a janitor.
trigger spec
Triggers after a special action is taken by a mob. eg. trash being picked up by a janitor.
trigger speech
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.
trigger sunset
Happens after the message "the sun disappears in the west".
trigger sunrise
Happens after the message "the sun rises in the east".
trigger end_day
Happens after the message "the night has begun."
trigger start_day
Happens after the message "the day has begun."
trigger timer
Every mob has a timer, this timer can be started with the mob timer command. Normally you issue an mob timer 0 command to let the timer start counting from 0. Every PULSE_SOMETHING the timer trigger is called. You can use trig compare to check the trigger value. A good example of its use can be found in smurf.are.
NOTE: The timer can be started and stopped with the mob timer command.
trigger hour
This trigger is tested every hour in MUD time. The trigger value is the time of day.
NOTE: No mobprogs will be successful when the mobile is charmed (since it has no self volition, it should act like it has none) to protect mobiles which are given special powers from being implemented by a player.
trigger random
This trigger is checked at each PULSE_MOBILE. 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.
trigger delay
This trigger activates when the delay of a mobile (set with the 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 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.
trigger weather
Trips every time the weather changes. State is one of 'cloudless', 'cloudy', 'raining', 'lightning'.