Triggers
The main means of in-game scripting is to attach triggers to mobiles,
objects, and rooms. Triggers are scripts that execute when a pre-specified game
event occurs. For instance, someone speaking, entering or leaving a room,
dropping an object, and so forth. Like the things they attach to, triggers
exist as game content within a zone. They have reference keys, just like
all other game content. Effectively, they are behaviors that are part of the
game world.
NakedMud comes with 14 built-in trigger types, which will each be covered in
the next section. This section will explain how to bring up and use the trigger
editor.
tedit
The command for editing a trigger is tedit. If a key is specified, that
trigger's information is brought up in the online editing tool. If the key does
not exist, a new trigger is created for that key.
> tedit helloworld [helloworld@tutorial] 1) Name : An Unfinished Trigger 2) Trigger type: <NONE> 3) Script Code # trigger code goes here # make sure to comment it with pounds (#) Enter choice, ? [topic] for help, or Q to quit:Every trigger must be given a type. This is the game event that causes the trigger to run. Each type of trigger can only be attached to certain game contents. When a trigger type is listed, what it can be attached to will also display. Let's create a speech trigger as a first example:
Enter choice, ? [topic] for help, or Q to quit: 2 Type Usable By ----------------------------------- 0) speech mob, room 1) greet mob 2) enter mob, room 3) exit mob, room 4) move mob 5) drop obj, room 6) get obj, room 7) give obj, mob 8) receive mob 9) wear mob 10) remove obj, mob 11) reset room 12) combat mob 14) open obj, room Enter a trigger type: 0 [helloworld@tutorial] 1) Name : An Unfinished Trigger 2) Trigger type: speech 3) Script Code # trigger code goes here # make sure to comment it with pounds (#) Enter choice, ? [topic] for help, or Q to quit:Now let's set it up to be a room trigger; every time a person says hello world!, teleport them to a new room:
[helloworld@tutorial] 1) Name : Teleport the person to a new zone 2) Trigger type: speech 3) Script Code if arg.lower() == "hello world!": ch.room = "startroom@magic_forest" ch.send("You say the magic words, and suddenly find yourself in a new place.") ch.act("look") Enter choice, ? [topic] for help, or Q to quit:When this trigger is attached to a room, every time a person in it says the magic words they will be teleported to another room.