Aardwolf MUD Home Page Link

Location: Home / Lua Coding / Lua Triggers

In designing the Lua / Mud trigger system we have tried to keep it as consistent with mobprogs as possible so it will be familiar to existing builders. The mobprog trigger types were also necessary to convert the old ROM areas to V3 as their flow is based on these trigger types. There are a number of new trigger types and options available with triggers, details are listed below.

Character Triggers

Character triggers are the type you will be most familiar with, and most work the same. Some have additional arguments that are passed through to Lua. The important thing to note is that most triggers in place so far exist only to support the conversion of mobprogs to Lua or for the academy. The Lua system can trigger on pretty much anything - post to the Aardwolf Lua forum if you have a need to trigger on something unavailable here.

act:
An 'act' trigger allows a mob to respond to actions in the room such as socials, or room echos from many commands. In ROM mobprogs, 'act' was widely used to catch social output. The need for 'act' triggers is reduced in v3 due to being able to trap command input in room progs. However, it still has its uses.
Note that some mud actions output messages to mobs in the room only, specificaly so that act progs can be triggered. If you have to capture act messages on a command that does not echo anything to the room, and roomprogs won't meet your need for whatever reason, contact Lasher to discuss adding mob-only output to the command. A good example of mob only output is when a player drops an item in a room.
Syntax to add: add act [prog id] "trigger phrase"
bribe:
A 'bribe' trigger allows a mob to respond only when given a minimum amount of gold.
Syntax to add: add bribe [prog id] [min gold]
death:
A 'death' trigger gives a mob a percentage chance to run a lua program upon death, before its corpse is created and it is removed from the game. Death triggers are often used to randomly load a piece of equipment or transfer a character to the next part of an area quest.
Syntax to add: add death [prog id] [percent chance]
delay:
An 'delay' trigger has a percentage chance to run after a mob executes an adddelay(seconds) statement from another prog. Usually a delay prog looks for a previously remembered char before continuing.
Syntax to add: add delay [prog id] [percent]
entry:
A 'entry' trigger is executed when a mob moves, not a player. Exit triggers are commonly used to keep a specific mob within a small group of rooms, or on a wandering guard to attack as it enters.
Syntax to add: add entry [prog id] [percent chance]
exall:
An 'exall' trigger runs when a player moves in a specific direction. N,E,S,W,U,D correspond to 0 through 5 for directions. Unlike 'exit' triggers, 'exall' triggers fire even if the mob is busy, and visibility is ignored.
Syntax to add: add exall [prog id] [dir]
exit:
An 'exit' trigger runs when a player moves in a specific direction. N,E,S,W,U,D correspond to 0 through 5 for directions. For 'exit' triggers to fire, the mob must not be occupied and must be able to see the player.
Syntax to add: add exit [prog id] [dir]
fight:
A 'fight' trigger gives a random chance for the program to be executed while the mob is actually in combat. Often used to cast spells, summon helpers or run away.
Syntax to add: add fight [prog id] [percent chance]
give:
A 'give' trigger caused the program to run when a mobile is given either a specific items, or if the last argument is 'all', any item. The item given to the mob is variable 'obj' in Lua and all functions that use an obj type variable can be applied to it. 'All' is commonly used with give triggers to cause the mob to return items other than those it is specifically interested in.
Syntax to add: add give [prog id] [objkey, or, "all"]
grall:
A 'grall' trigger adds a percentage chance to run a lua program when a player enters the room. The chance to trigger takes place regardless of the mob's current condition or whether or not the mob can see the player.
Syntax to add: add grall [prog id] [percent chance]
greet:
A 'greet' trigger adds a percentage chance to run a lua program when a player enters the room. The mob must not already be busy/sleeping and must be able to see the player for a chance to trigger the prog. See 'grall' for other options.
Syntax to add: add greet [prog id] [percent chance]
hpcnt:
A 'hpcnt' trigger causes a program to run when the mobile is in combat and its hit points fall below the percentage given.
Syntax to add: add hpcnt [prog id] [percent hp]
kill:
A 'kill' trigger adds a percentage chance to run a lua program when someone initiates combat with the mob. Usually used to stop combat or summon help. The academy guards have a 'kill' prog that transfers away anyone not level 201.
Syntax to add: add kill [prog id] [percent chance]
listen:
An 'listen' trigger has a percent chance to execute when a player uses the listen command on a mob.
Syntax to add: add listen [prog id] [percent]
random:
A 'random' trigger sets an event to run a program on a mob. For compatibility with old mobprogs, a 100% random runs, on average, every 3 seconds. 50% runs every 6 seconds etc.
Note that with random progs, the prog is triggered without a player causing it, so 'ch' is not defined. Random triggers usually cause a mob to echo or do something not involving another player, or find a random player in the room using randchar().
Syntax to add: add random [prog id] [percent]
speech:
speechexact:
A 'speech' trigger allows a prog to be called when the player says something. Speechexact requires the exact phrase to be entered whereas 'speech' will trigger if any part of the player's speech contains the trigger phrase.
There is a special case to 'speech' triggers - if the trigger phrase is set to 'all', the prog will be triggered on any speech in the room and what was actually said will be available in lua as a string using the variable 'charg'. Regular speech triggers are always checked before an 'all' trigger so they can be mixed. More than one 'all' trigger is pointless.
Syntax to add: add speech [prog id] [trigger phrase]
Syntax to add: add speechexact [prog id] [trigger phrase]
tell:
tellexact:
A 'tell' trigger allows a prog to be called when the player sends a tell to the mob. Tellexact requires the exact phrase to be entered whereas 'tell' will trigger if any part of the player's tell contains the trigger phrase.
There is a special case to 'tell' triggers - if the trigger phrase is set to 'tell', the prog will be triggered on any tell to the mob and what was actually sent will be available in lua as a string using the variable 'charg'. This is how the academy decides whether or not you answer correctly during the quiz sections.
Syntax to add: add tell [prog id] [trigger phrase]
Syntax to add: add tellexact [prog id] [trigger phrase]
transfer:
An 'transfer' trigger executes when a player is transfered into the room by another lua prog. Greet/grall progs are not triggered by transfer, this trigger type is used instead. Note that imm transfers, portals, etc do not run transfer triggers - only transfer from within another prog.
Syntax to add: add transfer [prog id] [percent]

Room Triggers

Room triggers are split into two main types: Room triggers that act as arbitrary commands on a room. For example, allowing a player to 'pick apple' in the Orchard or 'board' the train in lands of legend. The second type of trigger is actions performed by the room itself - perhaps a room damages chars on entry if they dont have enough resists to fire, or an "onrepop" trigger runs when the area repops, basically allowing you to create your own reset types. At the time of writing, only the first type of triggers are in place. These are listed below.

Room triggers/progs have some important differences from standard mobprogs. Firstly, each trigger type has an additional (optional) argument for 'actor'. The actor is the key of a mob that much be in the room for the prog to be able to run - this mob then becomes 'self' as if a mobprog had been called. Lands of Legend uses this - 'board' only works if the conductor is there. The academy progs that wait for you to type a command before continuing also use this - they will only run if the trainer is present.

Another important difference with room progs is that unless an actor is given (see above), there is no "self" when the prog runs. Many of the existing luaprog functions require/assume that 'self' is present and either will not run at all (echo - WHO is doing the echo in this case?) or require an extra argument (oload - requires char to put the object on if there is no self).

command:
The 'command' trigger is the main way to trigger progs from arbitrary room actions. A trigger of 'push rock' on the room will fire if the player types 'push rock'. A command trigger of only 'push' will trigger on 'push' by itself or 'push' with any other argument. If the command also happens to be a real mud command, it is not executed. This means that command progs which do nothing but return can be used to block a specific command in a room, or even change its function completely (as 'board' does in lands of legend - you board the train instead of seeing the list of MUD boards).
Syntax to add: add command [prog id] "trigger phrase" [optional - mobkey for actor]
after:
The 'after' trigger allows a mud command to be run, but then runs the program afterwards. The academy programs that require new users to type a command to try it rely on this type of prog. For example, Claire requires new players to type 'help kill' and 'score' in basic training - the output of these commands is displayed then the trigger calls a prog which causes Claire to move on to the next part of the lesson.
Syntax to add: add after [prog id] "trigger phrase" [optional - mobkey for actor]