Difference between revisions of "Manual:Zone Manual/The NPC Section/DIL functions for NPCs"

From DikuMUD Wiki
Jump to navigation Jump to search
(checked against the current code (wiki review 2026-11-15))
 
Line 1: Line 1:
 
=== DIL functions for NPCs ===
 
=== DIL functions for NPCs ===
  
−
The DIL language is the language a builder can use to make his own
+
DIL is the language for making rooms, NPCs and objects do things. This manual doesn't teach you to write DIL; the [[Manual:DIL Manual|DIL manual]] does. But DikuMUD3 comes with many ready-made DIL functions (templates) that you can put on an NPC without writing any DIL yourself. This page describes the ones for NPCs.
−
special functions on rooms, NPCs, objects, PCs, and much more. This
 
−
manual is for basic zone writing and therefore will not go into how to
 
−
write your own DIL functions. The VME however is released with many
 
−
functions for you as an Administrator and your builders to use to make
 
−
special rooms, NPCs, and objects. The following is a list of all NPC
 
−
functions released with the VME 2.0 server.
 
  
 +
You put a template on an NPC with [[Manual:DIL Manual/dilcopy()|dilcopy]] in its definition:
 +
<pre>
 +
dilcopy aggressive@function(0, -1, 0, 0, 3, PULSE_SEC*5, 0, "ANY", {"$1n attacks $3n!", "$1n attacks you!"});
 +
</pre>
 +
* The name is <code>template@zone</code>. Most of these live in <code>vme/zone/function.zon</code>; a few in other zones, such as <code>guilds.zon</code> and <code>midgaard.zon</code>.
 +
* The arguments are numbers ([[Manual:DIL Manual/integer|integer]]), strings in double quotes ([[Manual:DIL Manual/string|string]]), string lists in braces such as <code>{"a", "b"}</code> ([[Manual:DIL Manual/stringlist|stringlist]]), number lists such as <code>{4, 23}</code> ([[Manual:DIL Manual/intlist|intlist]]), and [[Manual:DIL Manual/null|null]] for an empty list. Macros from the headers work in them, for example <code>PULSE_SEC*10</code> or <code>RACE_DWARF</code>.
 +
* The line ends with <code>;</code>.
 +
* '''vmc checks neither the name nor the arguments.''' A misspelt template or a wrong argument compiles fine, and shows up only at boot or when the NPC acts, as an error in <code>vme/bin/vme.log</code>. Before you use a template, read its <code>dilbegin</code> line, and the comment above it, in the zone file on [https://github.com/Seifert69/DikuMUD3/tree/master/vme/zone GitHub].
 +
* Times are often in ''ticks'': 4 ticks are one second. <code>PULSE_SEC</code> (4) and <code>WAIT_SEC</code> (4) are macros for it.
 +
* In messages, <code>$1n</code>, <code>$2n</code> and <code>$3n</code> are replaced by names of the units involved; each function below says which is which. See [[Manual:DIL Manual/act()|act()]].
  
−
;Mercenary
+
You can give an NPC as many of these as you like; the janitor in [[Manual:Zone Manual/The NPC Section/A more complex set of NPCs|A more complex set of NPCs]] has two. In the game, <code>wstat &lt;symbol&gt;@&lt;zone&gt; func</code> lists the DIL programs an NPC runs.
−
: This function allows you to make an NPC hireable by players in the game.  You simply dilcopy this unto a mob and the player can then type 'contract &lt;character name&gt;
+
 
−
and the mob will hunt that char for a fee. This function takes no special
+
Many NPC templates in <code>macros.h</code> already add some of these functions; for example the black dragon templates add <code>aggressive</code> and <code>combat_mag</code>. See [[Manual:Zone Manual/The NPC Section/NPC macros|NPC macros]].
−
arguments.  the following is the function definition found in
+
 
−
''function.zon'':
+
==== Fighting ====
−
<nowiki>
+
 
−
dilbegin mercenary_hire();</nowiki>
+
===== aggressive =====
−
To use it you simply dilcopy it to your NPC as follows:
+
Makes the NPC attack players who come into its room, or do something there, under the conditions you give. It attacks only players it can see, never gods, and only while it is awake and not already fighting.
−
<nowiki>
+
<pre>
−
dilcopy mercenary_hire@function();</nowiki>
+
dilbegin aggressive (sx : integer, rce : integer, opp : integer,
−
;Obey
+
                    levl : integer, sanc : integer, tme : integer,
−
: This function when dilcopied on the NPC will make it obey there master. And example mobile of this is the familiar. Upon completing a small quest a Mage receives a familiar that will obey that player and that player only. The player can simply type '''Tell &lt;familiar name&gt; cast heal
+
                    tar : integer, align : string, attack : stringlist);
−
&lt;player name&gt;''' and it will carry out the command.  This function takes
+
</pre>
−
no arguments.  The following is the definition found in
 
−
''function.zon'':
 
−
<nowiki>
 
−
dilbegin obey();</nowiki>
 
−
To use this function simply dilcopy it to the NPC you want to be a
 
−
mercenary like so:
 
−
<nowiki>
 
−
dilcopy obey@function();</nowiki>
 
−
;Evaluate
 
−
: This function when placed on an NPC allows it to evaluate items for a fee.  The function definition looks as follows:
 
−
<nowiki>
 
−
dilbegin evaluate (amt:integer);</nowiki>
 
−
The function has one argument 'amt' that lets you set the cost of
 
−
the evaluation of items.  If you wanted to set the value to four gold it
 
−
would work just like when setting the money field and look as
 
−
follows:
 
−
<nowiki>
 
−
dilcopy evaluate@function(4*GOLD_PIECE);</nowiki>
 
−
;Guard Direction
 
−
: This is an enhanced version of the Guard Way Function. It will allow both certain players to enter as well as certain mobs. An optional stop DIL can be supplied if you wish to do something special. It takes two arguments, the activator and the direction.  The following is the function definition:
 
−
<nowiki>
 
−
dilbegin guard_dir(direction : string, excludepc : stringlist,
 
−
                  excludenpc : stringlist, stopdil : string);</nowiki>
 
−
This function is dilcopied onto the mob in the room that the mob is initially
 
−
loaded. Thus is the mob is summoned or commanded away it will not block the
 
−
directions until it is back to where it was first created. This DIL takes four
 
−
arguments. The first is the direction to block. The second arguments is for those
 
−
PC's you wish to allow to pass in that direction without being stopped.  The next
 
−
for the NPCs you wish to allow to pass. The last is the 'act you wish the blocking
 
−
mob to display to the PC's that are blocked from proceeding in the selected direction.
 
−
The third and forth arguments may be 'null', this will pass the defaults to the
 
−
dilcopy.  The third argument is a stringlist that tells which players
 
−
or NPCs are excluded from the guard.  The forth is a DIL you can pass in
 
−
to do something special to people who are stopped. We will not show how
 
−
to use the forth argument because it takes more DIL knowledge than this
 
−
manual covers.  The following would be a valid dilcopy for this
 
−
function:
 
−
<nowiki>
 
−
dilcopy guard_dir@function("south", {"papi",
 
−
{"rejji"}, null, null);</nowiki>
 
−
;Combat magic
 
−
: This function when placed on a mobile allows it to use any of the combat spells.  The function definition is as follows: It also allows the NPC to cast heal during combat on itself.
 
−
<nowiki>
 
−
dilbegin combat_mag(atk_spl : string, def_spl : string,
 
−
                    def_pct:integer, spd: integer);</nowiki>
 
 
{| class="wikitable"
 
{| class="wikitable"
−
|+Combat magic arguments
+
! Argument !! Type !! Meaning
 +
|-
 +
| sx || integer || The victim's sex (not the <code>SEX_</code> values): 0 any, 1 the opposite of the NPC's own (not for a neutral NPC), 2 male, 3 female, 4 neutral.
 
|-
 
|-
−
!argument
+
| rce || integer || A player race, <code>RACE_HUMAN</code> (0) to <code>RACE_DARK_ELF</code> (10), or -1 for any race.
−
!Type
 
−
!description
 
 
|-
 
|-
−
|atk_spl
+
| opp || integer || What to do with <code>rce</code>: 0 ignore it, 1 attack only that race, 2 attack every race but that one.
−
|string
 
−
|Attack spell ie "fireball" or "" for none
 
 
|-
 
|-
−
|def_spl
+
| levl || integer || 0: any level. 30: players of level 30 and above. -30: players of level 30 and below. Allowed: -49 to 50.
−
|string
 
−
|Defense Spell ie "heal" or "" for none
 
 
|-
 
|-
−
|def_pct
+
| sanc || integer || Whether the NPC spares protected players: 0 no, 1 those with ''sanctuary'', 2 those with ''soothe'', 3 both.
−
|integer
 
−
|At what % of hitpoints defense spell will be cast
 
 
|-
 
|-
−
|spd
+
| tme || integer || How long it waits before attacking, in ticks, 0 to 400 (100 seconds). The real wait is random, between about half and one and a half times this.
−
|integer
+
|-
−
|speed at which mob will uses its attack magic, 1 for all
+
| tar || integer || Which of the players who qualify it picks: -2 the last to enter the room, -1 the weakest, 0 a random one, 1 the strongest, 2 the first to enter.
−
at once (every round) to 5 for every 5 rounds. I suggest 2.
+
|-
 +
| align || string || The victim's alignment: <code>"ANY"</code>, <code>"GOOD"</code>, <code>"EVIL"</code>, <code>"NEUTRAL"</code>, <code>"OPPOSITE"</code> (the opposite of the NPC's; not for a neutral NPC), <code>"SALIGN"</code> (the same as the NPC's) or <code>"DALIGN"</code> (any other than the NPC's).
 +
|-
 +
| attack || stringlist || The attack messages: <code>{"to the others", "to the victim"}</code>. <code>$1n</code> is the NPC, <code>$3n</code> the victim. With one string, everyone in the room sees it (don't use <code>$3n</code> then); with <code>{}</code> or <code>{""}</code> there is no message.
 
|}
 
|}
−
Defense spells take priority when the hit points fall below the % specified,
+
If an argument is out of range the function logs "AGGRO ERROR" in <code>vme.log</code> and stops.
−
after (if) the hits have been restored above that number attack magic will
+
 
−
resume.  If def_spl is used, function automatically makes sure that it retains
+
A level 40 goblin who hates evil female dwarves of level 20 and above, spares players with sanctuary (but not soothe), and waits about 10 seconds before attacking:
−
enough mana for at least one healing, ie it will attack 4 times if it don't
+
<pre>
−
need a healing.  The following would be an example of what you would put
+
dilcopy aggressive@function(3, RACE_DWARF, 1, 20, 1, PULSE_SEC*10, 0, "EVIL",
−
on your NPC:
+
                            {"$1n savagely attacks $3n with his big axe!",
−
<nowiki>
+
                            "$1n attacks you!"});
−
dilcopy combat_mag@function ("harm", "heal", 25, 2);</nowiki>
+
</pre>
−
;Fido
+
A monster that attacks anyone, after about 20 seconds, with one message for all:
−
: This function turns the NPC into a corpse eating mobile. The following is the functions definition:
+
<pre>
−
<nowiki>
+
dilcopy aggressive@function(0, -1, 0, 0, 3, PULSE_SEC*20, 0, "ANY",
−
dilbegin fido(txt1:string,txt2:string);</nowiki>
+
                            {"Big monster attacks!"});
 +
</pre>
 +
 
 +
===== combat_mag =====
 +
Makes the NPC cast spells while it fights: an attack spell, and a defence spell (such as a heal on itself) when its hit points run low.
 +
<pre>
 +
dilbegin fnpri(FN_PRI_COMBAT) combat_mag(atk_spl : string, def_spl : string, def_pct : integer,
 +
                    spd: integer);
 +
</pre>
 
{| class="wikitable"
 
{| class="wikitable"
−
|+Fido arguments
+
! Argument !! Type !! Meaning
 
|-
 
|-
−
!Argument
+
| atk_spl || string || The attack spell, as a player types it after <code>cast</code>, for example <code>"fireball"</code>, or <code>""</code> for none.
−
!Type
 
−
!description
 
 
|-
 
|-
−
|txt1
+
| def_spl || string || The defence spell, for example <code>"heal"</code>, or <code>""</code> for none.
−
|string
 
−
|The text shown when mob finds and eats corpses, default:
 
−
                        'XXX savagely devours a corpse.'
 
−
                  will be shown if txt1 is set to "".
 
−
                  If txt1 is set to "stop", the mob will NOT devour corpses
 
−
                  (convenient if you want your dogs to only eat food leftovers
 
−
                  but not corpses).
 
 
|-
 
|-
−
|txt2
+
| def_pct || integer || When the NPC's hit points are at or below this percentage of its maximum, it casts the defence spell.
−
|string
+
|-
−
|The text shown when mob finds and eats ITEM_FOOD, default:
+
| spd || integer || How often it casts the attack spell: 1 every combat round, 2 every second round, and so on. 2 is a good choice.
−
                        'XXX hungrily devours YYY.'
 
−
                  will be shown if txt2 is set to "".
 
−
                  If txt2 is set to "stop", the mob will NOT devour
 
−
                  ITEM_FOOD (convenient if you want to make a corpse-eating
 
−
                  ghoul, who'd choke on normal food, etc).
 
 
|}
 
|}
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">In both cases $1n is the mob itself, $2n is the title of the item devoured.</blockquote>
+
The defence spell comes first whenever the hit points are low. With a defence spell, the NPC casts its attack spell only while it has 40 mana or more, so that some is left for the defence; without one, 16 or more. The spell names are in <code>vme/etc/spells.def</code>.
 +
<pre>
 +
dilcopy combat_mag@function("harm", "heal", 25, 2);
 +
</pre>
  
−
An example of the 'fido' function on an NPC would look as
+
===== comb_poison and comb_acid =====
−
follows:
+
In a fight, about half of the NPC's hits also poison the victim (<code>comb_poison</code>) or burn them with acid (<code>comb_acid</code>). The two messages go to the victim and to the others in the room; <code>$1n</code> is the NPC, <code>$3n</code> the victim.
−
<nowiki>
+
<pre>
−
dilcopy fido@function("$1n slowly devours $2n, crunching the bones.",
+
dilbegin aware comb_poison(toact : string, restact : string);
−
                      "$1n grabs $2n and hungrily munches it.");</nowiki>
+
dilbegin aware comb_acid(toact : string, restact : string);
−
;Wander zone
+
</pre>
−
: This function allows a mob to wander around more than one zone, but not all zones.
+
<pre>
−
You specify what zones the mob can wander. Has optional intelligence which allows
+
dilcopy comb_poison@function("You feel very ill as $1n bites you!",
−
the opening and closing of doors. The following is the function
+
                            "$1n sinks $1s fangs deep into $3n!");
−
definition:
+
</pre>
−
<nowiki>
+
 
−
dilbegin wander_zones(zones : string, spd : integer, doors : integer,
+
===== teamwork =====
−
                      lckd_doors : integer);</nowiki>
+
The NPC joins the fight when one of the NPCs it protects is attacked, if they are in the same room.
 +
<pre>
 +
dilbegin aware fnpri(FN_PRI_RESCUE) teamwork(lst: string);
 +
</pre>
 +
<code>lst</code> lists the names of the NPCs to help, separated by <code>/</code>. A name matches one of the names in the other NPC's <code>names</code>.
 +
<pre>
 +
dilcopy teamwork@function("guard/captain");
 +
</pre>
 +
Note: at present the function skips NPCs of its own zone, so it helps only NPCs from other zones.
 +
 
 +
===== rescue =====
 +
The NPC rescues one of the NPCs it protects when that NPC is fighting in the same room and is down to half its hit points or less. Both must come from the same zone. It uses the ''rescue'' skill, so it can fail.
 +
<pre>
 +
dilbegin aware fnpri(FN_PRI_RESCUE) rescue(lst: string);
 +
</pre>
 +
<code>lst</code> is as for <code>teamwork</code>. NPCs often have both:
 +
<pre>
 +
dilcopy teamwork@function("guard/captain");
 +
dilcopy rescue@function("guard/captain");
 +
</pre>
 +
 
 +
==== Moving around ====
 +
 
 +
===== wander_zones =====
 +
The NPC walks through random exits, but only into rooms of the zones you list, and never into a room with <code>UNIT_FL_NO_MOB</code>. It stands up if it is sitting or resting, and does nothing while asleep. If it finds itself outside its zones, it waits five minutes and tries again.
 +
<pre>
 +
dilbegin wander_zones(zones : string, spd : integer, doors : integer, lckd_doors : integer);
 +
</pre>
 
{| class="wikitable"
 
{| class="wikitable"
−
|+Zone wander arguments
+
! Argument !! Type !! Meaning
 
|-
 
|-
−
!argument
+
| zones || string || Zone names separated by spaces. <code>@loadzone</code> in the list stands for the zone the NPC is in when it starts.
−
!Type
 
−
!description
 
 
|-
 
|-
−
|zones
+
| spd || integer || Seconds between steps; less than 5 counts as 5.
−
|string
 
−
|A string of zone names separated by spaces.
 
 
|-
 
|-
−
|spd
+
| doors || integer || 1: it opens closed doors to go through, and closes them behind it. 0: it doesn't.
−
|integer
 
−
|The speed (in seconds) at which the mob wanders.
 
−
                              Minimum = 5 secs (for process time).
 
 
|-
 
|-
−
|doors
+
| lckd_doors || integer || 1: it also goes through locked doors, without a key, and locks them again behind it. 0: it doesn't.
−
|integer
 
−
|Can open/close doors (0 = false, 1 = true)
 
−
|-
 
−
|lckd_doors
 
−
|integer
 
−
|Can open/closed locked doors (0=false, 1=true)
 
 
|}
 
|}
−
The options are not too hard so we will show how to use it and
+
<pre>
−
leave it at that
+
dilcopy wander_zones@function("haon_dor @loadzone", 30, 1, 0);
−
<nowiki>
+
</pre>
−
dilcopy wander_zones@function ("halfzon haon_dor", 5, 1);</nowiki>
+
An NPC with an extra named <code>$block wander</code> stops wandering.
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">@loadzone option which is used by inputting @loadzone somewhere in the zones string will replace it by the zone the mob is loaded in like this:
+
 
−
<nowiki>
+
===== global_wander =====
−
dilcopy wander_zones@function ("halfzon haon_dor @loadzone", 5, 1);</nowiki>
+
Like <code>wander_zones</code>, but the NPC may wander into any zone.
−
</blockquote>
+
<pre>
−
;Global wander
+
dilbegin global_wander(spd : integer, doors : integer, lckd_doors : integer);
−
: This is similar to wander_zones because it's just a modified version of it,
+
</pre>
−
which requires no zones argument since it moves in all zones. The
+
The arguments are those of <code>wander_zones</code> without <code>zones</code>; a speed below 2 counts as 5 seconds.
−
following is the function definition:
+
<pre>
−
<nowiki>
+
dilcopy global_wander@function(60, 1, 0);
−
dilbegin global_wander(spd : integer, doors : integer,
+
</pre>
−
                      lckd_doors :integer);</nowiki>
+
 
 +
==== Guards ====
 +
 
 +
These guards block only in the room where the NPC was when the function started, normally the room it was loaded into. Moved away, it doesn't block until it is back.
 +
 
 +
===== guard_dir =====
 +
The NPC stops characters from leaving in one direction, except those you name.
 +
<pre>
 +
dilbegin fnpri(FN_PRI_MISSION) guard_dir(direction : string,
 +
                  excludepc : stringlist,
 +
                  excludenpc : stringlist,
 +
                  stopdil : string);
 +
</pre>
 
{| class="wikitable"
 
{| class="wikitable"
−
|+Global wander arguments
+
! Argument !! Type !! Meaning
−
! Argument
 
−
! Type
 
−
! Description
 
 
|-
 
|-
−
|spd
+
| direction || string || The direction to block: <code>"north"</code>, <code>"south"</code>... <code>"up"</code>, <code>"down"</code>, <code>"northeast"</code>...
−
|integer
 
−
|The speed (in seconds) at which the mob wanders. Minimum = 5 seconds (for process time).
 
 
|-
 
|-
−
|doors
+
| excludepc || stringlist || The players allowed through, by name, or <code>null</code>.
−
|integer
 
−
|Can open/close doors (0 = false, 1 = true)
 
 
|-
 
|-
−
|lckd_doors
+
| excludenpc || stringlist || The NPCs allowed through, by name, or <code>null</code>.
−
|integer
+
|-
−
|Can open/closed locked doors (0=false, 1=true)
+
| stopdil || string || <code>""</code> for the normal messages ("&lt;guard&gt; stops you from going south!"). Otherwise the name of a DIL procedure that takes the blocked character and the direction, <code>(u : unitptr, dir : string)</code>, and is called instead; this needs DIL of your own.
 
|}
 
|}
 +
<pre>
 +
dilcopy guard_dir@function("south", {"papi", "whistler"}, {"guard", "captain"}, "");
 +
dilcopy guard_dir@function("east", {"rejji"}, null, "");
 +
</pre>
 +
 +
===== guard_door =====
 +
The NPC stops everyone from opening, closing, locking, unlocking or picking the door in one direction, or casting a spell at it.
 +
<pre>
 +
dilbegin fnpri(FN_PRI_MISSION) guard_door(dir:integer,as:string,ao:string);
 +
</pre>
 +
<code>dir</code> is a direction constant: <code>NORTH</code>, <code>EAST</code>, <code>SOUTH</code>, <code>WEST</code>, <code>UP</code>, <code>DOWN</code>... <code>as</code> is the message to the character who tried, <code>ao</code> the message to the others; <code>$1n</code> is the guard, <code>$3n</code> the character.
 +
<pre>
 +
dilcopy guard_door@function(WEST, "$1n stops you.",
 +
                            "$1n prevents $3n from opening the grating.");
 +
</pre>
  
−
The options are not to hard so we will show how to use it and
+
===== guard_unit =====
−
leave it at that
+
The same for an object in the room, such as a chest or a safe: nobody may open, close, lock, unlock or pick it, or cast at it. The first argument is the object's full symbolic name, <code>symbol@zone</code>.
−
<nowiki>
+
<pre>
−
dilcopy global_wander@function (60, 1, 1);</nowiki>
+
dilbegin fnpri(FN_PRI_MISSION) guard_unit(us:string,as:string,ao:string);
−
;Team work
+
</pre>
−
: This function when placed on a mob, located in the same room as another mob,
+
<pre>
−
will allow the mobile to assist the other in combat. The following is
+
dilcopy guard_unit@function("safe@midgaard", "$1n stops you.",
−
the function definition:
+
                            "$1n prevents $3n from opening the safe.");
−
<nowiki>
+
</pre>
−
dilbegin aware teamwork(lst: string);</nowiki>
 
−
This function takes one argument which is a string of the mobiles it is
 
−
to protect. So if we wanted a NPC to protect both Jesper and Enver the
 
−
dilcopy would look as follows:
 
−
<nowiki>
 
−
dilcopy teamwork@function("jesper/enver");</nowiki>
 
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">For this to work both mobs must be in the same room or following each other.</blockquote>
 
−
;Rescue
 
−
: This function when placed on a mob, located in the same room as another mob,
 
−
will allow the mobile to rescue the other mob if it is attacked. The
 
−
function is as follows:
 
−
<nowiki>
 
−
dilbegin aware rescue(lst: string);</nowiki>
 
−
This function takes one argument, a string of those mobiles
 
−
you wish this NPC to assist should they be attacked.
 
  
−
<blockquote style="background-color: #E8E8E8; font-style: italic; "> For this to work both NPCs must be in the same room or following each other.</blockquote>
+
==== Cleaning up ====
  
−
  Again we will use our test subjects Jesper and Enver and if
+
===== fido =====
−
we wanted an NPC to protect them and come to their aid the following
+
The NPC eats NPC corpses and food that lie in its room, every 10 to 30 seconds. When it eats a corpse, what the corpse held drops to the floor. It doesn't eat player corpses or buried things.
−
would be the dilcopy:
+
<pre>
−
<nowiki>
+
dilbegin fido(txt1:string,txt2:string);
−
dilcopy teamwork@function("jesper/enver");</nowiki>
+
</pre>
−
;Agressive
 
−
: This function makes a Mob hostile to person(s) in the room with it, under certain conditions which are provided as arguments.
 
−
In short, the all-singing, all-dancing aggression DIL. The following is
 
−
this functions definition:
 
−
<nowiki>
 
−
dilbegin aggressive (sx : integer, rce : integer, opp : integer,
 
−
                    levl : integer, sanc : integer, tme : integer,
 
−
                    tar : integer, align : string, attack :
 
−
                    stringlist);</nowiki>
 
 
{| class="wikitable"
 
{| class="wikitable"
−
|+Agressive arguments
+
! Argument !! Type !! Meaning
 
|-
 
|-
−
!argument
+
| txt1 || string || The message when it eats a corpse. <code>""</code> gives "&lt;npc&gt; savagely devours a corpse.", <code>"stop"</code> means it doesn't eat corpses.
−
!Type
 
−
!description
 
 
|-
 
|-
−
|sx
+
| txt2 || string || The message when it eats food. <code>""</code> gives "&lt;npc&gt; hungrily devours &lt;food&gt;.", <code>"stop"</code> means it doesn't eat food.
−
|integer
+
|}
−
|NOTE: not the sex values in values.h.
+
In the messages <code>$1n</code> is the NPC and <code>$2n</code> what it eats.
−
                                This decides the sex of your mob's
+
<pre>
−
                                victim.
+
dilcopy fido@function("$1n slowly devours $2n, crunching the bones.",
−
                                0 - Sex doesn't matter,
+
                      "$1n grabs $2n and hungrily munches it.");
−
                                1 - Attack opposite sex to self (if not
+
</pre>
−
                                    neutral!),
+
 
−
                                2 - Attack SEX_MALE,
+
===== janitors =====
−
                                3 - Attack SEX_FEMALE,
+
This one is in <code>midgaard.zon</code>, so it is <code>janitors@midgaard</code>. The NPC tidies its room: it picks up things it can carry and puts them in a trash bag (which it gets when the function starts), buries NPC corpses after taking what is in them, tells a player where their corpse lies, gives away food and drink, and throws out slime. It leaves containers alone, and does nothing in rooms where burying isn't allowed (<code>UNIT_FL_NO_BURY</code>). If it loses its trash bag, it stops wandering and sings a song instead.
−
                                4 - Attack SEX_NEUTRAL.
+
<pre>
 +
dilbegin fnpri(FN_PRI_MISSION) janitors(rate: integer);
 +
</pre>
 +
<code>rate</code> is the number of seconds between two rounds of tidying. The janitor doesn't move by itself; give it <code>wander_zones</code> or <code>global_wander</code> too.
 +
<pre>
 +
dilcopy janitors@midgaard(15);
 +
dilcopy wander_zones@function("@loadzone", 20, 1, 0);
 +
</pre>
 +
 
 +
==== Shops and services ====
 +
 
 +
===== shopkeepernew =====
 +
The NPC runs a shop. Players can <code>list</code> what it sells, <code>buy</code>, <code>sell</code>, <code>value</code> (what it would pay) and <code>request</code> (what it asks); see [[Help/Shops|Help: Shops]]. It restocks once a mud day, and buys from players only while it has money left for the day.
 +
<pre>
 +
dilbegin aware shopkeepernew(prod      : stringlist,
 +
                            custom_acts : stringlist,
 +
                            itemtypes  : intlist,
 +
                            sellprofit : integer,    buyprofit  : integer,
 +
                            maxcash    : integer, shophome : integer);
 +
</pre>
 +
{| class="wikitable"
 +
! Argument !! Type !! Meaning
 
|-
 
|-
−
|rce
+
| prod || stringlist || What it sells. Each entry is <code>"symbol@zone daily max"</code>: the object, how many come into stock each mud day, and the most it keeps. Both numbers must be more than 0.
−
|integer
 
−
|Any of the PC races from 0 to 14. A value
 
−
                                of -1 means we don't care about the
 
−
                                victim's race.
 
 
|-
 
|-
−
|opp
+
| custom_acts || stringlist || Its messages, in the order below. An empty or missing message gets the default.
−
|integer
 
−
|0 - Non race specific (same as rce := -1)
 
−
                                1 - Attack the specified rce,
 
−
2 - Attack any pc race _but_ the specified rce.
 
 
|-
 
|-
−
|levl
+
| itemtypes || intlist || The kinds of object it buys from players, as <code>ITEM_</code> constants (from <code>vme/include/vme.h</code>), for example <code>{ITEM_FOOD, ITEM_DRINKCON}</code>.
−
|integer
 
−
|Allow level specific aggression.
 
−
                                A value of 30 would make the mob hostile
 
−
                                to all pcs level 30 and above.
 
−
                                A value of -30 (note the -) would make the
 
−
                                mob hostile to all pcs level 30 or below.
 
−
                                A value of 0 means level doesn't matter.
 
 
|-
 
|-
−
|sanc
+
| sellprofit || integer || Its selling price, as a percentage of the object's <code>cost</code>: 110 means 10% more than the cost.
−
|integer
 
−
|Does this mob obey the sanc/soothe rules?
 
−
                                (ie, if someone has cast sanctuary on
 
−
                                themselves, will this mob recognize it, and
 
−
                                not attack, or attack anyway).
 
−
                                0 - Doesn't obey sanc or soothe
 
−
                                1 - Obeys only sanc
 
−
                                2 - Obeys only soothe
 
−
                                3 - Obeys both sanc and soothe
 
−
                                (SOOTHE is a new spell for ranger's guild)
 
 
|-
 
|-
−
|tme
+
| buyprofit || integer || What it pays players, as a percentage of the cost: 50 means half.
−
|integer
 
−
|Time in ticks to wait before attacking (is
 
−
                                automatically put to RANTIME, ie, time
 
−
                                variance of time-time/2 to time+time/2).
 
−
                                Values accepted are from 0 to 400 (that's
 
−
                                0 - 100 seconds. Can be specified using
 
−
                                PULSE_SEC).
 
 
|-
 
|-
−
|tar
+
| maxcash || integer || The money it has each mud day to buy things from players, in money units (an iron piece is 10; <code>2*PLATINUM_MULT</code> is two platinum pieces).
−
|integer
 
−
|This is a special value which determines
 
−
                                which of the eligible victims we pick.
 
−
                                -2 - Last eligible victim to into the room.
 
−
                                -1 - Weakest eligible victim in room.
 
−
                                0  - Random eligible victim.
 
−
                                +1 - Strongest eligible victim in room.
 
−
+2 - First eligible victim into the room.
 
 
|-
 
|-
−
|align
+
| shophome || integer || <code>TRUE</code>: it serves only in the room where it was loaded, and walks back there if moved. <code>FALSE</code>: a wandering trader.
−
|string
 
−
|The desired alignment of the victim.
 
−
                                "ANY"      - We don't care about the alignment.
 
−
                                "GOOD"    - Attack only good alignment.
 
−
                                "EVIL"    - Attack only evil alignment.
 
−
                                "NEUTRAL " - Attack only neutral alignment.
 
−
                                "OPPOSITE" - Attack opposite alignment to self
 
−
                                (provided self isn't neutral).
 
−
"SALIGN" - Attack same alignment as self.
 
−
                                "DALIGN" - Attack any alignment
 
−
                                different to self.
 
−
|-
 
−
|attack
 
−
|stringlist
 
−
|This is a 2 string stringlist. These are
 
−
                                    the messages sent to the people in the room
 
−
                                    except the victim, and the victim itself,
 
−
                                    in that order.
 
−
                                    If the second (victim) string is "", the
 
−
                                    first string will be shown to the victim,
 
−
                                    as if they were anyone else in the room.
 
−
                                    You can leave both blank if you wish.
 
−
                                    $1n is the mob name (self), $3n is the
 
−
                                    victim's name.
 
−
                                    NOTE: the $ values only apply if you supply
 
−
                                    BOTH string 1 and 2.
 
 
|}
 
|}
−
The argument descriptions pretty much explain everything there is
+
The messages, in order. <code>$1n</code> is the shopkeeper, <code>$2n</code> the object and <code>$3n</code> the player.
−
to know about the agressive function and what it was so we will finish
+
# The player asks for something it doesn't have.
−
off by giving an example of a dilcopy that will create a NPC that fits
+
# The player tries to sell or value something they don't have.
−
the following description
+
# The player tries to sell something of a kind it doesn't buy.
 +
# The player can't afford it.
 +
# After a purchase. (Not shown at present: it says "That cost you ..." instead.)
 +
# After a sale. (Not shown at present: it says "I paid you ..." instead.)
 +
# It hasn't got as many as the player asked for.
 +
# The object can't be sold (it has an extra named <code>$no-sell</code>).
 +
# It has no money left to buy with.
  
−
Let's say our mob is a level 40 Goblin who doesn't like
+
<code>shopkeepernew</code> has no opening hours. For those, add <code>opening_hours</code> (below).
−
dwarves. He's very particular in that he doesn't like evil female
 
−
dwarves who are level 20 and above. He does recognize the sanctuary
 
−
spell, but he doesn't recognize soothe, and he'll wait 10 seconds on
 
−
average before he attacks. The 2 messages sent are: "$1n savagely
 
−
attacks $3n with his big axe!" and "$1n attacks you!"
 
  
−
Here's what the function call would look like:
+
Here is Hogan, a bartender. The lists are made into macros with <code>#define</code>, at the top of the zone file, to keep the NPC readable; a <code>\</code> at the end of a line continues the macro on the next line.
−
<nowiki>
+
<pre>
−
dilcopy aggressive (3, 2, 1, 20, 2, PULSE_SEC*10, 0, "EVIL",
+
#define TAVERN_PROD {"tuborg@udgaard 5 20", "beer_bottle@midgaard 10 30"}
−
                    {"$1n savagely attacks $3n with his big axe!",
 
−
                    "$1n attacks you!"});</nowiki>
 
−
In this example, 3 (attack females), 2 (attack dwarves), 1 (just dwarves),
 
−
  20 (Level 20+ victims), 2 (obey only soothe), PULSE_SEC*10
 
−
(wait around 10 seconds before attacking), EVIL (attack only
 
−
evil), and the strings in the stringlist are displayed to
 
−
the victim and the room, in that order.
 
−
;Janitors
 
−
: This function turns the NPC into a janitor that will pick up items left lying around and will also tell new  players. those under level 20,
 
−
where there corpse is if they come across it in there wanderings.
 
−
You must also supply the wander_zone DIL for this to work correctly.
 
−
The definition for the janitor function is as follows:
 
−
<nowiki>
 
−
dilbegin janitors(rate: integer);</nowiki>
 
−
The Janitor function only takes one argument and that determines
 
−
how fast the janitor will pick up stuff in seconds.
 
  
−
To make a Janitor that will pick up stuff every thirty seconds the
+
#define TAVERN_MSG \
−
following would be the dilcopy:
+
{"$1n says, 'This is a tavern, I don't sell such an item as that!'", \
−
<nowiki>
+
  "$1n says, '$3n, you don't even have that!'", \
−
dilcopy janitor@function(30);</nowiki>
+
"$1n says, 'I don't trade in things such as $2n! Just buy a beer!'", \
−
;Shop Keeper
+
"$1n says, '$3n, you can't afford $2n.'", \
−
: This is one of the more complex dilcopies and considered by some to be confusing. Below I will step you through the creation of the mobile,
+
  "$1n says, 'Here you are.'", \
−
and the application of this DIL using defines to hopefully simplify the
+
"$1n says, 'Thank you, $3n.'", \
−
use of this function. The function is defined as:
+
  "$1n says, 'I don't have that many $2Ns in stock.'", \
−
<nowiki>
+
  "$1n says, 'I haven't got a use for $2n.'", \
−
dilbegin aware shopkeeper(prod: stringlist, custom_acts : stringlist,
+
  "$1n says, 'I'd like to buy it, but I can't afford it, sorry.'"}
−
                            opentimes : stringlist, itemtype: string,
 
−
sellprofit : integer,buyprofit: integer,
 
−
maxcash : integer,closedil : string,
 
−
dilparams : string );</nowiki>
 
−
;Step 1
 
−
: First, figure out what you want your shopkeeper to sell.  He can sell pretty much any item from any zone, as long as you know its symbolic name.
 
−
For Hogan (our example shopkeeper), he is a bartender, so he sells things
 
−
you would commonly find in a pub, tavern, or bar.
 
−
His list of items (their symbolic names at which zone) are:
 
−
  <nowiki>
 
−
grain_alcohol@gobtown1
 
−
pretzels@gobtown1
 
−
beer_nuts@gobtown1
 
−
rum_coke@gobtown1
 
−
tuborg@udgaard</nowiki>
 
−
Now, since I use defines, I make a define for Hogan's products.  I called
 
−
it TAVERN_PROD (for tavern's products).  And use the following setup
 
−
and just stick the names of your items in where his items are.
 
−
Each item will have a setup like this:
 
−
<nowiki>
 
−
"tuborg@udgaard 15 20"</nowiki>
 
−
A symbolic name followed by two numbers, with the entire thing in
 
−
quotes. Where :
 
−
* The "tuborg@udgaard" is your item's symbolic name
 
−
* The 15 (our first number in the string) is the number of that item that
 
−
  will load into your shop daily
 
−
* The 20 (our second number in the string) is the limit available of that
 
−
  item in the shop ever
 
−
So this shop would sell tuborgs.. and every mudday, 15 tuborgs will load
 
−
into our shop to replenish our stock.. and the maximum tuborgs we can have
 
−
at any given time is 20.
 
  
−
Next we place all this info into the define we created above, which would look
+
#define TAVERN_TYPES {ITEM_DRINKCON, ITEM_FOOD}
−
like this:
 
−
<nowiki>
 
−
#define TAVERN_PROD \
 
−
{"grain_alcohol@gobtown1 15 20", \
 
−
"pretzels@gobtown1 10 15", \
 
−
"beer_nuts@gobtown1 15 20", \
 
−
"rum_coke@gobtown1 10 15", \
 
−
"tuborg@udgaard 15 20"}</nowiki>
 
−
The above is my define for Hogan's products that he sells.  Each one is in
 
−
quotes and they have commas separating them.  If you put each item on its
 
−
own separate line, you need to put a space and then a back slash after the
 
−
comma which separates the items, like it shows above.  The entire define
 
−
is enclosed in curly brackets, {}.
 
−
Now we are finished with the items he sells.
 
−
;Step 2
 
−
: Now you must decide what kind of dialogue you would like your shopkeeper to say.  There are ten separate responses you can make for your shopkeeper.  They do go in a specific order and I will list what each do.
 
  
−
;Response 1
+
%mobiles
−
: The first response will be used if the shopkeeper doesn't have the particular item you're trying to buy in stock, or if he doesn't sell that item at all.
 
−
;Response 2
 
−
: The second response is used when the player is trying to sell the shopkeeper something which the player does not have in his inventory. Items worn by the player can not be sold until removed from there worn position.
 
−
;Response 3
 
−
: The third response is used when the player is trying to sell the shopkeeper something that is not one of those of his trade types. (This will be more clear when we get to the trade type part below. Such as a player trying to sell our bartender a canoe. =)
 
−
;Response 4
 
−
: The fourth response is used when the player tries to buy something from the shopkeeper, but doesn't have enough money to buy it.
 
−
;Response 5
 
−
: The fifth response is used when the sale was successful and the player buys something from the shopkeeper.
 
−
;Response 6
 
−
: The sixth response is again used when the sale was successful, but this time it's for when the player successfully sells something to the shopkeeper.
 
−
;Response 7
 
−
: The seventh response is used when the shopkeeper doesn't have enough of the item to sell as the player requests. Such as someone trying to buy 10 tuborgs, but our bartender only has 9.
 
−
;Response 8
 
−
: The eighth response is Used when the shop is closed and a player tries to buy something from or sell something to the shopkeeper.
 
−
;Response 9
 
−
: The ninth response is used when the player tries to sell an item to the shopkeeper that the shopkeeper doesn't trade that item.
 
−
;Response 10
 
−
: The tenth (and last!) response is for when the shopkeeper has run out of money and can't afford to buy what the player is trying to sell him.
 
  
−
Now. again, I made a define called TAVERN_MSG (for tavern messages) and I
+
bartender
−
placed all my responses in it.  Don't forget, they do go in that specific
+
names {"Hogan", "goblin", "bartender"}
−
order!  And below is our setup with responses in it.
+
title "Hogan"
 +
descr "Hogan stands behind the bar, waiting to take your order."
 +
extra {}
 +
"He looks back at you, patiently waiting for your order."
 +
M_SHOP_KEEPER(30, SEX_MALE, RACE_GOBLIN)
 +
money 2 SILVER_PIECE, 2 COPPER_PIECE
  
−
<blockquote style="background-color: #E8E8E8; font-style: italic; ">In the responses below, $1n refers to the shopkeeper, $2n refers to the item being sold, bought, etc.. and $3n refers to the person dealing with the shopkeeper.</blockquote>
+
dilcopy opening_hours@function({8, 23}, {"list", "buy", "sell", "value", "request"},
−
<nowiki>
+
  "say Sorry, we're closed.",
−
#define TAVERN_MSG \
+
  {"stand", "say The bar is open!"},
−
{"$1n says, 'This is a tavern, I don't sell such an item as that!'", \
+
  {"say The bar is closed, come back at eight.", "rest"});
−
"$1n says, '$3n, you don't even have that!'", \
+
 
−
"$1n says, 'I don't trade with things such as $2n! Just buy a beer!'", \
+
dilcopy shopkeepernew@function(TAVERN_PROD, TAVERN_MSG, TAVERN_TYPES,
−
"$1n says, '$3n, you can't afford $2n.'", \
+
                              110, 50, 2*PLATINUM_MULT, TRUE);
−
"$1n says, 'Thank you, $3n, here are %s for $2n.'", \
+
end
−
"$1n says, 'Thank you, $3n.'", \
+
</pre>
−
"$1n says, 'I don't have that many $2ns in stock.'", \
+
Hogan sells Tuborgs from Udgaard and bottles of beer from Midgaard at 110% of their cost, buys drinks and food from players at half their cost, and has two platinum pieces a day for that.
−
"$1n says, 'I'm on break, come back later.'", \
+
 
−
"$1n says, 'I haven't got a use for $2n.'", \
+
===== opening_hours =====
−
"$1n says, 'I'd like to buy it, but I can't afford it, sorry.'"} \</nowiki>
+
Closes a shop (or anything else) outside its opening hours: it blocks the commands you list, and the NPC does what you give it when it opens and closes.
−
Just like with the items, the responses are in quotes, and are separated
+
<pre>
−
with commas.  Since I put each on their own separate lines (for neatness
+
dilbegin fnpri(FN_PRI_BLOCK-1) opening_hours(shophours  : intlist,
−
sake), I put a space and a back slash, \, after each. The entire define is
+
                                            blockcmds : stringlist,
−
enclosed in curly braces,{}.
+
                                            blockexec : string,
−
And then you're done with your shopkeeper's messages!
+
                                            opencmds  : stringlist,
−
Don't worry, it gets simpler from here.
+
                                            closecmds : stringlist);
−
;Step 3
+
</pre>
−
: Now we get to decide when we want our shop to be open.  We get to use military time, so 1 refers to 1am, 6 refers to 6am, 12 refers to 12pm
 
−
(noon), 18 refers to 6pm, and both 0 and 24 refer to 12am (midnight)..
 
−
etc.. =)
 
−
And my define for this I named TAVERN_OPEN_TIMES (for when the tavern is
 
−
open) and I used the following setup:
 
−
  <nowiki>
 
−
#define TAVERN_OPEN_TIMES {"12","18"}</nowiki>
 
−
You just have to make your define and stick your times in quotes and
 
−
enclose them in curly braces. So Hogan will be opened from 1am ("1")
 
−
until 11pm ("23").  He will close after 11pm and reopen again at 1am.
 
−
You may also add multiple open and close times as per the following
 
−
example:
 
−
  <nowiki>
 
−
#define TAVERN_OPEN_TIMES {"1","12","16","20"}</nowiki>
 
−
;Step 4
 
−
: For this step you get to choose your shopkeeper's trade types.  And what you pick all depends on what kinds of things you want your shopkeeper to sell and buy.  You can find the item types in ''values.h'', but I'll also list them below.
 
 
{| class="wikitable"
 
{| class="wikitable"
−
|+Sale types
+
! Argument !! Type !! Meaning
 
|-
 
|-
−
!Value
+
| shophours || intlist || Pairs of mud hours, open from the first to the second, both included: <code>{8, 23}</code>, or <code>{4, 10, 12, 20}</code> for two periods. A period can't cross midnight: write <code>{22, 23, 0, 6}</code>, not <code>{22, 6}</code>.
−
!Type
 
−
!Value
 
−
!Type
 
 
|-
 
|-
−
|1
+
| blockcmds || stringlist || The commands it refuses while closed.
−
|ITEM_LIGHT
 
−
|14
 
−
|ITEM_TRAP
 
 
|-
 
|-
−
|2
+
| blockexec || string || The command the NPC does when it refuses one, for example <code>"say We're closed."</code>.
−
|ITEM_SCROLL
 
−
|15
 
−
|ITEM_CONTAINER
 
 
|-
 
|-
−
|3
+
| opencmds || stringlist || Commands the NPC does when it opens.
−
|ITEM_WAND
 
−
|16
 
−
|ITEM_NOTE
 
 
|-
 
|-
−
|4
+
| closecmds || stringlist || Commands the NPC does when it closes.
−
|ITEM_STAFF
 
−
|17
 
−
|ITEM_DRINKCON
 
−
|-
 
−
|5
 
−
|ITEM_WEAPON
 
−
|18
 
−
|ITEM_KEY
 
−
|-
 
−
|6
 
−
|ITEM_FIREWEAPON
 
−
|19
 
−
|ITEM_FOOD
 
−
|-
 
−
|7
 
−
|ITEM_MISSILE
 
−
|20
 
−
|ITEM_MONEY
 
−
|-
 
−
|8
 
−
|ITEM_TREASURE
 
−
|21
 
−
|ITEM_PEN
 
−
|-
 
−
|9
 
−
|ITEM_ARMOR
 
−
|22
 
−
|ITEM_BOAT
 
−
|-
 
−
|10
 
−
|ITEM_POTION
 
−
|23
 
−
|ITEM_SPELL
 
−
|-
 
−
|11
 
−
|ITEM_WORN
 
−
|24
 
−
|ITEM_BOOK
 
−
|-
 
−
|12
 
−
|ITEM_OTHER
 
−
|25
 
−
|ITEM_SHIELD
 
−
|-
 
−
|13
 
−
|ITEM_TRASH
 
−
|
 
−
|
 
 
|}
 
|}
−
We are making a bartender, so he should sell food and drinks. So I
+
See Hogan above for an example.
−
selected ITEM_FOOD, and it's corresponding number is 19.  So I made my
+
 
−
define TAVERN_ITEM_TYPE (for our tavern's type of items) using the
+
===== shopkeeper =====
−
following setup:
+
The older form of the shop, still used by many shops in the public zones. It passes its arguments on to <code>shopkeepernew</code>; new shops should use <code>shopkeepernew</code> directly.
−
<nowiki>
+
<pre>
−
#define TAVERN_ITEM_TYPE "19"</nowiki>
+
dilbegin aware shopkeeper(prod      : stringlist, custom_acts : stringlist,
−
Now, if we had a magic shop, and wanted to sell potions and scrolls, I
+
                          opentimes  : stringlist, itemtype    : string,
−
would make a define called for example MAGIC_ITEM_TYPE and make it like
+
                          sellprofit : integer,   buyprofit  : integer,
−
this:
+
                          maxcash    : integer,
−
<nowiki>
+
                          closedil  : string,    dilparams  : string );
−
#define MAGIC_ITEM_TYPE "2 10"</nowiki>
+
</pre>
−
The 2 was our number corresponding to the scrolls, and the 10
+
The differences: <code>custom_acts</code> has ten messages, with "the shop is closed" as the eighth; <code>itemtype</code> is a string of numbers, such as <code>"17 19"</code>; and <code>opentimes</code>, <code>closedil</code> and <code>dilparams</code> are ignored, so the shop is always open unless you add <code>opening_hours</code>. The shopkeeper always stays in its shop. At present, from the seventh message on, the messages come out in the wrong places; another reason to use <code>shopkeepernew</code>.
−
corresponded to the potions.  That is how you make your shopkeeper
+
 
−
sell more than one item type, just stick the corresponding numbers inside
+
===== evaluate =====
−
quotes with a space separating them.
+
For a fee, the NPC tells a player about a weapon, armour or shield they carry: the kind of weapon, armour or shield, and how good its craftsmanship is. The player types <code>evaluate &lt;item&gt;</code>.
−
;Step 5
+
<pre>
−
: Now you get to decide how much money your shopkeeper gets to have to buy things with.  One platinum piece is equal to 40960.  So if I wanted him to have two platinum pieces to spend on buying things from players, I would make a define called TAVERN_MAX_CASH (for the maximum amount of money our shopkeeper gets) and use the following setup:
+
dilbegin aware evaluate (amt: integer);
−
<nowiki>
+
</pre>
−
#define TAVERN_MAX_CASH 81920</nowiki>
+
<code>amt</code> is the fee in iron pieces; 64 is one silver piece.
−
I got 81920 by multiplying the 40960 (one platinum) by 2
+
<pre>
−
;Step 6
+
dilcopy evaluate@function(64);
−
: The sixth thing we get to do is to decide how much profit does our shopkeeper get when he sells his items. Items should have a cost to them already tagged on them, so their whatever their cost is, that is equal to 100%. Now, if your shopkeeper wants to take an extra 10% on the items he's selling so he can support his family, then you would make his selling profit 110.  So I made a define called TAVERN_SELL_PROFIT (for his profit when he sells things) and gave him 110% selling profit, and used the following setup:
+
</pre>
−
<nowiki>
+
 
−
#define TAVERN_SELL_PROFIT 110</nowiki>
+
===== mercenary_hire =====
−
;Step 7
+
The NPC can be hired to kill a player. <code>offer &lt;player&gt;</code> tells you the price, <code>contract &lt;player&gt;</code> pays it. The mercenary then sneaks to the victim, fights until the victim is dead, takes the loot and goes back home. It refuses players of level 20 or below and gods; only gods can hire it against an NPC. The price is 20 platinum pieces plus a little per level of the victim.
−
: This last define is almost exactly like our selling profit, but now, we're doing our buying profit... when a player sells an item to the shopkeeper,
+
<pre>
−
he doesn't want to pay full price because it must be used since a player
+
dilbegin mercenary_hire();
−
has it.  Now the item's cost is 100%, and maybe the shopkeeper only wants
+
</pre>
−
to buy items for half its cost. So I would make his buying profit 50,
+
<pre>
−
and use the following setup.
+
dilcopy mercenary_hire@function();
−
<nowiki>
+
</pre>
−
#define TAVERN_BUY_PROFIT 50</nowiki>
+
 
−
All of the previous  defines you can place anywhere in the zone.  I like
+
==== Pets and followers ====
−
to place mine before the %DIL section just to keep them somewhere where
 
−
I know they all are.  You can place each one on the mob itself, but I
 
−
think that looks cluttered so's why I put them where I put
 
−
them.  And you're going to have a dilcopy placed on your mob also, which
 
−
I'll explain in step 8.
 
−
;Step 8
 
−
: Okay one last step. Now you get to place the DIL on your shopkeeper mob using all of those cute little defines you just made.  The syntax for the DIL is:
 
−
<nowiki>
 
−
  dilcopy shopkeeper@function(products, responses, opentimes,
 
−
                            tradetypes, sellprofit, buyprofit,
 
−
                            maxcash, closedil, dilparams);</nowiki>
 
−
Take your defines from above the defines that you made are
 
−
called:
 
−
<nowiki>
 
−
TAVERN_PROD, TAVERN_MSG, TAVERN_OPEN_TIMES, TAVERN_ITEM_TYPE,
 
−
TAVERN_SELL_PROFIT, TAVERN_BUY_PROFIT, and TAVERN_MAX_CASH.</nowiki>
 
−
Now all you have to do is place them in the syntax where they belong like
 
−
in the below example.
 
−
<nowiki>
 
−
dilcopy shopkeeper@function(TAVERN_PROD, TAVERN_MSG, TAVERN_OPEN_TIMES,
 
−
                            TAVERN_ITEM_TYPE, TAVERN_SELL_PROFIT,
 
−
                            TAVERN_BUY_PROFIT, TAVERN_MAX_CASH, "", "");</nowiki>
 
−
For the last two fields, I just put "", "" because I don't make my own
 
−
unique DIL for those.  By just putting and empty set of quotes for each,
 
−
it makes it go to the default.
 
−
And make sure you don't forget that semicolon at the end either.
 
  
−
You are pretty much done now. All you have to do is place your
+
===== obey =====
−
defines either up before %DIL or somewhere in %mob if you'd like, and
+
The NPC obeys the character it follows. When that character types <code>tell &lt;npc&gt; &lt;command&gt;</code> in the same room, the NPC does the command, for example <code>tell familiar cast heal papi</code>. Others are ignored.
−
place the dilcopy onto your mob.
+
<pre>
 +
dilbegin obey();
 +
</pre>
 +
<pre>
 +
dilcopy obey@function();
 +
</pre>
  
−
Just to make sure I've completely beaten a very dead horse, this is
+
===== obey_animal =====
−
what it would look like in the end.
+
<code>obey</code> for animals: the animal obeys only simple commands (moving, <code>kill</code>, <code>get</code>, <code>drop</code>, <code>give</code>, <code>follow</code>, <code>flee</code>, <code>look</code>, <code>sit</code>, <code>sleep</code>... but no spells or talking). Don't add <code>obey</code> as well; <code>obey_animal</code> adds it itself.
−
<nowiki>
+
<pre>
−
%zone sample_zon
+
dilcopy obey_animal@function();
 +
</pre>
  
−
#define TAVERN_PROD \
+
==== Teachers ====
−
{"grain_alcohol@gobtown1 15 20", \
 
−
"pretzels@gobtown1 10 15", \
 
−
"beer_nuts@gobtown1 15 20", \
 
−
"rum_coke@gobtown1 10 15", \
 
−
"tuborg@udgaard 15 20"}
 
  
−
#define TAVERN_MSG \
+
Teachers themselves are made with <code>special SFUN_TEACH_INIT</code>, described in [[Manual:Zone Manual/The NPC Section/A more complex set of NPCs|A more complex set of NPCs]]. These functions limit who may practise with them.
−
{"$1n says, 'This is a tavern, I don't sell such an item as that!'", \
 
−
"$1n says, '$3n, you don't even have that!'", \
 
−
"$1n says, 'I don't trade with things such as $2n! Just buy a beer!'", \
 
−
"$1n says, '$3n, you can't afford $2n.'", \
 
−
"$1n says, 'Thank you, $3n, here are %s for $2n.'", \
 
−
"$1n says, 'Thank you, $3n.'", \
 
−
"$1n says, 'I don't have that many $2ns in stock.'", \
 
−
"$1n says, 'I'm on break, come back later.'", \
 
−
"$1n says, 'I haven't got a use for $2n.'", \
 
−
"$1n says, 'I'd like to buy it, but I can't afford it, sorry.'"} \
 
  
−
#define TAVERN_OPEN_TIMES {"1","23"}
+
===== teach_q_block =====
−
#define TAVERN_ITEM_TYPE "19"
+
Only players who have done a quest may <code>practice</code>. Others are refused, and the NPC does the command <code>s</code>.
−
#define TAVERN_MAX_CASH 81920
+
<pre>
−
#define TAVERN_SELL_PROFIT 110
+
dilbegin fnpri(FN_PRI_BLOCK) teach_q_block(q : string, s : string);
−
#define TAVERN_BUY_PROFIT 50
+
</pre>
 +
<code>q</code> is the quest as the player has it, for a finished quest usually "&lt;name&gt; Complete".
 +
<pre>
 +
dilcopy teach_q_block@function("Mary's Pot Complete", "say Buggar ye off!");
 +
</pre>
 +
<code>shop_q_block@function</code> takes the same arguments and does the same for <code>buy</code> and <code>sell</code> at a shop.
  
−
%mobiles
+
===== TrainMemberChk =====
 +
In <code>guilds.zon</code>: only members of the guild may <code>practice</code>. The second argument is the command the NPC does when it refuses a player, or <code>""</code> for "say You're not a member of our guild, go speak with the guild master."
 +
<pre>
 +
dilbegin fnpri(FN_PRI_BLOCK+1) TrainMemberChk(sGuild : string, sMsg : string);
 +
</pre>
 +
<pre>
 +
dilcopy TrainMemberChk@guilds(GUILD_UDG_FIGHTER, "");
 +
</pre>
 +
The guild masters' functions (<code>MasterJoin</code>, <code>SetTitles</code>, <code>MurderBanish</code>) are also in [[Manual:Zone Manual/The NPC Section/A more complex set of NPCs|A more complex set of NPCs]].
  
−
bartender
+
==== More ====
−
names {"hogan","goblin","bartender"}
 
−
title "Hogan"
 
−
descr "Hogan stands behind the bar waiting to take your order."
 
−
extra {}
 
−
"He looks back at you, patiently waiting for your order."
 
−
M_AVG_GOBLIN(76,SEX_MALE)
 
−
alignment -1000
 
−
exp 100
 
−
money 2 SILVER_PIECE, 2 COPPER_PIECE
 
  
−
dilcopy shopkeeper@function(TAVERN_PROD, TAVERN_MSG, TAVERN_OPEN_TIMES,
+
<code>function.zon</code> holds more than this page shows: restrictions for objects (<code>abi_restrict</code>, <code>guild_restrict</code>, ...), functions for rooms (<code>death_room</code>, <code>force_move</code>, <code>safe_room</code>, <code>climb</code>), ships and others. The comments above each <code>dilbegin</code> explain them. The quest helpers for NPCs are in <code>quests.zon</code>.
−
                            TAVERN_ITEM_TYPE,TAVERN_SELL_PROFIT,
 
−
                            TAVERN_BUY_PROFIT, TAVERN_MAX_CASH, "", "");
 
−
end</nowiki>
 
  
−
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/The_NPC_Section/Compiling_and_debugging_your_first_NPC|Previous: Compiling and debugging your first NPC]]</div>
+
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone Manual/The NPC Section/Compiling and debugging your first NPC|Previous: Compiling and debugging your first NPC]]</div>
−
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/The_NPC_Section/A_more_complex_set_of_NPCs|Next: A more complex set of NPCs]]</div>
+
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone Manual/The NPC Section/A more complex set of NPCs|Next: A more complex set of NPCs]]</div>

Latest revision as of 06:17, 15 November 2026

DIL functions for NPCs

DIL is the language for making rooms, NPCs and objects do things. This manual doesn't teach you to write DIL; the DIL manual does. But DikuMUD3 comes with many ready-made DIL functions (templates) that you can put on an NPC without writing any DIL yourself. This page describes the ones for NPCs.

You put a template on an NPC with dilcopy in its definition:

dilcopy aggressive@function(0, -1, 0, 0, 3, PULSE_SEC*5, 0, "ANY", {"$1n attacks $3n!", "$1n attacks you!"});
  • The name is template@zone. Most of these live in vme/zone/function.zon; a few in other zones, such as guilds.zon and midgaard.zon.
  • The arguments are numbers (integer), strings in double quotes (string), string lists in braces such as {"a", "b"} (stringlist), number lists such as {4, 23} (intlist), and null for an empty list. Macros from the headers work in them, for example PULSE_SEC*10 or RACE_DWARF.
  • The line ends with ;.
  • vmc checks neither the name nor the arguments. A misspelt template or a wrong argument compiles fine, and shows up only at boot or when the NPC acts, as an error in vme/bin/vme.log. Before you use a template, read its dilbegin line, and the comment above it, in the zone file on GitHub.
  • Times are often in ticks: 4 ticks are one second. PULSE_SEC (4) and WAIT_SEC (4) are macros for it.
  • In messages, $1n, $2n and $3n are replaced by names of the units involved; each function below says which is which. See act().

You can give an NPC as many of these as you like; the janitor in A more complex set of NPCs has two. In the game, wstat <symbol>@<zone> func lists the DIL programs an NPC runs.

Many NPC templates in macros.h already add some of these functions; for example the black dragon templates add aggressive and combat_mag. See NPC macros.

Fighting

aggressive

Makes the NPC attack players who come into its room, or do something there, under the conditions you give. It attacks only players it can see, never gods, and only while it is awake and not already fighting.

dilbegin aggressive (sx : integer, rce : integer, opp : integer,
                     levl : integer, sanc : integer, tme : integer,
                     tar : integer, align : string, attack : stringlist);
Argument Type Meaning
sx integer The victim's sex (not the SEX_ values): 0 any, 1 the opposite of the NPC's own (not for a neutral NPC), 2 male, 3 female, 4 neutral.
rce integer A player race, RACE_HUMAN (0) to RACE_DARK_ELF (10), or -1 for any race.
opp integer What to do with rce: 0 ignore it, 1 attack only that race, 2 attack every race but that one.
levl integer 0: any level. 30: players of level 30 and above. -30: players of level 30 and below. Allowed: -49 to 50.
sanc integer Whether the NPC spares protected players: 0 no, 1 those with sanctuary, 2 those with soothe, 3 both.
tme integer How long it waits before attacking, in ticks, 0 to 400 (100 seconds). The real wait is random, between about half and one and a half times this.
tar integer Which of the players who qualify it picks: -2 the last to enter the room, -1 the weakest, 0 a random one, 1 the strongest, 2 the first to enter.
align string The victim's alignment: "ANY", "GOOD", "EVIL", "NEUTRAL", "OPPOSITE" (the opposite of the NPC's; not for a neutral NPC), "SALIGN" (the same as the NPC's) or "DALIGN" (any other than the NPC's).
attack stringlist The attack messages: {"to the others", "to the victim"}. $1n is the NPC, $3n the victim. With one string, everyone in the room sees it (don't use $3n then); with {} or {""} there is no message.

If an argument is out of range the function logs "AGGRO ERROR" in vme.log and stops.

A level 40 goblin who hates evil female dwarves of level 20 and above, spares players with sanctuary (but not soothe), and waits about 10 seconds before attacking:

dilcopy aggressive@function(3, RACE_DWARF, 1, 20, 1, PULSE_SEC*10, 0, "EVIL",
                            {"$1n savagely attacks $3n with his big axe!",
                             "$1n attacks you!"});

A monster that attacks anyone, after about 20 seconds, with one message for all:

dilcopy aggressive@function(0, -1, 0, 0, 3, PULSE_SEC*20, 0, "ANY",
                            {"Big monster attacks!"});
combat_mag

Makes the NPC cast spells while it fights: an attack spell, and a defence spell (such as a heal on itself) when its hit points run low.

dilbegin fnpri(FN_PRI_COMBAT) combat_mag(atk_spl : string, def_spl : string, def_pct : integer,
                    spd: integer);
Argument Type Meaning
atk_spl string The attack spell, as a player types it after cast, for example "fireball", or "" for none.
def_spl string The defence spell, for example "heal", or "" for none.
def_pct integer When the NPC's hit points are at or below this percentage of its maximum, it casts the defence spell.
spd integer How often it casts the attack spell: 1 every combat round, 2 every second round, and so on. 2 is a good choice.

The defence spell comes first whenever the hit points are low. With a defence spell, the NPC casts its attack spell only while it has 40 mana or more, so that some is left for the defence; without one, 16 or more. The spell names are in vme/etc/spells.def.

dilcopy combat_mag@function("harm", "heal", 25, 2);
comb_poison and comb_acid

In a fight, about half of the NPC's hits also poison the victim (comb_poison) or burn them with acid (comb_acid). The two messages go to the victim and to the others in the room; $1n is the NPC, $3n the victim.

dilbegin aware comb_poison(toact : string, restact : string);
dilbegin aware comb_acid(toact : string, restact : string);
dilcopy comb_poison@function("You feel very ill as $1n bites you!",
                             "$1n sinks $1s fangs deep into $3n!");
teamwork

The NPC joins the fight when one of the NPCs it protects is attacked, if they are in the same room.

dilbegin aware fnpri(FN_PRI_RESCUE) teamwork(lst: string);

lst lists the names of the NPCs to help, separated by /. A name matches one of the names in the other NPC's names.

dilcopy teamwork@function("guard/captain");

Note: at present the function skips NPCs of its own zone, so it helps only NPCs from other zones.

rescue

The NPC rescues one of the NPCs it protects when that NPC is fighting in the same room and is down to half its hit points or less. Both must come from the same zone. It uses the rescue skill, so it can fail.

dilbegin aware fnpri(FN_PRI_RESCUE) rescue(lst: string);

lst is as for teamwork. NPCs often have both:

dilcopy teamwork@function("guard/captain");
dilcopy rescue@function("guard/captain");

Moving around

wander_zones

The NPC walks through random exits, but only into rooms of the zones you list, and never into a room with UNIT_FL_NO_MOB. It stands up if it is sitting or resting, and does nothing while asleep. If it finds itself outside its zones, it waits five minutes and tries again.

dilbegin wander_zones(zones : string, spd : integer, doors : integer, lckd_doors : integer);
Argument Type Meaning
zones string Zone names separated by spaces. @loadzone in the list stands for the zone the NPC is in when it starts.
spd integer Seconds between steps; less than 5 counts as 5.
doors integer 1: it opens closed doors to go through, and closes them behind it. 0: it doesn't.
lckd_doors integer 1: it also goes through locked doors, without a key, and locks them again behind it. 0: it doesn't.
dilcopy wander_zones@function("haon_dor @loadzone", 30, 1, 0);

An NPC with an extra named $block wander stops wandering.

global_wander

Like wander_zones, but the NPC may wander into any zone.

dilbegin global_wander(spd : integer, doors : integer, lckd_doors : integer);

The arguments are those of wander_zones without zones; a speed below 2 counts as 5 seconds.

dilcopy global_wander@function(60, 1, 0);

Guards

These guards block only in the room where the NPC was when the function started, normally the room it was loaded into. Moved away, it doesn't block until it is back.

guard_dir

The NPC stops characters from leaving in one direction, except those you name.

dilbegin fnpri(FN_PRI_MISSION) guard_dir(direction : string,
                   excludepc : stringlist,
                   excludenpc : stringlist,
                   stopdil : string);
Argument Type Meaning
direction string The direction to block: "north", "south"... "up", "down", "northeast"...
excludepc stringlist The players allowed through, by name, or null.
excludenpc stringlist The NPCs allowed through, by name, or null.
stopdil string "" for the normal messages ("<guard> stops you from going south!"). Otherwise the name of a DIL procedure that takes the blocked character and the direction, (u : unitptr, dir : string), and is called instead; this needs DIL of your own.
dilcopy guard_dir@function("south", {"papi", "whistler"}, {"guard", "captain"}, "");
dilcopy guard_dir@function("east", {"rejji"}, null, "");
guard_door

The NPC stops everyone from opening, closing, locking, unlocking or picking the door in one direction, or casting a spell at it.

dilbegin fnpri(FN_PRI_MISSION) guard_door(dir:integer,as:string,ao:string);

dir is a direction constant: NORTH, EAST, SOUTH, WEST, UP, DOWN... as is the message to the character who tried, ao the message to the others; $1n is the guard, $3n the character.

dilcopy guard_door@function(WEST, "$1n stops you.",
                            "$1n prevents $3n from opening the grating.");
guard_unit

The same for an object in the room, such as a chest or a safe: nobody may open, close, lock, unlock or pick it, or cast at it. The first argument is the object's full symbolic name, symbol@zone.

dilbegin fnpri(FN_PRI_MISSION) guard_unit(us:string,as:string,ao:string);
dilcopy guard_unit@function("safe@midgaard", "$1n stops you.",
                            "$1n prevents $3n from opening the safe.");

Cleaning up

fido

The NPC eats NPC corpses and food that lie in its room, every 10 to 30 seconds. When it eats a corpse, what the corpse held drops to the floor. It doesn't eat player corpses or buried things.

dilbegin fido(txt1:string,txt2:string);
Argument Type Meaning
txt1 string The message when it eats a corpse. "" gives "<npc> savagely devours a corpse.", "stop" means it doesn't eat corpses.
txt2 string The message when it eats food. "" gives "<npc> hungrily devours <food>.", "stop" means it doesn't eat food.

In the messages $1n is the NPC and $2n what it eats.

dilcopy fido@function("$1n slowly devours $2n, crunching the bones.",
                      "$1n grabs $2n and hungrily munches it.");
janitors

This one is in midgaard.zon, so it is janitors@midgaard. The NPC tidies its room: it picks up things it can carry and puts them in a trash bag (which it gets when the function starts), buries NPC corpses after taking what is in them, tells a player where their corpse lies, gives away food and drink, and throws out slime. It leaves containers alone, and does nothing in rooms where burying isn't allowed (UNIT_FL_NO_BURY). If it loses its trash bag, it stops wandering and sings a song instead.

dilbegin fnpri(FN_PRI_MISSION) janitors(rate: integer);

rate is the number of seconds between two rounds of tidying. The janitor doesn't move by itself; give it wander_zones or global_wander too.

dilcopy janitors@midgaard(15);
dilcopy wander_zones@function("@loadzone", 20, 1, 0);

Shops and services

shopkeepernew

The NPC runs a shop. Players can list what it sells, buy, sell, value (what it would pay) and request (what it asks); see Help: Shops. It restocks once a mud day, and buys from players only while it has money left for the day.

dilbegin aware shopkeepernew(prod       : stringlist,
                             custom_acts : stringlist,
                             itemtypes  : intlist,
                             sellprofit : integer,    buyprofit   : integer,
                             maxcash    : integer, shophome : integer);
Argument Type Meaning
prod stringlist What it sells. Each entry is "symbol@zone daily max": the object, how many come into stock each mud day, and the most it keeps. Both numbers must be more than 0.
custom_acts stringlist Its messages, in the order below. An empty or missing message gets the default.
itemtypes intlist The kinds of object it buys from players, as ITEM_ constants (from vme/include/vme.h), for example {ITEM_FOOD, ITEM_DRINKCON}.
sellprofit integer Its selling price, as a percentage of the object's cost: 110 means 10% more than the cost.
buyprofit integer What it pays players, as a percentage of the cost: 50 means half.
maxcash integer The money it has each mud day to buy things from players, in money units (an iron piece is 10; 2*PLATINUM_MULT is two platinum pieces).
shophome integer TRUE: it serves only in the room where it was loaded, and walks back there if moved. FALSE: a wandering trader.

The messages, in order. $1n is the shopkeeper, $2n the object and $3n the player.

  1. The player asks for something it doesn't have.
  2. The player tries to sell or value something they don't have.
  3. The player tries to sell something of a kind it doesn't buy.
  4. The player can't afford it.
  5. After a purchase. (Not shown at present: it says "That cost you ..." instead.)
  6. After a sale. (Not shown at present: it says "I paid you ..." instead.)
  7. It hasn't got as many as the player asked for.
  8. The object can't be sold (it has an extra named $no-sell).
  9. It has no money left to buy with.

shopkeepernew has no opening hours. For those, add opening_hours (below).

Here is Hogan, a bartender. The lists are made into macros with #define, at the top of the zone file, to keep the NPC readable; a \ at the end of a line continues the macro on the next line.

#define TAVERN_PROD {"tuborg@udgaard 5 20", "beer_bottle@midgaard 10 30"}

#define TAVERN_MSG \
{"$1n says, 'This is a tavern, I don't sell such an item as that!'", \
 "$1n says, '$3n, you don't even have that!'", \
 "$1n says, 'I don't trade in things such as $2n! Just buy a beer!'", \
 "$1n says, '$3n, you can't afford $2n.'", \
 "$1n says, 'Here you are.'", \
 "$1n says, 'Thank you, $3n.'", \
 "$1n says, 'I don't have that many $2Ns in stock.'", \
 "$1n says, 'I haven't got a use for $2n.'", \
 "$1n says, 'I'd like to buy it, but I can't afford it, sorry.'"}

#define TAVERN_TYPES {ITEM_DRINKCON, ITEM_FOOD}

%mobiles

bartender
names {"Hogan", "goblin", "bartender"}
title "Hogan"
descr "Hogan stands behind the bar, waiting to take your order."
extra {}
"He looks back at you, patiently waiting for your order."
M_SHOP_KEEPER(30, SEX_MALE, RACE_GOBLIN)
money 2 SILVER_PIECE, 2 COPPER_PIECE

dilcopy opening_hours@function({8, 23}, {"list", "buy", "sell", "value", "request"},
   "say Sorry, we're closed.",
   {"stand", "say The bar is open!"},
   {"say The bar is closed, come back at eight.", "rest"});

dilcopy shopkeepernew@function(TAVERN_PROD, TAVERN_MSG, TAVERN_TYPES,
                               110, 50, 2*PLATINUM_MULT, TRUE);
end

Hogan sells Tuborgs from Udgaard and bottles of beer from Midgaard at 110% of their cost, buys drinks and food from players at half their cost, and has two platinum pieces a day for that.

opening_hours

Closes a shop (or anything else) outside its opening hours: it blocks the commands you list, and the NPC does what you give it when it opens and closes.

dilbegin fnpri(FN_PRI_BLOCK-1) opening_hours(shophours  : intlist,
                                             blockcmds  : stringlist,
                                             blockexec  : string,
                                             opencmds   : stringlist,
                                             closecmds  : stringlist);
Argument Type Meaning
shophours intlist Pairs of mud hours, open from the first to the second, both included: {8, 23}, or {4, 10, 12, 20} for two periods. A period can't cross midnight: write {22, 23, 0, 6}, not {22, 6}.
blockcmds stringlist The commands it refuses while closed.
blockexec string The command the NPC does when it refuses one, for example "say We're closed.".
opencmds stringlist Commands the NPC does when it opens.
closecmds stringlist Commands the NPC does when it closes.

See Hogan above for an example.

shopkeeper

The older form of the shop, still used by many shops in the public zones. It passes its arguments on to shopkeepernew; new shops should use shopkeepernew directly.

dilbegin aware shopkeeper(prod       : stringlist, custom_acts : stringlist,
                          opentimes  : stringlist, itemtype    : string,
                          sellprofit : integer,    buyprofit   : integer,
                          maxcash    : integer,
                          closedil   : string,     dilparams   : string );

The differences: custom_acts has ten messages, with "the shop is closed" as the eighth; itemtype is a string of numbers, such as "17 19"; and opentimes, closedil and dilparams are ignored, so the shop is always open unless you add opening_hours. The shopkeeper always stays in its shop. At present, from the seventh message on, the messages come out in the wrong places; another reason to use shopkeepernew.

evaluate

For a fee, the NPC tells a player about a weapon, armour or shield they carry: the kind of weapon, armour or shield, and how good its craftsmanship is. The player types evaluate <item>.

dilbegin aware evaluate (amt: integer);

amt is the fee in iron pieces; 64 is one silver piece.

dilcopy evaluate@function(64);
mercenary_hire

The NPC can be hired to kill a player. offer <player> tells you the price, contract <player> pays it. The mercenary then sneaks to the victim, fights until the victim is dead, takes the loot and goes back home. It refuses players of level 20 or below and gods; only gods can hire it against an NPC. The price is 20 platinum pieces plus a little per level of the victim.

dilbegin mercenary_hire();
dilcopy mercenary_hire@function();

Pets and followers

obey

The NPC obeys the character it follows. When that character types tell <npc> <command> in the same room, the NPC does the command, for example tell familiar cast heal papi. Others are ignored.

dilbegin obey();
dilcopy obey@function();
obey_animal

obey for animals: the animal obeys only simple commands (moving, kill, get, drop, give, follow, flee, look, sit, sleep... but no spells or talking). Don't add obey as well; obey_animal adds it itself.

dilcopy obey_animal@function();

Teachers

Teachers themselves are made with special SFUN_TEACH_INIT, described in A more complex set of NPCs. These functions limit who may practise with them.

teach_q_block

Only players who have done a quest may practice. Others are refused, and the NPC does the command s.

dilbegin fnpri(FN_PRI_BLOCK) teach_q_block(q : string, s : string);

q is the quest as the player has it, for a finished quest usually "<name> Complete".

dilcopy teach_q_block@function("Mary's Pot Complete", "say Buggar ye off!");

shop_q_block@function takes the same arguments and does the same for buy and sell at a shop.

TrainMemberChk

In guilds.zon: only members of the guild may practice. The second argument is the command the NPC does when it refuses a player, or "" for "say You're not a member of our guild, go speak with the guild master."

dilbegin fnpri(FN_PRI_BLOCK+1) TrainMemberChk(sGuild : string, sMsg : string);
dilcopy TrainMemberChk@guilds(GUILD_UDG_FIGHTER, "");

The guild masters' functions (MasterJoin, SetTitles, MurderBanish) are also in A more complex set of NPCs.

More

function.zon holds more than this page shows: restrictions for objects (abi_restrict, guild_restrict, ...), functions for rooms (death_room, force_move, safe_room, climb), ships and others. The comments above each dilbegin explain them. The quest helpers for NPCs are in quests.zon.

Previous: Compiling and debugging your first NPC
Next: A more complex set of NPCs