Difference between revisions of "Manual:Zone Manual/The NPC Section/DIL functions for NPCs"
(checked against the current code (wiki review 2026-11-15)) |
|||
| Line 1: | Line 1: | ||
=== DIL functions for NPCs === | === 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 [[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. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| + | 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()]]. | ||
| − | + | 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 <symbol>@<zone> func</code> lists the DIL programs an NPC runs. | |
| − | + | ||
| − | + | 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]]. | |
| − | + | ||
| − | + | ==== 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. | |
| − | + | <pre> | |
| − | + | dilbegin aggressive (sx : integer, rce : integer, opp : integer, | |
| − | + | levl : integer, sanc : integer, tme : integer, | |
| − | + | tar : integer, align : string, attack : stringlist); | |
| − | + | </pre> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | ; | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | : | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
{| class="wikitable" | {| class="wikitable" | ||
| − | | | + | ! 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. | ||
|- | |- | ||
| − | + | | rce || integer || A player race, <code>RACE_HUMAN</code> (0) to <code>RACE_DARK_ELF</code> (10), or -1 for any race. | |
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | opp || integer || What to do with <code>rce</code>: 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. |
| − | |integer | ||
| − | | | ||
|- | |- | ||
| − | | | + | | 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 | + | |- |
| − | | | + | | 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: <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. | ||
|} | |} | ||
| − | + | If an argument is out of range the function logs "AGGRO ERROR" in <code>vme.log</code> 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: | |
| − | + | <pre> | |
| − | + | 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!"}); | |
| − | + | </pre> | |
| − | + | A monster that attacks anyone, after about 20 seconds, with one message for all: | |
| − | + | <pre> | |
| − | + | dilcopy aggressive@function(0, -1, 0, 0, 3, PULSE_SEC*20, 0, "ANY", | |
| − | + | {"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" | ||
| − | + | ! Argument !! Type !! Meaning | |
|- | |- | ||
| − | + | | 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. | |
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | def_spl || string || The defence spell, for example <code>"heal"</code>, or <code>""</code> for none. |
| − | |string | ||
| − | |The | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | 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 <code>vme/etc/spells.def</code>. | |
| + | <pre> | ||
| + | dilcopy combat_mag@function("harm", "heal", 25, 2); | ||
| + | </pre> | ||
| − | + | ===== comb_poison and comb_acid ===== | |
| − | + | 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. | |
| − | + | <pre> | |
| − | + | dilbegin aware comb_poison(toact : string, restact : string); | |
| − | + | dilbegin aware comb_acid(toact : string, restact : string); | |
| − | ; | + | </pre> |
| − | : | + | <pre> |
| − | + | dilcopy comb_poison@function("You feel very ill as $1n bites you!", | |
| − | + | "$1n sinks $1s fangs deep into $3n!"); | |
| − | + | </pre> | |
| − | + | ||
| − | + | ===== teamwork ===== | |
| − | + | 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" | ||
| − | + | ! Argument !! Type !! Meaning | |
|- | |- | ||
| − | + | | zones || string || Zone names separated by spaces. <code>@loadzone</code> 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. |
| − | |integer | ||
| − | | | ||
| − | |||
|- | |- | ||
| − | | | + | | lckd_doors || integer || 1: it also goes through locked doors, without a key, and locks them again behind it. 0: it doesn't. |
| − | |integer | ||
| − | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
|} | |} | ||
| − | + | <pre> | |
| − | + | dilcopy wander_zones@function("haon_dor @loadzone", 30, 1, 0); | |
| − | + | </pre> | |
| − | + | An NPC with an extra named <code>$block wander</code> stops wandering. | |
| − | < | + | |
| − | + | ===== global_wander ===== | |
| − | + | Like <code>wander_zones</code>, but the NPC may wander into any zone. | |
| − | + | <pre> | |
| − | + | dilbegin global_wander(spd : integer, doors : integer, lckd_doors : integer); | |
| − | + | </pre> | |
| − | + | The arguments are those of <code>wander_zones</code> without <code>zones</code>; a speed below 2 counts as 5 seconds. | |
| − | + | <pre> | |
| − | + | dilcopy global_wander@function(60, 1, 0); | |
| − | + | </pre> | |
| − | + | ||
| + | ==== 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" | ||
| − | + | ! Argument !! Type !! Meaning | |
| − | ! Argument | ||
| − | ! Type | ||
| − | ! | ||
|- | |- | ||
| − | | | + | | direction || string || The direction to block: <code>"north"</code>, <code>"south"</code>... <code>"up"</code>, <code>"down"</code>, <code>"northeast"</code>... |
| − | | | ||
| − | |The | ||
|- | |- | ||
| − | | | + | | excludepc || stringlist || The players allowed through, by name, or <code>null</code>. |
| − | | | ||
| − | | | ||
|- | |- | ||
| − | | | + | | excludenpc || stringlist || The NPCs allowed through, by name, or <code>null</code>. |
| − | | | + | |- |
| − | | | + | | stopdil || string || <code>""</code> 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, <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> | ||
| − | + | ===== 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, <code>symbol@zone</code>. | |
| − | + | <pre> | |
| − | + | dilbegin fnpri(FN_PRI_MISSION) guard_unit(us:string,as:string,ao:string); | |
| − | + | </pre> | |
| − | + | <pre> | |
| − | + | dilcopy guard_unit@function("safe@midgaard", "$1n stops you.", | |
| − | + | "$1n prevents $3n from opening the safe."); | |
| − | + | </pre> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | ==== 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. | |
| − | + | <pre> | |
| − | + | dilbegin fido(txt1:string,txt2:string); | |
| − | + | </pre> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
{| class="wikitable" | {| class="wikitable" | ||
| − | + | ! Argument !! Type !! Meaning | |
|- | |- | ||
| − | + | | txt1 || string || The message when it eats a corpse. <code>""</code> gives "<npc> savagely devours a corpse.", <code>"stop"</code> means it doesn't eat corpses. | |
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | txt2 || string || The message when it eats food. <code>""</code> gives "<npc> hungrily devours <food>.", <code>"stop"</code> means it doesn't eat food. |
| − | | | + | |} |
| − | + | In the messages <code>$1n</code> is the NPC and <code>$2n</code> what it eats. | |
| − | + | <pre> | |
| − | + | dilcopy fido@function("$1n slowly devours $2n, crunching the bones.", | |
| − | + | "$1n grabs $2n and hungrily munches it."); | |
| − | + | </pre> | |
| − | + | ||
| − | + | ===== janitors ===== | |
| − | + | 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. | |
| − | + | <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 | ||
|- | |- | ||
| − | | | + | | 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. |
| − | | | ||
| − | | | ||
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | 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 <code>ITEM_</code> constants (from <code>vme/include/vme.h</code>), for example <code>{ITEM_FOOD, ITEM_DRINKCON}</code>. |
| − | | | ||
| − | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | sellprofit || integer || Its selling price, as a percentage of the object's <code>cost</code>: 110 means 10% more than the cost. |
| − | |integer | ||
| − | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | buyprofit || integer || What it pays players, as a percentage of the cost: 50 means half. |
| − | |integer | ||
| − | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | 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 | ||
| − | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | 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. |
| − | | | ||
| − | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | | | ||
| − | | | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
|} | |} | ||
| − | The | + | The messages, in order. <code>$1n</code> is the shopkeeper, <code>$2n</code> the object and <code>$3n</code> the player. |
| − | + | # The player asks for something it doesn't have. | |
| − | + | # The player tries to sell or value something they don't have. | |
| − | + | # 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. | ||
| − | + | <code>shopkeepernew</code> has no opening hours. For those, add <code>opening_hours</code> (below). | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | 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. | |
| − | + | <pre> | |
| − | + | #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 | |
| − | + | </pre> | |
| − | + | 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. | |
| − | + | <pre> | |
| − | + | dilbegin fnpri(FN_PRI_BLOCK-1) opening_hours(shophours : intlist, | |
| − | + | blockcmds : stringlist, | |
| − | + | blockexec : string, | |
| − | + | opencmds : stringlist, | |
| − | + | closecmds : stringlist); | |
| − | + | </pre> | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
{| class="wikitable" | {| class="wikitable" | ||
| − | + | ! Argument !! Type !! Meaning | |
|- | |- | ||
| − | + | | 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>. | |
| − | |||
| − | |||
| − | |||
|- | |- | ||
| − | | | + | | blockcmds || stringlist || The commands it refuses while closed. |
| − | | | ||
| − | | | ||
| − | | | ||
|- | |- | ||
| − | | | + | | blockexec || string || The command the NPC does when it refuses one, for example <code>"say We're closed."</code>. |
| − | | | ||
| − | | | ||
| − | | | ||
|- | |- | ||
| − | | | + | | 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 <code>shopkeepernew</code>; new shops should use <code>shopkeepernew</code> directly. | |
| − | + | <pre> | |
| − | + | dilbegin aware shopkeeper(prod : stringlist, custom_acts : stringlist, | |
| − | + | opentimes : stringlist, itemtype : string, | |
| − | + | sellprofit : integer, buyprofit : integer, | |
| − | + | maxcash : integer, | |
| − | + | closedil : string, dilparams : string ); | |
| − | + | </pre> | |
| − | + | 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>. | |
| − | + | ||
| − | + | ===== 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 <code>evaluate <item></code>. | |
| − | ; | + | <pre> |
| − | + | dilbegin aware evaluate (amt: integer); | |
| − | + | </pre> | |
| − | + | <code>amt</code> is the fee in iron pieces; 64 is one silver piece. | |
| − | + | <pre> | |
| − | + | dilcopy evaluate@function(64); | |
| − | + | </pre> | |
| − | + | ||
| − | + | ===== mercenary_hire ===== | |
| − | + | The NPC can be hired to kill a player. <code>offer <player></code> tells you the price, <code>contract <player></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. | |
| − | + | <pre> | |
| − | + | dilbegin mercenary_hire(); | |
| − | + | </pre> | |
| − | + | <pre> | |
| − | + | dilcopy mercenary_hire@function(); | |
| − | + | </pre> | |
| − | + | ||
| − | + | ==== Pets and followers ==== | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | ; | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | ===== obey ===== | |
| − | + | The NPC obeys the character it follows. When that character types <code>tell <npc> <command></code> in the same room, the NPC does the command, for example <code>tell familiar cast heal papi</code>. Others are ignored. | |
| − | + | <pre> | |
| + | dilbegin obey(); | ||
| + | </pre> | ||
| + | <pre> | ||
| + | dilcopy obey@function(); | ||
| + | </pre> | ||
| − | + | ===== obey_animal ===== | |
| − | + | <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. | |
| − | + | <pre> | |
| − | + | dilcopy obey_animal@function(); | |
| + | </pre> | ||
| − | + | ==== Teachers ==== | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | 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. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | ===== teach_q_block ===== | |
| − | + | Only players who have done a quest may <code>practice</code>. Others are refused, and the NPC does the command <code>s</code>. | |
| − | + | <pre> | |
| − | + | dilbegin fnpri(FN_PRI_BLOCK) teach_q_block(q : string, s : string); | |
| − | + | </pre> | |
| + | <code>q</code> is the quest as the player has it, for a finished quest usually "<name> 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. | ||
| − | + | ===== 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]]. | ||
| − | + | ==== More ==== | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | + | <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>. | |
| − | |||
| − | |||
| − | |||
| − | <div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual: | + | <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: | + | <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
Contents
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 invme/zone/function.zon; a few in other zones, such asguilds.zonandmidgaard.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 examplePULSE_SEC*10orRACE_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 itsdilbeginline, and the comment above it, in the zone file on GitHub. - Times are often in ticks: 4 ticks are one second.
PULSE_SEC(4) andWAIT_SEC(4) are macros for it. - In messages,
$1n,$2nand$3nare 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.
- The player asks for something it doesn't have.
- The player tries to sell or value something they don't have.
- 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
$no-sell). - 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.