Difference between revisions of "Manual:Zone Manual/The Reset Section"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the current code (wiki review 2026-11-15))
 
Line 1: Line 1:
 
== The reset section ==
 
== The reset section ==
  
−
Once you have learned to build rooms, objects and NPCs, you will
+
Rooms exist as soon as the zone is loaded, but the NPCs and objects you have written are only templates: nothing of them is in the game until something loads it. The reset section does that. It is a list of commands that the server runs when the zone resets: it loads NPCs and objects into rooms, puts objects into containers and NPCs' inventories, dresses NPCs, makes NPCs follow each other, and closes, locks or hides doors that players have opened.
−
find one main missing thing, while you have created NPCs and objects
+
 
−
they don't exist in the game unless you load them. When developing the
+
The section starts with <code>%reset</code> and is usually the last one, just before <code>%end</code>. It must hold at least one command: an empty <code>%reset</code> is a syntax error, so leave the header out if you have nothing to reset.
−
VME we found that logging on and loading everything for the players to
+
 
−
interact with, became a very difficult thing to do when we got over 30
+
=== When the reset section runs ===
−
items.  After many seconds of thought we came up with the idea of a
+
 
−
reset section that would do all of this work for us.  In fact the reset
+
Two fields in the [[Manual:Zone Manual/Zone Source File/Zone information section|zone header]] decide when the commands run:
−
takes care of closing doors after players have opened them, loading NPCs
+
 
−
and their equipment, loading objects by themselves in rooms or even
+
;<code>lifespan</code>
−
loaded objects in objects.
+
:Minutes between resets (default 60). The server adds a random delay of up to three minutes so that not all zones reset at the same moment. With <code>lifespan 0</code> the zone is never reset, not even at boot.
 +
;<code>reset</code>
 +
:The reset mode, one of the constants from ''vme.h'':
 +
 
 +
{| class="wikitable"
 +
! Mode !! Value !! The reset section runs
 +
|-
 +
| <code>RESET_NOT</code> || 0 || once, when the game boots. This is the default.
 +
|-
 +
| <code>RESET_IFEMPTY</code> || 1 || at boot, then every <code>lifespan</code> minutes if no player is in the zone; while one is, it tries again every minute.
 +
|-
 +
| <code>RESET_ANYHOW</code> || 2 || at boot, then every <code>lifespan</code> minutes, players or not.
 +
|-
 +
| <code>RESET_NEVER</code> || 3 || never, not even at boot.
 +
|}
 +
 
 +
A zone that should refill itself while the game runs needs <code>RESET_IFEMPTY</code> or <code>RESET_ANYHOW</code>; with the default, NPCs that are killed stay dead until the next reboot. An administrator can also reset a zone by hand with the <code>reset</code> command (<code>reset dragonst</code>), and <code>wstat zone dragonst reset</code> lists a zone's reset commands as the server read them.
 +
 
 +
=== How the commands run ===
 +
 
 +
The commands run from top to bottom, every time the zone resets. They are not a script that runs once: the same <code>load</code> runs again at the next reset, and only its limits (<code>max</code>, <code>zonemax</code>, <code>local</code>, see [[Manual:Zone Manual/The Reset Section/Loading objects and NPCs|Loading objects and NPCs]]) stop it from loading a second copy.
 +
 
 +
Any command can be followed by a block in braces with more commands. The block runs only if its command succeeded, and the commands in it work on what that command loaded: a <code>load</code> in an NPC's block goes into the NPC's inventory, one in a container's block goes into the container. Blocks can be nested as deep as you like.
 +
 
 +
{| class="wikitable"
 +
! Command !! What it does !! Described in
 +
|-
 +
| <code>door</code> || sets the flags of one side of a door || below
 +
|-
 +
| <code>load</code> || loads an NPC or object into a room, or into the unit of the enclosing block || [[Manual:Zone Manual/The Reset Section/Loading objects and NPCs|Loading objects and NPCs]]
 +
|-
 +
| <code>equip</code> || loads an object and puts it on the NPC of the enclosing block || [[Manual:Zone Manual/The Reset Section/Loading objects and NPCs|Loading objects and NPCs]]
 +
|-
 +
| <code>follow</code> || loads an NPC next to the NPC of the enclosing block and makes it follow || [[Manual:Zone Manual/The Reset Section/Special reset functions|Special reset functions]]
 +
|-
 +
| <code>purge</code> || empties a room of everything but players || [[Manual:Zone Manual/The Reset Section/Special reset functions|Special reset functions]]
 +
|-
 +
| <code>remove</code> || removes every copy of a unit from a room || [[Manual:Zone Manual/The Reset Section/Special reset functions|Special reset functions]]
 +
|-
 +
| <code>random</code> || runs its block a given percentage of the time || [[Manual:Zone Manual/The Reset Section/Special reset functions|Special reset functions]]
 +
|-
 +
| <code>nop</code> || does nothing and always succeeds; only useful with a block || [[Manual:Zone Manual/The Reset Section/Special reset functions|Special reset functions]]
 +
|}
 +
 
 +
The order of the commands is up to you. A common one is doors first, then objects in rooms, then NPCs with their equipment.
 +
 
 +
vmc does not check the names in reset commands. A misspelt unit compiles, and the server logs it when it boots (<code>Slimed: Illegal ref.: ...</code>) and loads a blob of green slime in its place. After adding resets, read the server log and <code>wstat zone &lt;zone&gt; errors</code>.
  
−
Everything inside the reset section activates once at boot time and
 
−
then again when the reset time is up and the reset flag is true.  These
 
−
two fields were described in (Link to zoneinfo) and are included
 
−
in the zone header.  The reset section is denoted by the symbol '%reset' and can placed
 
−
anywhere but we try to keep it at the end of our zone files.  There is
 
−
no set order you must reset your doors, objects, and NPCs in but I like
 
−
to do doors first, special reset commands second, objects in rooms third, objects with objects in them
 
−
forth, NPCs fifth,
 
−
and finally NPCs.  You may find that you have a better way of sorting
 
−
them and again it is up to you.
 
 
=== Door resets ===
 
=== Door resets ===
  
−
To show how the door resets work we will revisit an old room
+
A door is two exits, one in each room, and each side has its own flags. The flags in the room definition are what the door starts with when the zone is loaded. After that only the reset section changes them back: a door that a player opened stays open until a <code>door</code> command closes it. Here are two rooms from the dragon station joined by a door:
−
example from (Link to rmdoorexits). The following two rooms are
+
 
−
linked with a door and at boot time they are reset to closed.  When the
+
<pre>
−
mud boots the door flags set on the room are the door flags that are
+
hallway
−
used. After boot up time the reset section is where the VME gets its
+
title "Module tunnel"
−
information about what to do with the door.
+
descr
−
<nowiki>
+
"The hallway is about 50 metres long and around 100 metres from side to
−
hallway
+
side and top to bottom."
−
title "Module tunnel"
+
movement SECT_INSIDE
−
descr "The hallway is about 50 meters long and around 100 meters from
+
ALWAYS_LIGHT
−
side to side and top to bottom...."
+
flags {UNIT_FL_NO_WEATHER, UNIT_FL_INDOORS}
 +
 
 +
east to office descr
 +
"You see what looks to be an office."
 +
keyword {"air lock door","air lock","door"}
 +
open {EX_OPEN_CLOSE, EX_CLOSED};
 +
end
 +
 
 +
office
 +
title "The station office"
 +
descr
 +
"Large paintings fill the walls of this part of the station."
 +
movement SECT_INSIDE
 +
ALWAYS_LIGHT
 +
flags {UNIT_FL_NO_WEATHER, UNIT_FL_INDOORS}
 +
 
 +
west to hallway descr
 +
"You see what looks to be a hallway."
 +
keyword {"air lock door","air lock","door"}
 +
open {EX_OPEN_CLOSE, EX_CLOSED};
 +
end
 +
</pre>
  
−
movement SECT_INSIDE
+
The door command is:
−
ALWAYS_LIGHT
 
−
flags {UNIT_FL_NO_WEATHER, UNIT_FL_INDOORS}
 
  
−
west to chamber descr
+
<pre>
−
"The hallway opens up into a chamber.";
+
door <room> <direction> <flags>
 +
</pre>
  
−
east to office descr
+
;room
−
"You see what looks to be an office."
+
:The symbolic name of the room the exit is in. A room in another zone takes its zone name: <code>door myroom ...</code> for a room in this zone, <code>door out_room@frogwart ...</code> for one in the zone frogwart.
−
keyword {"air lock door","air lock","door"}
+
;direction
−
open {EX_OPEN_CLOSE, EX_CLOSED};
+
:The exit, as a number. Use the direction macros from ''vme.h'' (included by ''macros.h''):
 +
{| class="wikitable"
 +
! Macro !! Value !! Macro !! Value
 +
|-
 +
| <code>NORTH</code> || 0 || <code>DOWN</code> || 5
 +
|-
 +
| <code>EAST</code> || 1 || <code>NORTHEAST</code> || 6
 +
|-
 +
| <code>SOUTH</code> || 2 || <code>NORTHWEST</code> || 7
 +
|-
 +
| <code>WEST</code> || 3 || <code>SOUTHEAST</code> || 8
 +
|-
 +
| <code>UP</code> || 4 || <code>SOUTHWEST</code> || 9
 +
|}
 +
:If the room has no exit in that direction the server logs <code>Zone Reset Error: No ... direction from room ... in door</code> and does nothing. vmc does not check the number; only 0 to 9 are exits.
 +
;flags
 +
:The new flags of that exit, one flag or several in braces. They replace all the exit's flags, so list every flag the exit should have, also the ones that are not about the door's state (<code>EX_CLIMB</code>, <code>EX_PICKPROOF</code>, ...). The flags are those of the <code>open</code> field of an exit:
  
−
end
+
{| class="wikitable"
 +
! Flag !! Meaning
 +
|-
 +
| <code>EX_OPEN_CLOSE</code> || The exit is a door, gate or the like that can be opened and closed.
 +
|-
 +
| <code>EX_CLOSED</code> || The door is closed.
 +
|-
 +
| <code>EX_LOCKED</code> || The door is locked. Without a <code>key</code> on the exit it can only be opened with the pick skill, the unlock spell or from DIL.
 +
|-
 +
| <code>EX_PICKPROOF</code> || The lock can't be picked. (The unlock spell still opens it.)
 +
|-
 +
| <code>EX_HIDDEN</code> || The exit can't be seen until someone finds it with <code>search</code>.
 +
|-
 +
| <code>EX_CLIMB</code> || The exit must be climbed.
 +
|-
 +
| <code>EX_FALL_THIS_WAY</code> || Things that fall in the room fall this way.
 +
|}
  
−
office
+
To close the door between the two rooms at every reset, reset both sides:
−
title "The station office"
 
−
descr
 
−
"Large paintings fill the walls of this part of the station...."
 
  
−
movement SECT_INSIDE
+
<pre>
−
ALWAYS_LIGHT
+
door hallway EAST {EX_OPEN_CLOSE, EX_CLOSED}
−
flags {UNIT_FL_NO_WEATHER, UNIT_FL_INDOORS}
+
door office WEST {EX_OPEN_CLOSE, EX_CLOSED}
 +
</pre>
  
−
west to hallway descr
+
If you reset only one side, the other side stays open after a player opened it, and the door is closed from one room and open from the other.
−
"You see what looks to be a hallway."
 
−
keyword {"air lock door","air lock","door"}
 
−
open {EX_OPEN_CLOSE, EX_CLOSED};
 
−
end</nowiki>
 
−
Now that we have two rooms lets define the reset command and how
 
−
it works.  All reset commands have a keyword and then a set of
 
−
arguments.  The door reset command is simply 'door' followed by a set of
 
−
arguments that tell the VME where the door is, which door in that
 
−
location, and what you want to do with the door.  The command looks like
 
−
this.
 
−
<nowiki>
 
−
door &lt;room symbol&gt; &lt;Direction number&gt; {&lt;door flags&gt;}</nowiki>
 
−
==== Door argument explanation ====
 
−
;room symbolic
 
−
: As the name indicates this is the room that the door is located in.  If you are resetting a door not in the zone the reset command is in you will need to use a full symbolic name with the zone extension.  The following would be two valid examples.
 
−
<nowiki>
 
−
//room symbolic in  this zone
 
−
door myroom ...
 
  
−
//room symbolic in another zone
+
The reset can also give the door a different state from the one in the room definition. This locks the door at every reset:
−
door out_room@frogwart ...</nowiki>
 
−
;direction number
 
−
: The direction number can be one of the pre-defined direction numbers in the file ''vme.h''.  shown here so you don't have to go flipping file to file.
 
−
<nowiki>
 
−
#define NORTH 0
 
−
#define EAST  1
 
−
#define SOUTH 2
 
−
#define WEST  3
 
−
#define UP    4
 
−
#define DOWN  5
 
−
#define NORTHEAST 6
 
−
#define NORTHWEST 7
 
−
#define SOUTHEAST 8
 
−
#define SOUTHWEST 9</nowiki>
 
−
;door flags
 
−
: These flags, surrounded by '{}', describe the state of the door after the reset. The following is the list of possible door flags.
 
  
−
;EX_OPEN_CLOSE
+
<pre>
−
: Set this if you can open and close this exit, be it a door, gate or otherwise.
+
door hallway EAST {EX_OPEN_CLOSE, EX_CLOSED, EX_LOCKED}
−
;EX_CLOSED
+
door office WEST {EX_OPEN_CLOSE, EX_CLOSED, EX_LOCKED}
−
: Set this if you want the exit to be closed at reset time.
+
</pre>
−
;EX_LOCKED
 
−
: Set this if you want the exit to be locked at reset time.
 
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">
 
−
An interesting aspect is that if you do not specify a key, you can
 
−
    only unlock this door with the 'pick' skill, 'unlock' spell or from
 
−
    DIL with UnSet();
 
−
</blockquote>
 
−
;EX_PICK_PROOF
 
−
: Using this flag renders the 'pick' skill and 'unlock' spell un useable on the lock of this exit.
 
−
;EX_HIDDEN
 
−
: If this bit is set, the exit is hidden until the mobile has successfully searched for it, using the 'search'-command.
 
  
−
Now that we have all the information we need we can close the door
+
The two sides needn't have the same flags. The secret door in the dragon station is hidden only on the office side (see [[Manual:Zone Manual/The Reset Section/Reset walk through|Reset walk through]]).
−
after the reset time expires.  For our two rooms the door reset would
 
−
look like this.
 
−
<nowiki>
 
−
door hallway EAST {EX_OPEN_CLOSE, EX_CLOSED}
 
−
door office WEST {EX_OPEN_CLOSE, EX_CLOSED}</nowiki>
 
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">As you can see from the example it is very important to close both sides of the door. If you do not close both sides you will get very weird and undefined errors when players are trying to open and close them</blockquote>
 
  
−
Another thing that you can do with the door reset command is
+
A <code>door</code> command never counts as a success, so a block after it never runs; give it none.
−
change the doors status.  In our previous example we reset the door to
 
−
its status that it has when it first is loaded into the game.  If
 
−
however we wanted to change the door to a locked door we could do that
 
−
by adding the locked flag like this:
 
−
<nowiki>
 
−
door hallway EAST {EX_OPEN_CLOSE, EX_CLOSED,EX_LOCKED}
 
−
door office WEST {EX_OPEN_CLOSE, EX_CLOSED,EX_LOCKED}</nowiki>
 
  
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/The_Objects_Section/Suggested_object_exercises|Previous: Suggested object exercises]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/The_Objects_Section/Suggested_object_exercises|Previous: Suggested object exercises]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/The_Reset_Section/Loading_objects_and_NPCs|Next: Loading objects and NPCs]]</div>
 
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/The_Reset_Section/Loading_objects_and_NPCs|Next: Loading objects and NPCs]]</div>

Latest revision as of 06:23, 15 November 2026

The reset section

Rooms exist as soon as the zone is loaded, but the NPCs and objects you have written are only templates: nothing of them is in the game until something loads it. The reset section does that. It is a list of commands that the server runs when the zone resets: it loads NPCs and objects into rooms, puts objects into containers and NPCs' inventories, dresses NPCs, makes NPCs follow each other, and closes, locks or hides doors that players have opened.

The section starts with %reset and is usually the last one, just before %end. It must hold at least one command: an empty %reset is a syntax error, so leave the header out if you have nothing to reset.

When the reset section runs

Two fields in the zone header decide when the commands run:

lifespan
Minutes between resets (default 60). The server adds a random delay of up to three minutes so that not all zones reset at the same moment. With lifespan 0 the zone is never reset, not even at boot.
reset
The reset mode, one of the constants from vme.h:
Mode Value The reset section runs
RESET_NOT 0 once, when the game boots. This is the default.
RESET_IFEMPTY 1 at boot, then every lifespan minutes if no player is in the zone; while one is, it tries again every minute.
RESET_ANYHOW 2 at boot, then every lifespan minutes, players or not.
RESET_NEVER 3 never, not even at boot.

A zone that should refill itself while the game runs needs RESET_IFEMPTY or RESET_ANYHOW; with the default, NPCs that are killed stay dead until the next reboot. An administrator can also reset a zone by hand with the reset command (reset dragonst), and wstat zone dragonst reset lists a zone's reset commands as the server read them.

How the commands run

The commands run from top to bottom, every time the zone resets. They are not a script that runs once: the same load runs again at the next reset, and only its limits (max, zonemax, local, see Loading objects and NPCs) stop it from loading a second copy.

Any command can be followed by a block in braces with more commands. The block runs only if its command succeeded, and the commands in it work on what that command loaded: a load in an NPC's block goes into the NPC's inventory, one in a container's block goes into the container. Blocks can be nested as deep as you like.

Command What it does Described in
door sets the flags of one side of a door below
load loads an NPC or object into a room, or into the unit of the enclosing block Loading objects and NPCs
equip loads an object and puts it on the NPC of the enclosing block Loading objects and NPCs
follow loads an NPC next to the NPC of the enclosing block and makes it follow Special reset functions
purge empties a room of everything but players Special reset functions
remove removes every copy of a unit from a room Special reset functions
random runs its block a given percentage of the time Special reset functions
nop does nothing and always succeeds; only useful with a block Special reset functions

The order of the commands is up to you. A common one is doors first, then objects in rooms, then NPCs with their equipment.

vmc does not check the names in reset commands. A misspelt unit compiles, and the server logs it when it boots (Slimed: Illegal ref.: ...) and loads a blob of green slime in its place. After adding resets, read the server log and wstat zone <zone> errors.

Door resets

A door is two exits, one in each room, and each side has its own flags. The flags in the room definition are what the door starts with when the zone is loaded. After that only the reset section changes them back: a door that a player opened stays open until a door command closes it. Here are two rooms from the dragon station joined by a door:

hallway
title "Module tunnel"
descr
"The hallway is about 50 metres long and around 100 metres from side to
side and top to bottom."
movement SECT_INSIDE
ALWAYS_LIGHT
flags {UNIT_FL_NO_WEATHER, UNIT_FL_INDOORS}

east to office descr
"You see what looks to be an office."
keyword {"air lock door","air lock","door"}
open {EX_OPEN_CLOSE, EX_CLOSED};
end

office
title "The station office"
descr
"Large paintings fill the walls of this part of the station."
movement SECT_INSIDE
ALWAYS_LIGHT
flags {UNIT_FL_NO_WEATHER, UNIT_FL_INDOORS}

west to hallway descr
"You see what looks to be a hallway."
keyword {"air lock door","air lock","door"}
open {EX_OPEN_CLOSE, EX_CLOSED};
end

The door command is:

door <room> <direction> <flags>
room
The symbolic name of the room the exit is in. A room in another zone takes its zone name: door myroom ... for a room in this zone, door out_room@frogwart ... for one in the zone frogwart.
direction
The exit, as a number. Use the direction macros from vme.h (included by macros.h):
Macro Value Macro Value
NORTH 0 DOWN 5
EAST 1 NORTHEAST 6
SOUTH 2 NORTHWEST 7
WEST 3 SOUTHEAST 8
UP 4 SOUTHWEST 9
If the room has no exit in that direction the server logs Zone Reset Error: No ... direction from room ... in door and does nothing. vmc does not check the number; only 0 to 9 are exits.
flags
The new flags of that exit, one flag or several in braces. They replace all the exit's flags, so list every flag the exit should have, also the ones that are not about the door's state (EX_CLIMB, EX_PICKPROOF, ...). The flags are those of the open field of an exit:
Flag Meaning
EX_OPEN_CLOSE The exit is a door, gate or the like that can be opened and closed.
EX_CLOSED The door is closed.
EX_LOCKED The door is locked. Without a key on the exit it can only be opened with the pick skill, the unlock spell or from DIL.
EX_PICKPROOF The lock can't be picked. (The unlock spell still opens it.)
EX_HIDDEN The exit can't be seen until someone finds it with search.
EX_CLIMB The exit must be climbed.
EX_FALL_THIS_WAY Things that fall in the room fall this way.

To close the door between the two rooms at every reset, reset both sides:

door hallway EAST {EX_OPEN_CLOSE, EX_CLOSED}
door office WEST {EX_OPEN_CLOSE, EX_CLOSED}

If you reset only one side, the other side stays open after a player opened it, and the door is closed from one room and open from the other.

The reset can also give the door a different state from the one in the room definition. This locks the door at every reset:

door hallway EAST {EX_OPEN_CLOSE, EX_CLOSED, EX_LOCKED}
door office WEST {EX_OPEN_CLOSE, EX_CLOSED, EX_LOCKED}

The two sides needn't have the same flags. The secret door in the dragon station is hidden only on the office side (see Reset walk through).

A door command never counts as a success, so a block after it never runs; give it none.

Previous: Suggested object exercises
Next: Loading objects and NPCs