Manual:DIL Manual (Full Listing)
A DIL program is written in a zone file, compiled with the zone by vmc, and run by the game server on a unit: a room, an object, an NPC or a player. This page goes through a whole program from nothing: where it is written, its parts, how it gets onto a unit, how it runs and waits, and how to compile it. A complete example is at the end.
Templates
A program is written once, as a template, between dilbegin and dilend. Each unit that runs it gets its own copy: the copy has its own variables and its own place in the code, while the code itself is shared. Ten guards with the same template are ten programs that know nothing of each other's variables.
A template's full name is name@zone: its name (at most 15 characters) and the zone it is written in. Templates are also called by other templates, as procedures or as functions (see Functions).
Where DIL is written
- The
%dilsection of a zone, after%zoneand before%rooms, holds the zone's templates. Any unit of any zone can use them by their full name. - Inside a unit's definition: a
dilbegin ... dilendwritten among a room's, object's or mobile's fields is a template of the zone too, and that unit gets a copy every time it is loaded. Such a template takes no arguments. dilcopy name@zone(arguments);in a unit's definition gives every unit loaded from that definition a copy of the template. The arguments are constants: numbers, strings, and lists in braces ({"a", "b"},{1, 2}). A unit can have severaldilcopylines. The%resetsection has nodilcopyof its own: the program comes with the definition of the unit the reset loads.- At run time, dilcopy() puts a copy on any unit:
dilcopy("name@zone(arg1,arg2)", u);, with string and integer arguments only. - As a player command: a template named with
func = name@zoneinvme/etc/commands.defruns when the command is typed. It takes one string argument, the rest of the line, andselfis the character who typed it. Spells are templates named the same way invme/etc/spells.def.
The zone must start with #include <macros.h>: dilend, pause and on_activation are macros from it, and vmc needs the ^ that dilend adds to find the end of each program.
The parts of a template
dilbegin [options] [type] name(arg : type, ...);
external
other templates it calls
var
its variables
code
{
statements
}
dilend
- The header names the template and its arguments. The options are aware, recall, unique and fnpri. A type before the name makes the template a function that returns a value of that type. See dilbegin.
- external declares the templates this one calls, also those in the same zone.
- var declares the variables, each with one of the eight data types. They start empty: 0, "", an empty list or null.
- code holds the statements in one pair of braces. Labels for goto are written
:name:.
Every function, field and built-in variable of DIL is a reserved word, so name, target, level, key and many more can't be variable names. vmc then reports a syntax error with that word as the token.
How a program runs
A copy starts at the first statement of code soon after its unit is loaded (or, for dilcopy(), at the unit's next tick). It runs until it waits, and waits most of its life:
- wait(events, condition) stops the program until an event of one of the given kinds comes for which the condition is true. The events are the
SFB_values: a command typed nearby (SFB_CMD), a command done (SFB_DONE), a message from another program (SFB_MSG), the program's timer (SFB_TICK), and others; see Messages. pause;waits for the program's next tick. The tick comes every heartbeat, which the program sets:heartbeat := PULSE_SEC * 30;is every 30 seconds.- interrupt() and on_activation() make the program react to some events whatever it is waiting for.
When an event wakes the program, the built-in variables activator, argument, medium, target and power describe it, and command(...) tells which command it was. self is always the program's own unit.
Two rules make DIL different from most languages:
- At every wake, every
unitptrandextraptrvariable becomes null, unless the unit was kept with secure(). The unit may have left or been destroyed while the program slept. Copy what you need right after thewait, and find units again after apause. Integers, strings and lists keep their values. - A program can't run forever without waiting. After about 52,000 statements without a wait (about 17,000 rounds of a one-line
whileloop) the server stops it and writes "had endless loop" to the zone's log.
The usual shape is a loop: a label, a wait, the work, and goto back to the label. A program ends for good with quit, or when its unit is destroyed. One that runs past the closing brace of code starts again from the top, with its variables as they were.
Programs on a player, and on the things a player carries, are saved with the player. Their integer, string and list variables are saved too; with recall the program also goes on from where it waited, instead of starting again.
Compiling
Zone files are in vme/zone/. Compile a zone with vmc, the zone compiler:
cd vme/zone ../bin/vmc -m -d ../etc/ -I../include/ myzone.zon
-m compiles only zones that have changed; -s checks the syntax without writing any files. vmc writes myzone.data and myzone.reset, which the server reads, and myzone.dh, a list of the zone's templates ready to copy into another template's external section. An error is reported with the line number and the token where vmc stopped:
30: syntax error
Token: 'name'
A new zone is listed in vme/etc/zonelist. The server reads zones only when it starts, so restart it after compiling. Errors while a program runs, such as a template that isn't found, a type error or an endless loop, are written to the zone's log in vme/bin/vme.log.
A complete example
#include <macros.h>
%zone mytown
lifespan 20
reset RESET_ANYHOW
creators {"manual"}
%dil
dilbegin town_crier(news : stringlist);
var
i : integer;
code
{
heartbeat := PULSE_SEC * 60;
:start:
wait(SFB_TICK | SFB_CMD, command(CMD_AUTO_TICK) or
(command("say") and (activator.type == UNIT_ST_PC)
and ("news" in argument)));
if (length(news) == 0)
quit;
if (i >= length(news))
i := 0;
exec("say Hear ye! " + news.[i], self);
i := i + 1;
goto start;
}
dilend
%rooms
square
title "The Town Square"
descr "Cobbled streets meet here around an old well."
dilbegin no_sleep();
code
{
:start:
wait(SFB_CMD, command("sleep") and (activator.type == UNIT_ST_PC));
act("Not in the middle of the square, please.",
A_ALWAYS, activator, null, null, TO_CHAR);
block;
goto start;
}
dilend
end
%mobiles
crier
names {"town crier", "crier"}
title "the town crier"
descr "The town crier stands by the well with a big bell."
M_AVG_HUMAN(5, SEX_MALE)
dilcopy town_crier@mytown({"The bridge is mended.", "Taxes are due on Friday."});
end
%reset
load crier into square max 1
%end
town_crieris a template in%dilthat takes a list of news. The crier's definition copies it onto every crier with two pieces of news. Every minute, and whenever a player says something with "news" in it, the crier says the next piece. The wait wakes for two kinds of event (SFB_TICK | SFB_CMD), and the condition lets ticks through withcommand(CMD_AUTO_TICK)and commands only when a player says "news". The crier doesn't hear its ownsay: a program isn't woken by its own unit's commands unless it is aware.no_sleepis written inside the room, so the room runs it. It wakes before a player'ssleepcommand runs, answers, and blocks the command so that it never happens.- The reset loads one crier into the square.
To try it, save it as vme/zone/mytown.zon, compile it, add mytown to vme/etc/zonelist and restart the server; a god can then goto square@mytown. Started as vme -w, the server lets the ticks pass without waiting (see Ending Notes).
See also
DIL has eight types. Every variable, argument, field and expression has one of them, fixed when vmc compiles the program, and vmc refuses a value of the wrong type ("Assigning incompatible types"). There are no other types: no floating-point numbers, no records, no arrays besides the two list types.
The eight types
| Type | Holds | Written as | Empty value |
|---|---|---|---|
| integer | A whole number, signed, 32 bits. Also DIL's truth values: 0 is false, anything else true. | 42, 0x2A, -5, constants such as TRUE or PULSE_SEC |
0 |
| string | A piece of text. | "Hello there" |
"" (or null)
|
| stringlist | An ordered list of strings: names, keywords, words. | {"red", "green"} |
an empty list |
| intlist | An ordered list of integers. | {10, -3, 0x10} |
an empty list |
| unitptr | A room, an object, an NPC or a player. | self, findroom("square@mytown") |
null |
| extraptr | One extra description of a unit (also used to store data on units). | "$visits" in u.extra |
null |
| zoneptr | A zone. | findzone("mytown"), zhead() |
null |
| cmdptr | One of the game's commands. | getcmd("look"), chead() |
null |
Variables are declared in var (n, m : integer;) or as a template's arguments, and start with the empty value. A list in braces may hold only constants; build a list from variables with addstring() or insert(). Each type's page tells how to work with it; the Fields page lists what units, extras, zones and commands hold.
Values and copies
- Integers, strings and lists are values. Assigning one variable to another, or passing it to a template, copies it: changing the copy doesn't change the original.
- unitptr, extraptr, zoneptr and cmdptr point to something that exists in the game. A copy points to the same thing, so
u.hp := 10;changes the unit whichever variable it is reached through. nullis the empty value of the pointer types, and assigning it empties strings and lists too. An integer can't be null. See null.- A global stringlist or intlist is shared by every program that declares the same key.
What a variable keeps
A program sleeps between events. What its variables hold when it wakes, and when its unit is saved and loaded again (a player and what the player carries), depends on the type:
| Type | After a wait (wait, pause, a heartbeat) |
When the unit is saved and loaded |
|---|---|---|
| integer, string, stringlist, intlist | kept | saved with the unit |
| unitptr | null, unless the unit is secured | null |
| extraptr | null (it can't be secured) | null |
| zoneptr, cmdptr | kept | null |
So keep names, numbers and texts in variables of the first kind, and find units and extras again after waiting. Saved values are thrown away when the template's variables have changed since the save. See var.
Truth values
Conditions (if, while, wait, and, or, not) take a value of any type:
- an integer is true when it isn't 0;
- a unitptr, extraptr, zoneptr, cmdptr or string is true when it isn't null. A string that holds
""after an assignment is true, so test text withs != ""; - a stringlist or intlist is true when it has at least one entry;
- a failed value (below) is false.
Failed values
Some expressions give no value at all: a field of null (u.level when u is null), a field the unit doesn't have, a division by 0, a list index outside the list, and most functions given a failed argument. Such a value fails: it is false in every comparison and condition, and assigning it leaves an integer, list or pointer variable as it was and empties a string variable. See Expressions and Assignment.
Converting between types
DIL never converts by itself: "You have " + 5 and if (n == "5") don't compile. The functions that convert:
| From | To | How |
|---|---|---|
| integer | string | itoa(n): "You have " + itoa(n) + " coins."
|
| string | integer | atoi(s): the number at the start of the text, 0 when there is none |
| string | stringlist | getwords(s) (words) or split(s, sep) (pieces between separators) |
| stringlist | string | a loop over the entries, joining them with +; sl.[i] is one entry
|
| string | unitptr | findsymbolic("name@zone"), findroom("name@zone"), or findunit() for a name as players type it |
| unitptr | string | u.name; its symbolic name is u.nameidx + "@" + u.zoneidx (the macro SYMNAME(u) in wmacros.h)
|
| string | zoneptr | findzone(name); a unit's zone is findzone(u.zone)
|
| string | cmdptr | getcmd(word) |
| string | extraptr | "name" in u.extra, or u.extra.["name"]
|
An extra description is the usual place for data on a unit: its text (exd.descr) holds a string, its vals an intlist. A cast such as (integer) exists only for calling a template whose name is in a string (see Functions).
Comparing
== and != work between two values of the same type. On strings they ignore case. On units, extras, zones and commands they tell whether both are the same thing. On two lists they tell whether both are the same list, not whether they hold the same entries: two list variables are never equal, even with the same contents. Comparing a list with null tells whether it is empty. See Operators.
See also
string
Type. A piece of text.
var s : string;
Strings are written between double quotes: "Hello there". A string variable holds a copy of its text: assigning one string variable to another, or passing a string to a template, copies it. An unset string variable is the empty string "".
Operators
+joins strings:"You have " + itoa(n) + " coins.". Both sides must be strings; numbers go throughitoa().==and!=ignore case:"Sword" == "sword"is true. So do< > <= >=:"B" > "a"is true.strcmp()andstrncmp()compare exactly."key" in stells whether the first string occurs anywhere in the second, ignoring case (1 or 0).s.[i]is the character at positioni(from 0) as a one-letter string. It can be read but not assigned (s.[1] := "x"is "Illegal lvalue").
Notes
- A
"can't be written inside a string: vmc stops at\". Use single quotes in the text. - A
^inside a string ends the program early (see dilend). - Reading
s.[i]past the end fails and writes "index of stringlist out of bounds" to the zone log; checklength(s)first. - If any part of a
+fails (a field of a null unit, say), the whole result fails, and asendtext()or assignment with it does nothing. - Text sent to players is HTML: lines end with
<br/>. - String variables keep their value through waits and are saved with the unit.
Example
dilbegin do_shout2(arg : string);
var
s : string;
code
{
if (arg == "")
{
sendtext("Shout what?<br/>", self);
quit;
}
if ("password" in arg)
{
sendtext("Better not.<br/>", self);
quit;
}
s := toupper(arg.[0]) + right(arg, length(arg) - 1);
act("$1n bellows, '$2t!'", A_ALWAYS, self, s, null, TO_ALL);
quit;
}
dilend
A command that refuses some words, gives the text a capital letter and shows it to the room.
See also
- stringlist
- length()
- itoa()
- atoi()
- in
- left()
- right()
- mid()
- replace()
- getword()
- split()
- strcmp()
- Operators
stringlist
Type. An ordered list of strings.
var sl : stringlist;
Stringlists hold names, keywords and lists of words: a unit's names, an extra's names, the result of split() or getwords(). A list is written as strings in braces: {"red", "green", "blue"}.
A stringlist variable holds its own list. Assigning a list to it (sl := u.names;) copies the strings, and a template that gets a stringlist argument gets a copy as well.
Working with a stringlist
sl.[i]is the string at positioni, counting from 0. It can be assigned to:sl.[0] := "black";.length(sl)is the number of strings.s in slis the position plus one of the first entry that iss, or the first whole words ofs, ignoring case; 0 if there is none."ship arrived" in {"ship"}is 1, but"ship" in {"ship arrived"}and"arrived" in {"arrived_port"}are 0.addstring(sl, s)adds at the end,substring(sl, s)takes a string out,insert(sl, i, s)andremove(sl, i)work by position.sl.[i].[j]is a character of one of the strings.
Notes
{...}may hold only constants: strings and macros that become strings.{name}with a variable is a syntax error; build such a list withaddstring().sl := {};doesn't compile ("Assigning incompatible types (C)"). An empty{}only works as an argument in a zone file'sdilcopy. To empty a list, assignnull:sl := null;.- Reading
sl.[i]outside the list fails and writes "index of stringlist out of bounds" to the zone log; assigning outside it does nothing. - Stringlist variables keep their value through waits and are saved with the unit.
- A stringlist can be the argument of a template copied with
dilcopyin a zone file, but not of thedilcopy()procedure, which only passes strings and integers.
Example
dilbegin list_names(u : unitptr);
var
sl : stringlist;
i : integer;
s : string;
code
{
sl := u.names;
s := "";
while (i < length(sl))
{
s := s + "[" + sl.[i] + "] ";
i := i + 1;
}
sendtext(u.name + " answers to: " + s + "<br/>", self);
if ("dragon" in sl)
sendtext("Careful, that is a dragon.<br/>", self);
quit;
}
dilend
Shows a unit's names one by one, and warns if one of them is "dragon".
See also
integer
Type. A whole number, signed, 32 bits.
var n : integer;
Integers count, measure and flag things, and they are DIL's truth values too: a condition is true when it is not 0. TRUE (1) and FALSE (0) are defined in vme.h; a comparison gives 1 or 0.
Numbers are written in decimal (42) or hexadecimal (0x2A). A negative number is a minus sign in front of one (-5). Most constants in vme.h and values.h (UNIT_ST_PC, PULSE_SEC, SFB_CMD...) are integers.
Operators
- Arithmetic:
+ - * / %. Division cuts towards 0. - Bits:
&(and),|(or).isset(),set()andunset()do the same for flag fields. - Logic:
and,or,not. Both sides are always worked out. - Comparison:
== != < > <= >=.
Notes
- Comparisons bind more loosely than
andandor:if (a == 1 and b == 2)compiles, but means(a == (1 and b)) == 2. Put each comparison in brackets:if ((a == 1) and (b == 2)). - Dividing by 0 (
/or%) gives no number but a failed value. A failed value is false in every comparison, and assigning it changes nothing: the variable keeps its old value. - A field of a null unit fails the same way:
u.level > 5andu.level <= 5are both false whenuis null. - Many integer fields are stored in fewer bits (8 or 16); a value assigned to them that doesn't fit wraps around. Each field's page says.
- Integer variables keep their value through waits and are saved with the unit.
itoa()makes a string of an integer,atoi()an integer of a string;"a" + 5is a compile error.
Example
dilbegin integer percent(part : integer, whole : integer);
code
{
if (whole == 0)
return (0);
return ((part * 100) / whole);
}
dilend
dilbegin do_health(arg : string);
external
integer percent(part : integer, whole : integer);
var
pct : integer;
code
{
pct := percent(self.hp, self.max_hp);
if (pct < 25)
sendtext("You are badly hurt (" + itoa(pct) + "%).<br/>", self);
else
sendtext("You are at " + itoa(pct) + "% of your hit points.<br/>", self);
quit;
}
dilend
A function that works out a percentage without dividing by 0, and a command that uses it.
See also
integerlist
Type. Another name used on this wiki for intlist.
DIL has no keyword integerlist: a list of integers is declared with intlist.
var il : intlist;
See intlist.
See also
extraptr
Type. A pointer to an extra description.
var exd : extraptr;
Extra descriptions are the texts a unit shows when looked at (look at sign), and DIL also uses them to store data on units: quest flags, counters, settings. look doesn't show an extra whose first name starts with $, so such names hold data. Each extra has these fields:
| Field | Type | Meaning |
|---|---|---|
| names | stringlist | the names it is found by |
| name | string | the first of the names |
| descr | string | its text (read and write) |
| vals | intlist | numbers stored with it |
| next | extraptr | the next extra on the same unit |
u.extra is the first extra of a unit. To find one by name, use "name" in u.extra or u.extra.["name"]; both give null when there is none.
Notes
- An extraptr variable is cleared at every wait (
wait,pause, a heartbeat), and it can't be secured. Look the extra up again after waiting. - A field of a null extraptr fails; test
exd == nullfirst. addextra()andsubextra()add and remove extras. An extra made with empty text is not added.- Extras themselves are saved with the unit; extraptr variables are not (they come back null).
Example
dilbegin visit_count();
var
pc : unitptr;
exd : extraptr;
code
{
:start:
wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC)
and (activator.outside == self));
pc := activator;
exd := "$visits" in pc.extra;
if (exd == null)
{
addextra(pc.extra, {"$visits"}, "1");
sendtext("Welcome, stranger.<br/>", pc);
}
else
{
exd.descr := itoa(atoi(exd.descr) + 1);
sendtext("Welcome back, visit number " + exd.descr + ".<br/>", pc);
}
goto start;
}
dilend
On a room: counts each player's visits in a hidden extra on the player.
See also
cmdptr
Type. A pointer to one of the game's commands.
var cmd : cmdptr;
A cmdptr gives a program the facts about a command, as set in commands.def: its name, type, and who may use it. chead() is the first command, cmd.next the next one (null after the last), and getcmd(word) the command a word means when typed, abbreviations included.
Fields
| Field | Type | Meaning |
|---|---|---|
| name | string | the command's full name |
| type | integer | its type: TYPE_SOCIAL, TYPE_SKILL and the others in values.h
|
| level | integer | the lowest level that may use it |
| position | integer | the lowest position it can be used in (POSITION_...)
|
| loglevel | integer | from which level the use is logged; 0 for not at all |
| speed | integer | its speed in combat |
| next | cmdptr | the next command |
Each field's page has the details.
Notes
- Commands stay for as long as the server runs, so cmdptr variables keep their value through waits. They are not saved with a unit: after loading they are null.
- A field of a null cmdptr fails; test
cmd == nullfirst. - There is no
previousfield, and the function isgetcmd(), notgetcommand(), though older pages said so. cmd.professioncompiles but stops the program with a type error when it runs.
Example
dilbegin do_mycmds(arg : string);
var
cmd : cmdptr;
s : string;
code
{
cmd := chead();
while (cmd != null)
{
if ((cmd.level <= self.level) and (cmd.type != TYPE_SOCIAL)
and (cmd.type != TYPE_SKILL))
s := s + cmd.name + " ";
cmd := cmd.next;
}
pagestring("You can use: " + s + "<br/>", self);
quit;
}
dilend
A command that lists the commands the player's level allows, leaving out socials and skills; adapted from comm_dil in commands.zon.
See also
unitptr
Type. A pointer to a unit: a room, an object, an NPC or a player.
var u : unitptr;
Through a unitptr a program reads and changes a unit's fields (u.name, u.hp, u.outside...), and hands the unit to functions and procedures. u.type says which kind of unit it is: UNIT_ST_ROOM, UNIT_ST_OBJ, UNIT_ST_NPC or UNIT_ST_PC. Which fields a unit has depends on that type.
A unitptr is null or points to a unit. Built-in variables such as self, activator, medium and target are unitptrs, and so are the results of findunit(), findroom(), findsymbolic() and load().
Notes
- A unitptr variable is cleared at every wait. When the program wakes from
wait,pauseor a heartbeat, every unitptr variable is null again, unless that unit issecured. Find the unit again after waiting, or secure it.selfis always the program's own unit. - A field of a null unit fails, and a failed value is false in every comparison:
u.level > 5andu.level <= 5are both false whenuis null. Testu == null(ornot u) first, on its own:anddoesn't stop early. - A field on a call's result is a syntax error:
findroom(s).titledoesn't compile. Put the unit in a variable first. ==and!=tell whether two unitptrs point to the same unit.- Units in a room (or carried, or in a container) form a list:
u.insideis the first one,.nextthe next. When the loop moves or destroys units, useforeachinstead. - unitptr variables are not saved with a unit: after loading they are null.
Example
dilbegin do_count(arg : string);
var
u : unitptr;
pcs, others, things : integer;
code
{
u := self.outside.inside;
while (u != null)
{
if (u.type == UNIT_ST_PC)
pcs := pcs + 1;
else if (u.type == UNIT_ST_NPC)
others := others + 1;
else if (u.type == UNIT_ST_OBJ)
things := things + 1;
u := u.next;
}
sendtext("Here: " + itoa(pcs) + " players, " + itoa(others) + " others and "
+ itoa(things) + " things.<br/>", self);
quit;
}
dilend
A command that counts the players, NPCs and objects in the room (npcs and objs are reserved words, so the variables have other names).
See also
zoneptr
Type. A pointer to a zone.
var z : zoneptr;
A zoneptr gives a program the facts about a zone: its name, title, creators, reset settings and size. zhead() is the first zone in the game, z.next the next one (null after the last), and findzone(name) finds one by name.
Fields
| Field | Type | Meaning |
|---|---|---|
| name | string | the zone's name, as in %zone
|
| title | string | the zone's title |
| creators | stringlist | its creators |
| next | zoneptr | the next zone |
| rooms, objs, npcs | unitptr | a unit of the zone's first room, object or NPC definition (in name order), or null when that one has none in the game |
| roomcount, objcount, npccount | integer | how many rooms, objects and NPCs the zone defines |
| resetmode, resettime | integer | its reset settings |
| access, loadlevel, payonly | integer | its access level, the level needed to load its things, and its pay-only setting |
| bonusband | integer | its treasure band, 0-7, or -1 (BONUS_NOT_APPLICABLE) when it has none |
| fname, notes, help | string | its file name, notes and help text |
Each field's page has the details.
Notes
- Zones stay for as long as the server runs, so zoneptr variables keep their value through waits. They are not saved with a unit: after loading they are null.
- A field of a null zoneptr fails; test
z == nullfirst. ==and!=compare two zoneptrs, or one withnull.- There is no
previousfield, though older pages listed one. - A unit's
zonefield is the name of the zone it is in, a string:findzone(u.zone)gives the zoneptr.
Example
dilbegin zoneptr get_zone(s : string);
var
zn : zoneptr;
code
{
zn := zhead();
while (zn != null)
{
if (zn.name == s)
break;
zn := zn.next;
}
return (zn);
}
dilend
dilbegin do_zinfo(arg : string);
external
zoneptr get_zone(s : string);
var
z : zoneptr;
code
{
z := get_zone(arg);
if (z == null)
{
sendtext("No zone called '" + arg + "'.<br/>", self);
quit;
}
sendtext(z.name + ": " + z.title + ", " + itoa(z.roomcount) + " rooms.<br/>", self);
quit;
}
dilend
A function that walks the zone list (as get_zone in commands.zon), and a command that uses it.
See also
A DIL program sleeps until something happens near it: a command typed, a command done, a blow struck, a death, a message from another program, or its own timer. The server calls each of these an event (also message), and wakes the programs that wait for that kind.
The kinds of event
A program names the kinds it wants in wait() or interrupt(), with the SFB_ constants of vme/include/vme.h joined by |: wait(SFB_CMD | SFB_MSG, ...).
| Constant | When | Can be blocked |
|---|---|---|
| SFB_CMD | A character near the unit types a command, before it runs. Also moves, unknown words, and commands given with exec(). |
yes: the command doesn't run |
| SFB_DONE | A command has been carried out: something given, taken, dropped, a move, a spell cast, a room entered (CMD_AUTO_ENTER). |
no, it has happened |
| SFB_PRE | A spell is about to take effect, or damage is about to be dealt (CMD_AUTO_DAMAGE). power can be changed. |
yes: it doesn't happen |
| SFB_TICK | The program's own timer, every heartbeat. SFB_RANTIME added makes the time vary. |
no |
| SFB_MSG | Another program sent a message. | only from the programs after it |
| SFB_COM | A character near the unit makes a melee attack. | no |
| SFB_DEAD | A character near the unit dies (also the unit itself). | no |
SFB_EDIT |
A player closes the editor started with beginedit(). | |
SFB_PROMPT |
The player's prompt is being made. |
pause is wait(SFB_TICK | SFB_RANTIME, TRUE). SFB_SAVE and SFB_ACTIVATE work only in interrupt() (the second is what on_activation() uses).
What the program sees
When an event wakes a program, these built-in variables describe it:
| Variable | Holds |
|---|---|
| activator | the character who caused it: who typed the command, who attacked or died, which unit sent the message; null for a tick |
| argument | the rest of the command line, or the message's text |
| medium | what was used, for some commands and spells: the item given, the weapon, the scroll |
| target | who or what the command was done to |
| power | a number: the amount of money given, the damage about to be dealt, the strength of a spell |
| cmdstr, excmdstr, excmdstr_case | the command's name, the word as typed in lower case, and exactly as typed |
command("give") is true when the event comes from that command; automatic events have numbers, such as command(CMD_AUTO_ENTER), command(CMD_AUTO_TICK) or command(CMD_AUTO_DAMAGE). What each value holds for each event is on the event's page; for SFB_DONE it is set by the command, in its call to send_done().
These values belong to the event that woke the program, and the next wait replaces them. At the same wake every unitptr and extraptr variable that isn't secured becomes null. So the first statements after a wait copy what the program needs:
wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC));
pc := activator;
said := argument;
Who gets an event
- Commands, done, pre, combat and death events go to the units around the character who caused them: first the room's programs, then the things the character carries and wears, then the other units in the room (the characters, what they wear but not what they carry, and what is in open transparent units). A
targetsomewhere else gets it too. See SFB_CMD. - A tick goes only to the program whose timer it is.
- Messages go where the sender sends them (below).
- A program doesn't hear what its own unit does: when the activator is the program's own unit, the event passes it by. A program on a player doesn't see what the player types, and an NPC's program doesn't see the NPC's own
exec(). Declare the template aware (dilbegin aware name();) to get those events. A unit's own death, and messages sent to it withsendto(), arrive withoutaware.
Every event of a kind the program waits for wakes it, also one its condition then turns down, so a wide wait near a busy place runs often. Keep the condition short. While a program is running (it sent a message and the receivers haven't finished, say) it can't be woken, and events are not queued: what comes while a program waits for something else, or is busy, is lost to it.
The order of programs on a unit
A unit can run several programs. They get each event one after another, in the order of their fnpri, lowest number first (FN_PRI_BLOCK 25 before the default FN_PRI_CHORES 40); among equals the oldest first.
- block stops the event: the command doesn't run, or the spell or damage doesn't happen, and no program after this one, on this unit or on the units after it, gets the event. A program that should stop a command before another program acts on it needs the lower
fnpri. - priority keeps the programs after this one on the same unit from getting any event at all, until nopriority.
- on_activation(condition, skip) makes a program ignore every event while the condition holds; the other programs still get them.
Sending messages
Programs talk to each other with messages: a text that wakes the programs waiting for SFB_MSG, with the text in argument and the sending unit in activator.
| Procedure | Reaches |
|---|---|
| send(msg) | the programs around the sender's unit, as a command does; the sender's own other programs only when they are aware
|
| sendto(msg, u) | every program on the unit u, wherever it is, the sender's own unit included
|
| sendtoall(msg, "sym@zone") | the programs on every unit in the game made from that definition; medium is the sender too
|
| sendtoalldil(msg, "tmpl@zone") | every running copy of that template in the game; target is the receiver's own unit
|
- The receivers run at once, before the send returns. The sending program itself never gets its own message.
- A program that isn't waiting for
SFB_MSGat that moment misses it. To catch messages while waiting for something else, useinterrupt(SFB_MSG, condition, label). - After the send, the sender's secures are tested: a secured unit that a receiver moved away sends the sender to its label.
- Messages are plain text. Agree on the words, compare them with
==(which ignores case), or pack several values withitoa()and take them apart with getword().
Events can also be made: send_done() sends an SFB_DONE as a command does when it has succeeded, and send_pre() an SFB_PRE.
Example
dilbegin bell_rope();
code
{
:start:
wait(SFB_CMD, command("pull") and ("rope" in argument));
block;
act("You pull the rope, and far above a bell rings.",
A_ALWAYS, activator, null, null, TO_CHAR);
act("$1n pulls the rope, and far above a bell rings.",
A_ALWAYS, activator, null, null, TO_ROOM);
sendtoalldil("bell", "bell_ringer@mytown");
goto start;
}
dilend
dilbegin bell_ringer();
var
n : integer;
code
{
heartbeat := PULSE_SEC * 30;
:start:
wait(SFB_MSG | SFB_TICK, (command(CMD_AUTO_MSG) and (argument == "bell"))
or command(CMD_AUTO_TICK));
if (command(CMD_AUTO_TICK))
{
n := 0;
goto start;
}
n := n + 1;
if (n > 3)
goto start;
exec("say The bell! Someone is at the gate!", self);
goto start;
}
dilend
bell_rope sits in a room: it makes up the command "pull rope" (the game has no pull, so it must block, or the server answers that the command isn't known) and sends a message. Every NPC running bell_ringer, anywhere in the game, wakes with the message and answers, at most three times in a row; its own tick resets the count.
See also
SFB_CMD
Constant (integer, vme.h: 0x0004).
wait(SFB_CMD, condition)
The command event. A program waiting with SFB_CMD (in wait() or interrupt()) wakes whenever a player or a monster near it types a command, before the command runs. That includes commands the server doesn't know, commands the character isn't allowed to use, moving in a direction, and commands that DIL runs with exec(). Because the command hasn't happened yet, the program can stop it with block.
What the event holds
| Variable | Value |
|---|---|
| activator | the character who typed the command |
| argument | the rest of the line, without the spaces at either end ("all from corpse") |
| cmdstr | the full name of the command ("get") |
| excmdstr | the word as typed, in lower case ("ge") |
| excmdstr_case | the word exactly as typed ("Ge") |
| command("get") | TRUE |
| medium, target | null |
Notes
- Commands are matched by name:
command("north")is also true when the player typed "n". There are noCMD_NORTHorCMD_GETconstants; only the automatic events have numbers (CMD_AUTO_*in vme.h). - A word the server doesn't know comes as
CMD_AUTO_UNKNOWN, andcommand("tester")is true when the typed word is the start of "tester". Unless a program blocks it, the server then answers "... is not a known command.", so a program that makes up its own command mustblock. - The event reaches the character's room, the things the character carries and wears, everything else in the room (other characters, but of them only what they wear, and what is inside open transparent units), and the room around the room if this one is transparent.
- A program doesn't get the commands of the unit it runs on, unless it is declared
aware(dilbegin aware name();). A program on a player that watches what the player types needsaware. - The event comes before the level and position checks, so a program also sees commands the character can't use.
- When characters follow someone, each follower's step sends its own
SFB_CMDfor the direction, with an empty argument. - The programs on a unit get the event one after another, in
fnpriorder. Ablockstops the command and every program after this one; give a blocking program a low priority, such asFN_PRI_BLOCK. activatorand the other values belong to this event only. Unit variables that aren't secured become null at every wake, so copy what you need right after the wait.
Example
dilbegin fnpri(FN_PRI_BLOCK) guardnorth();
code
{
heartbeat := PULSE_SEC * 5;
:start:
wait(SFB_CMD, command("north") and (activator.type == UNIT_ST_PC));
if (activator.level >= IMMORTAL_LEVEL)
goto start;
act("$1n steps in front of you and shakes $1s head.",
A_SOMEONE, self, null, activator, TO_VICT);
block;
goto start;
}
dilend
A guard who stops mortal players from going north.
See also
SFB_DONE
Constant (integer, vme.h: 0x0800).
wait(SFB_DONE, condition)
The "it has happened" event. It is sent after a command has succeeded: an item was given, taken or dropped, a character moved, a spell was cast. A program waiting with SFB_DONE learns about it after the fact, so block can't undo anything; use SFB_CMD or SFB_PRE to stop a command.
What the event holds
activator, medium, target, power and argument are set by the command that sends it; command("name") tells which command it was. Some of them:
| Command | activator | medium | target | power |
|---|---|---|---|---|
| command("give") | the giver | the item, or the money | the one who got it | the amount, for money |
| command("get") | the taker | where it was taken from (null from the floor) | the item | 0 |
| command("drop") | the one dropping | null | the item | 0 |
| command("north") etc. | the one moving | the room being left | the room being entered | the direction |
| command(CMD_AUTO_ENTER) | the one moving | the unit that moved (the character, or what carried it) | the room that was left | the direction |
| command("cast") | the caster | the caster, or the scroll, wand or staff | the target | the spell number |
Notes
- give, get and drop are commands written in DIL (baseget.zon) that send the event with
send_done(); any DIL command can do the same. Check thesend_done()call in the command's source when you need to know what a command puts in each value. - The event reaches the activator's surroundings, as a command does (see SFB_CMD), and also
targetor the unit named insend_done()when it is somewhere else. - The direction event is sent while the mover is still in the old room;
CMD_AUTO_ENTERcomes after it has arrived, and is heard in the new room. - When a player enters the game (
CMD_AUTO_PLAY) or leaves it (CMD_AUTO_LEAVE), anSFB_DONEgoes to the roomvoid@basis. - A program doesn't get the events of its own unit unless it is declared
aware. - Given money is merged with the coins the receiver already has, so
mediummay be the whole pile;poweris the amount given.
Example
dilbegin thanks();
var
pc : unitptr;
code
{
:start:
wait(SFB_DONE, command("give") and (target == self));
pc := activator;
if (medium.type != UNIT_ST_OBJ)
goto start;
exec("say Thank you for " + medium.name + ", " + pc.name + ".", self);
goto start;
}
dilend
A monster that thanks whoever gives it something.
See also
SFB_TICK
Constant (integer, vme.h: 0x0008).
wait(SFB_TICK, condition)
The timer event. A program waiting with SFB_TICK wakes every time its own timer runs out; the timer is the program's heartbeat, counted in pulses of a quarter second (PULSE_SEC is 4 pulses). pause is wait(SFB_TICK | SFB_RANTIME, TRUE), defined in wmacros.h.
What the event holds
| Variable | Value |
|---|---|
| activator, medium, target | null |
| argument | empty |
| command(CMD_AUTO_TICK) | TRUE |
Notes
- Each program has its own timer; a tick goes only to the program it belongs to, not to the room.
- The shortest heartbeat is one second (
PULSE_SEC): a smaller value is raised to that when the program goes back to waiting. - With
SFB_RANTIMEadded, each wait lasts a random time between half and one and a half heartbeats. - A changed heartbeat starts a new timer when the program goes back to waiting. Otherwise an event of another kind doesn't reset the timer.
- When an earlier program on the same unit holds
priority, the tick is skipped. - Under a god's
wtimewarp(andvme -w) the ticks come as fast as the server can run them.
Example
dilbegin chime();
code
{
heartbeat := PULSE_SEC * 60;
:start:
wait(SFB_TICK, TRUE);
if (mudhour == 12)
act("The bell chimes noon.", A_ALWAYS, self, null, null, TO_ROOM);
goto start;
}
dilend
A bell (an object in a room) that looks at the mud clock once a minute and chimes at noon.
See also
SFB_COM
Constant (integer, vme.h: 0x0020).
wait(SFB_COM, condition)
The combat event. It is sent every time a character makes a melee attack, after the attack is rolled and before its damage is worked out (a fumble sends none). A program waiting with SFB_COM wakes for every attack made near it; its unit doesn't have to be in the fight.
What the event holds
| Variable | Value |
|---|---|
| activator | the character making the attack |
| argument | empty |
| command(CMD_AUTO_COMBAT) | TRUE |
| medium, target | null: the one attacked is activator.fighting
|
Notes
- The event reaches the same units as a command (see SFB_CMD): the attacker's room, what the attacker carries and wears, and the others in the room.
- A program doesn't get the attacks of its own unit unless it is declared
aware. A monster that wants to act on its own attacks needsaware; to act when it is attacked, checkself.fightingorself.position == POSITION_FIGHTING. - In a fight of several rounds the event comes often: keep the condition of the
wait()narrow. - To change the damage of a hit, use
SFB_PREwithcommand(CMD_AUTO_DAMAGE)instead.
Example
dilbegin nokill();
var
pc : unitptr;
room : unitptr;
code
{
heartbeat := PULSE_SEC * 3;
:start:
wait(SFB_COM, self.position == POSITION_FIGHTING);
pc := self.fighting;
room := self.outside.exit_to[SOUTH];
if ((pc == null) or (room == null))
goto start;
if (pc.level >= IMMORTAL_LEVEL)
goto start;
act("Black-covered shapes drag $1n out of the guild.",
A_SOMEONE, pc, null, null, TO_ROOM);
act("Black-covered shapes drag you out of the guild!",
A_SOMEONE, pc, null, null, TO_CHAR);
stop_fighting(pc, null);
link(pc, room);
goto start;
}
dilend
A guild master whose guards throw out anyone who fights him, after nokill in assassin.zon.
See also
SFB_DEAD
Constant (integer, vme.h: 0x0010).
wait(SFB_DEAD, condition)
The death event. It is sent when a player or a monster dies, at the start of its death: it still carries and wears all its things, and no corpse has been made yet.
What the event holds
| Variable | Value |
|---|---|
| activator | the character who is dying |
| argument | empty |
| command(CMD_AUTO_DEATH) | TRUE |
| medium, target | null |
Notes
- Unlike the other events, the dying character's own programs get it too, without
aware:wait(SFB_DEAD, activator == self)on a monster catches its own death. - It also reaches the room, what the dying character carries and wears, and the others in the room, as a command does (see SFB_CMD). A cursed item can catch its owner's death with
activator == self.outside. - It is sent by every real death: killed in combat, and killed by a god's
slay. The killer isn't in the event. The dying character'sfightingfield usually points to an opponent, but not necessarily the one who struck last; the example looks for everyone who fought it. - The death itself goes on after the program has run; it can't be blocked.
Example
dilbegin fnpri(FN_PRI_BLOCK-2) avenge();
var
u : unitptr;
code
{
:loop:
wait(SFB_DEAD, activator == self);
foreach (UNIT_ST_PC, u)
{
if ((u.fighting == self) and (u.outside == self.outside))
log(u.name + " killed " + self.name + ".");
}
goto loop;
}
dilend
A monster that, as it dies, logs every player in the room who was fighting it, after MurderBanish in guilds.zon.
See also
SFB_MSG
Constant (integer, vme.h: 0x0040).
wait(SFB_MSG, condition)
The message event: how DIL programs talk to each other. A program sends a text with send(), sendto(), sendtoall() or sendtoalldil(); a program waiting with SFB_MSG wakes with the text in argument.
What the event holds
| Variable | Value |
|---|---|
| activator | the unit whose program sent the message |
| argument | the text that was sent |
| command(CMD_AUTO_MSG) | TRUE |
| medium | null; with sendtoall() and sendtoalldil() the sender too
|
| target | null; with sendtoalldil() the unit receiving it
|
Who gets it
send(msg): the sender's surroundings, as a command (see SFB_CMD). The other programs on the sending unit get it only if they are declaredaware.sendto(msg, u): every program onu, the sender's own programs too whenuis the sender.sendtoall(msg, "sym@zone"): the programs on every copy of that unit in the game.sendtoalldil(msg, "tmpl@zone"): every running copy of that template, except the one sending.
Notes
- A program that is running can't be woken. While the sender is still busy after its send, a message sent back to it is lost; it can only be caught by programs that are waiting.
- Messages are not queued: a program that is busy, or waiting for another kind of event, misses them. Use
interrupt(SFB_MSG, ...)to catch a message while waiting for something else. - Compare texts with
==(which ignores case) or test words within.
Example
dilbegin herald();
code
{
heartbeat := PULSE_SEC * 5;
:start:
wait(SFB_MSG, argument == "gate open");
exec("shout The gate stands open!", self);
goto start;
}
dilend
dilbegin gatekeeper();
code
{
:start:
wait(SFB_CMD, command("say") and ("open sesame" in argument));
send("gate open");
goto start;
}
dilend
When a player says "open sesame" next to the gatekeeper, it tells the room, and a herald in the same room shouts the news.
See also
SFB_PRE
Constant (integer, vme.h: 0x0400).
wait(SFB_PRE, condition)
The "about to happen" event. It is sent just before a spell takes effect and just before damage is dealt, and the programs that get it can change it: set power to change how strong it is, or block to stop it.
Before a spell: command("cast")
| Variable | Value |
|---|---|
| activator | the caster |
| medium | the caster, or the scroll, wand or staff the spell comes from |
| target | the target of the spell |
| argument | the spell number (SPL_* in values.h), followed by the spell's own argument, which is usually empty
|
| power | how well the spell succeeds (its "hm"); read and write |
block stops the spell: nothing happens, and the caster's cast_spell() gets the value of power back, so set it to -1 as well.
Before damage: command(CMD_AUTO_DAMAGE)
| Variable | Value |
|---|---|
| activator | the one who deals the damage |
| medium | the weapon, or what the damage comes from |
| target | the one who takes it |
| argument | three numbers: the attack group (MSG_TYPE_WEAPON, MSG_TYPE_SPELL, MSG_TYPE_SKILL or MSG_TYPE_OTHER, vme.h), the attack within the group (for weapons a WPN_*), and the body part hit (in melee one of WEAR_HEAD, WEAR_HANDS, WEAR_ARMS, WEAR_BODY, WEAR_LEGS or WEAR_FEET)
|
| power | the damage; read and write. Don't set it below 0. |
block cancels the damage completely.
Notes
- The event reaches the activator's surroundings, as a command does (see SFB_CMD), and the target too when it is somewhere else.
- A program doesn't get the events of its own unit unless it is declared
aware: a monster that changes the damage of its own blows needsaware, as comb_poison in function.zon does. send_pre()sends this event from DIL.- Take the numbers out of
argumentwithgetword()andatoi().
Example
dilbegin fireward();
var
s : string;
spl : integer;
code
{
heartbeat := PULSE_SEC;
:start:
wait(SFB_PRE, command("cast") and (target == self));
s := getword(argument);
spl := atoi(s);
if (spl == SPL_FIREBALL_3)
{
act("The flames die around $1n.", A_SOMEONE, self, null, null, TO_ROOM);
power := -1;
block;
}
goto start;
}
dilend
dilbegin dmghalf();
code
{
heartbeat := PULSE_SEC;
:start:
wait(SFB_PRE, command(CMD_AUTO_DAMAGE) and (target == self.outside));
if (power > 1)
power := power / 2;
goto start;
}
dilend
fireward makes a monster immune to the strongest fireball; dmghalf on an item halves the damage its carrier takes.
See also
Built-in variables are set by the server for every program; a program uses them without declaring them. Most of them can only be read. Click a name for the full page.
The program and its event
Set for the running program; activator, medium, target, power, argument and the command strings describe the event that woke it.
| Variable | Access | What it holds |
|---|---|---|
self : unitptr |
read-only | The unit the program runs on. |
activator : unitptr |
read-only | The unit that caused the event that woke the program. |
medium : unitptr |
read-only | The unit used in the event that woke the program, when the event has one; otherwise null. |
target : unitptr |
read-only | The unit an action in the event was aimed at, when the event has one; otherwise null. |
power : integer |
read/write | A number that comes with SFB_PRE and SFB_DONE events. |
argument : string |
read-only | The text that came with the event that woke the program. |
cmdstr : string |
read-only | The full name of the command in the event that woke the program, as commands.def names it, even when the player typed an abbreviation. |
excmdstr : string |
read-only | The first word of the line the player typed, in lower case, not expanded. |
excmdstr_case : string |
read-only | The first word of the line the player typed, exactly as typed: Mellon stays "Mellon".
|
heartbeat : integer |
read/write | How often the program's tick comes, in quarter seconds: PULSE_SEC (4, vme.h) is one second.
|
Time and weather
| Variable | Access | What it holds |
|---|---|---|
realtime : integer |
read-only | The real time, in seconds since 1 January 1970 UTC: what time(NULL) gives in C.
|
| mudhour, mudday, mudmonth, mudyear (all four) | read-only | The game's clock and calendar. |
mudhour : integer |
read-only | The hour of the mud day, 0 to 23: 0 is midnight, 12 noon. |
mudday : integer |
read-only | The day of the mud month, 0 to 13. |
mudmonth : integer |
read-only | The month of the mud year, 0 to 8. |
mudyear : integer |
read-only | The mud year: the number of mud years since 11 August 1990, about 1261 in November 2026. |
weather : integer |
read-only | The sky over the zone the program's unit is in. |
null is not a variable but the empty value: see Data Types.
See also
- Messages, for the events that set
activatorand the others - Built-In Functions
- Fields
cmdstr
Variable (string, read-only).
cmdstr : string
The full name of the command in the event that woke the program, as commands.def names it, even when the player typed an abbreviation: n gives "north", 'hi gives "say". For a word that is no command, it's that word in lower case.
It is set in SFB_CMD events and in the SFB_DONE and SFB_PRE events of a command (after a give, "give"), and the first time a player command written in DIL runs. For ticks, messages, damage and other events that aren't a named command it is null, and comparing it with a string gives false.
Notes
cmdstr + " " + argumentis not what the player typed: the abbreviation is expanded and the spaces are trimmed. excmdstr is the word as typed.- To test for a command, use command(). cmdstr is for when the name is needed as text, for instance to repeat the command: basemove.zon's follow does
c := cmdstr;and laterexec(c, self);. - It belongs to the current event; copy it into a variable before a wait or pause.
- It can't be assigned.
Example
dilbegin fnpri(FN_PRI_BLOCK) gate_guard();
code
{
:start:
wait(SFB_CMD, (command("north") or command("up")) and
(activator.type == UNIT_ST_PC));
if (self.position < POSITION_STANDING)
goto start;
block;
act("$1n stops you from going $2t.", A_SOMEONE, self, cmdstr, activator, TO_VICT);
act("$1n stops $3n from going $2t.", A_SOMEONE, self, cmdstr, activator, TO_NOTVICT);
goto start;
}
dilend
A guard that blocks players going north or up, and names the direction in full whatever they typed.
See also
excmdstr
Variable (string, read-only).
excmdstr : string
The first word of the line the player typed, in lower case, not expanded: N gives "n", where cmdstr gives "north". A line starting with ' gives "say", one starting with , gives "emote". A word that is no command is there too.
It is set while a typed command is being handled: in SFB_CMD events, in the SFB_DONE and SFB_PRE events of that command, and the first time a player command written in DIL runs. Otherwise (ticks, messages, after the command) it is null.
Notes
- Use it to insist on the full word: commands.zon's quit refuses with
if (excmdstr != "quit"). - It reads typed input that isn't a command: competition.zon's menu takes a number with
atoi(excmdstr)afterwait(SFB_CMD, ...). excmdstr + " " + argumentis the line as typed, apart from case and spacing. excmdstr_case keeps the case.- It belongs to the command, not to the event: if the program exec()s the same command while handling it, excmdstr is null afterwards. Copy it into a variable first.
- It can't be assigned.
Example
dilbegin do_retire(arg : string);
code
{
if (excmdstr != "retire")
{
sendtext("You typed '" + excmdstr + "'. Type 'retire', no less, to retire.<br/>", self);
quit;
}
sendtext("You retire from adventuring.<br/>", self);
quit;
}
dilend
A player command (func = do_retire@zone in commands.def) that only works when typed in full, as quit in commands.zon.
See also
excmdstr_case
Variable (string, read-only).
excmdstr_case : string
The first word of the line the player typed, exactly as typed: Mellon stays "Mellon". Otherwise the same as excmdstr: ' gives "say", , gives "emote", and it is null outside a typed command.
Notes
- Use it where case matters, such as a password typed at a prompt: commands.zon's password command reads it after
wait(SFB_CMD, self == activator)andblock. ==on strings ignores case, soexcmdstr_case == "Mellon"is also true formellon. For an exact match usestrcmp(excmdstr_case, "Mellon") == 0.- Only the first word: the rest of the line is in
argument, which keeps its case. - Like excmdstr it belongs to the command: an exec() of the same command while handling it leaves it null. Copy it first.
Example
dilbegin secret_word();
var
word : string;
code
{
sendtext("Speak the word, exactly as it is written: ", self);
wait(SFB_CMD, activator == self);
block;
word := excmdstr_case;
if (strcmp(word, "Mellon") == 0)
sendtext("The doors swing open.<br/>", self);
else
sendtext("Nothing happens.<br/>", self);
quit;
}
dilend
Asks the player for a word and accepts only Mellon with that capital letter. The block keeps the word from running as a command.
See also
self
Variable (unitptr, read-only).
self : unitptr
The unit the program runs on:
- a template copied with
dilcopy: the unit it was copied onto; - a
dilbeginwritten inside a unit's definition: that unit; - a player command written in DIL (
func =in commands.def): the character who typed it; - a spell's DIL: the caster;
- a function called as
name@zone: the caller'sself, since it runs inside the caller's program.
Notes
selfis never cleared by a wait or a pause and needs no secure(). Unit variables are cleared at every wake;selfisn't one.- It can't be assigned (
self := uis "Illegal lvalue"). - When the unit is destroyed, its programs end with it. A program that destroys its own unit should
quitright afterdestroy(self), as death.zon's rot_head does. - The usual tests:
self.position(asleep, fighting),self.outside(where it is),exec("say ...", self)to make an NPC act.
Example
dilbegin crier();
code
{
heartbeat := PULSE_SEC * 60;
:start:
wait(SFB_TICK, TRUE);
if (self.position != POSITION_STANDING)
goto start;
exec("say Hear ye! " + self.name + " brings news to " + self.outside.title + "!", self);
goto start;
}
dilend
An NPC that, once a minute when standing, calls out its own name and the title of the room it is in.
See also
activator
Variable (unitptr, read-only).
activator : unitptr
The unit that caused the event that woke the program:
- SFB_CMD: the character who typed the command.
- SFB_DONE and SFB_PRE: the one who acted (who gave, moved, hit, cast).
- SFB_MSG: the unit whose program sent the message (sendto(), send(), sendtoalldil()).
- SFB_DEAD: the character who died. SFB_COM: the character fighting.
- SFB_TICK: null.
Notes
- It describes the current event only. After the next wait() or pause it belongs to another event, and a tick has no activator. Take it into a variable right after the wait, and secure() that variable to keep it: unit variables that aren't secured are null after every wake.
- The first time a player command written in DIL (
func =in commands.def) runs, activator is null; the player isselfthere. - It can't be assigned (
activator := uis "Illegal lvalue"). - In a wait condition,
activator.type == UNIT_ST_PCalso keeps out ticks: with no activator the field fails and the comparison is false.
Example
dilbegin greet_back();
var
pc : unitptr;
code
{
heartbeat := PULSE_SEC * 2;
:start:
wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC) and
("hello" in argument));
pc := activator;
secure(pc, lost);
pause;
exec("say Hello, " + pc.name + "!", self);
unsecure(pc);
goto start;
:lost:
goto start;
}
dilend
An NPC that answers a player who says "hello", after a pause. The player is kept in pc and secured, because after the pause activator belongs to the tick.
See also
target
Variable (unitptr, read-only).
target : unitptr
The unit an action in the event was aimed at, when the event has one; otherwise null:
- SFB_DONE after
give: the receiver. Aftergetanddrop: the item. Afterput: the container. After a move: the room entered. - SFB_PRE with
command(CMD_AUTO_DAMAGE): the victim of the hit. SFB_PRE for a spell: the spell's target. - SFB_CMD, SFB_MSG from sendto(), SFB_TICK: null.
- A send_done() or send_pre() from DIL passes its own target.
Notes
- The usual give handler waits for
command("give") and (target == self);mediumis then the item, already inself's inventory. - It belongs to the current event: copy it into a variable right after the wait, and secure() the variable if it must outlast a wait or pause.
targetis a reserved word, so no variable can be calledtarget; usetgtorvict.
Example
dilbegin altar_watch();
code
{
:start:
wait(SFB_DONE, command("get") and (medium == self));
act("The altar glows as $1n takes $2n from it.",
A_SOMEONE, activator, target, null, TO_ROOM);
act("The altar glows as you take $2n from it.",
A_SOMEONE, activator, target, null, TO_CHAR);
goto start;
}
dilend
An altar (an object with this program) that glows when someone takes something from it: in a get, medium is the container and target the item taken.
See also
medium
Variable (unitptr, read-only).
medium : unitptr
The unit used in the event that woke the program, when the event has one; otherwise null. What it is depends on the event:
- SFB_DONE after
give: the item or the coins given (targetis the receiver). Afterput: the item put (targetis the container). Afterget: the container it was taken from (targetis the item). After a move: the room left (targetis the room entered). - SFB_PRE with
command(CMD_AUTO_DAMAGE): the weapon of the hit (randomt.zon's vorpal weapon waits formedium == self). - SFB_CMD, SFB_MSG from sendto(), SFB_TICK: null.
- A send_done() or send_pre() from DIL passes its own medium.
Notes
- Like activator and target it belongs to the current event: copy it into a variable right after the wait, and secure() the variable if it must outlast a wait or pause.
- It can't be assigned.
- Coins given arrive merged with the coins the receiver already holds;
poweris the amount given.
Example
dilbegin collector(wanted : string);
var
item : unitptr;
pc : unitptr;
code
{
:start:
wait(SFB_DONE, command("give") and (target == self) and
(activator.type == UNIT_ST_PC));
item := medium;
pc := activator;
if (item.symname != wanted)
{
act("$1n doesn't want $2n.", A_ALWAYS, self, item, pc, TO_VICT);
goto start;
}
act("$1n thanks you for $2n.", A_ALWAYS, self, item, pc, TO_VICT);
destroy(item);
goto start;
}
dilend
An NPC (dilcopy collector@zone("gem@zone");) that takes one kind of item from players and destroys it, and says so when given anything else (the item then stays in its inventory).
See also
power
Variable (integer, read/write).
power : integer
A number that comes with SFB_PRE and SFB_DONE events. In a pre event a program can change it, and the server goes on with the new value: the damage of a hit, the power of a spell. In a done event it says what was done (the coins given, the direction moved), and changing it changes nothing that has happened.
Notes
- What it holds:
- SFB_PRE with
command(CMD_AUTO_DAMAGE): the damage about to be dealt (fight.cpp).activatoris the attacker,mediumthe weapon,targetthe victim, andargumentthree numbers: attack group, attack number, hit location. - SFB_PRE for a spell: the spell's power (spell_parser.cpp);
argumentstarts with the spell number. To stop the spell,block; death.zon also setspower := -1first. - SFB_DONE after
giveof coins: the amount (baseget.zon). After a move: the direction. After a spell: the spell number. After backstab and similar skills: the damage. - send_pre() and send_done() from DIL pass their own power.
- SFB_PRE with
- In other events (commands, messages, ticks) power is normally 0, but it isn't tied to the event: an assignment there writes one spare value that every program then reads until it is changed again (
dilfe_powein dilexp.cpp). Assign it only in a pre event. - The programs that get a pre event run one after another; each sees the power the ones before it left.
Example
dilbegin sharp_edge(pct : integer);
code
{
:start:
wait(SFB_PRE, command(CMD_AUTO_DAMAGE) and (medium == self));
if (activator != self.outside)
goto start;
if (power <= 0)
goto start;
power := power + (power * pct) / 100;
goto start;
}
dilend
A weapon (dilcopy sharp_edge@zone(20);) whose wielder's hits do 20 percent more damage, as comb_poison in function.zon adds to power.
See also
argument
Variable (string, read-only).
argument : string
The text that came with the event that woke the program:
- SFB_CMD: what the player typed after the command word, with the spaces around it removed. For
'Hello there(say) and,smiles(emote) it's the text after the mark. - SFB_MSG: the message.
- SFB_PRE and SFB_DONE: what the sender passed. For damage, three numbers (attack group, attack number, hit location); for a spell, the spell number first; after a
giveof coins, the money type. - SFB_TICK, SFB_DEAD, SFB_COM:
"".
Notes
- In a player command written in DIL (
func =in commands.def) the typed text is the template's string parameter;argumentis""there. - It belongs to the current event: after the next wait() or pause it is another event's. Copy it into a string variable (strings keep their value across waits).
- getword() and findunit() on
argumenttake the word they use off it, for the rest of this activation. Copy it first if you need the whole text afterwards. argument == "yes"ignores case;"word" in argumentis a substring test that also ignores case.- It can't be assigned.
Example
dilbegin parrot();
var
said : string;
code
{
heartbeat := PULSE_SEC * 2;
:start:
wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC));
said := argument;
pause;
if (said != "")
exec("say " + said + "! Squawk!", self);
goto start;
}
dilend
A parrot that repeats what players say, a moment later. The text is copied into said before the pause.
See also
heartbeat
Variable (integer, read/write).
heartbeat : integer
How often the program's tick comes, in quarter seconds: PULSE_SEC (4, vme.h) is one second. A program waiting for SFB_TICK, and every pause, waits for it. Each program has its own heartbeat; a new one starts at PULSE_SEC.
Notes
- Write it as a multiple of
PULSE_SEC(orWAIT_SEC, the same 4):heartbeat := PULSE_SEC * 30;is 30 seconds. - The new value takes effect when the program next waits. Anything below
PULSE_SECis raised toPULSE_SEC: no program ticks more than once a second. - It is kept in 16 bits without a sign: the longest heartbeat is 65535 (about 4.5 hours), larger values wrap round, and a negative one becomes a very long heartbeat. Reading it back gives a negative number for values from 32768 up.
pausewaits for the next tick, so withheartbeat := PULSE_SEC * 90a pause can take 90 seconds, and underprioritythe unit's other programs wait all that time. Shorten the heartbeat around pauses, as the example does. Just after a change the next tick comes at a random point between half and one and a half heartbeats (SFB_RANTIMEinpause).- A function called as
name@zoneshares its caller's heartbeat; quests.zon's functions save it and put it back (heartbeat := phb;). - On a running game a god's
wtimewarpmakes the ticks come without delay, to try out long heartbeats.
Example
dilbegin broom_seller();
code
{
heartbeat := PULSE_SEC * 60;
:start:
wait(SFB_TICK, TRUE);
heartbeat := PULSE_SEC * 3;
exec("say Brooms! Fine brooms!", self);
pause;
exec("say Two copper each!", self);
heartbeat := PULSE_SEC * 60;
goto start;
}
dilend
A street seller who calls out once a minute, with a three second pause between the two lines.
See also
null
Keyword. The empty value: no unit, no extra, no zone, no command, no string, an empty list.
null
Use it to test whether a variable holds anything, to empty a variable, and as an argument where a function takes "no unit", as in act(..., self, null, null, TO_ROOM).
Notes
u == nullandu != nullwork for unitptr, extraptr, zoneptr and cmdptr. Many functions return null when they find nothing: findunit(), findroom(), findsymbolic(), load(), and"name" in u.extra.if (u)andwhile (u)also test for null.- Assigning null empties a variable of any pointer, string or list type:
u := null;,s := null;,sl := null;. An integer can't take null: vmc says "Assigning incompatible types". - A stringlist or intlist is equal to null when it is empty.
- A string is equal to null only when it holds no string at all (never set, or set to null). After
s := "";,s == nullis false. Test strings withs == "", which is true in both cases. - A field of null fails, and a failed value is false in every comparison: when
uis null,u.level > 5andu.level <= 5are both false.andandorevaluate both sides, so testif (u == null)on its own before usingu.
Example
dilbegin integer carries(pc : unitptr, keysym : string);
var
u : unitptr;
code
{
if (pc == null)
return (FALSE);
u := findsymbolic(pc, keysym, FIND_UNIT_INVEN | FIND_UNIT_EQUIP);
return (u != null);
}
dilend
Tells whether a player carries or wears a unit, by its symbolic name ("key@zone"); a null player gives FALSE.
See also
weather
Variable (integer, read-only).
weather : integer
The sky over the zone the program's unit is in: SKY_CLOUDLESS 0, SKY_CLOUDY 1, SKY_RAINING 2 or SKY_LIGHTNING 3 (vme.h).
Every zone has its own weather. It follows the zone's air pressure, which changes every mud hour around the base pressure given by the weather line of the zone's header (weather 1040) and the season (see mudmonth).
Notes
- The zone is that of the room the unit is in, through whatever holds it: an object in a backpack has the weather of the room its carrier stands in.
- It is the zone's weather, indoors too. Test
UNIT_FL_INDOORSandUNIT_FL_NO_WEATHERyourself, on the room and what is around it, as spells.zon does before its weather spells. - The unit must be in a room. A player taken to the menu with gamestate() is in none, and reading
weatherin a program on them crashes the server. - It can't be assigned.
Example
dilbegin string sky_report();
var
u : unitptr;
code
{
u := self.outside;
while (u)
{
if (isset(u.flags, UNIT_FL_NO_WEATHER | UNIT_FL_INDOORS))
return ("You can't see the sky from here.");
u := u.outside;
}
if (weather == SKY_CLOUDLESS)
return ("The sky is clear.");
if (weather == SKY_CLOUDY)
return ("Clouds cover the sky.");
if (weather == SKY_RAINING)
return ("It is raining.");
return ("Lightning flashes across the sky.");
}
dilend
Describes the sky, or says it can't be seen from inside, with the indoors test from spells.zon.
See also
realtime
Variable (integer, read-only).
realtime : integer
The real time, in seconds since 1 January 1970 UTC: what time(NULL) gives in C.
Notes
- It is the real clock:
vme -wandwtimewarpdon't move it, unlike mudhour and the other mud-time variables. - asctime() turns it into a readable date:
asctime(realtime). pc.birthis on the same clock, sorealtime - pc.birthis a player's age in real seconds.- To keep a moment across reboots or on a unit, store
itoa(realtime)in an extra and compare withatoi()later, as death.zon does with severed heads. - It is a 32-bit signed integer, so it overflows on 19 January 2038.
Example
dilbegin rot_away();
var
e : extraptr;
code
{
heartbeat := PULSE_SEC * 15;
if (self.extra.["$made"] == null)
addextra(self.extra, {"$made"}, itoa(realtime));
:loop:
pause;
e := "$made" in self.extra;
if (e == null)
goto loop;
if ((realtime - atoi(e.descr)) > 1800)
{
act("$1n rots away.", A_SOMEONE, self, null, null, TO_ROOM);
destroy(self);
quit;
}
goto loop;
}
dilend
An object that rots away half an hour (1800 real seconds) after it first ran, as the heads in death.zon. The extra is looked up again after each pause, because extra variables are cleared at every wake.
See also
mudhour, mudday, mudmonth, mudyear
Variables (integer, read only).
mudhour : integer mudday : integer mudmonth : integer mudyear : integer
The game's clock and calendar. Each has its own page; this page shows them together.
| Variable | Range | Length |
|---|---|---|
| mudhour | 0 to 23 | one mud hour is 5 real minutes (SECS_PER_MUD_HOUR)
|
| mudday | 0 to 13: the day of the month | one mud day is 24 mud hours, 2 real hours |
| mudmonth | 0 to 8 | a month is 14 days (MUD_MONTH)
|
| mudyear | 0 and up | a year is 9 months (MUD_YEAR)
|
Notes
- They are variables, not functions: write
mudhour, notmudhour(). - The clock runs on the game's ticks, so a god's
wtimewarpmoves it forward too. - The constants are in vme.h. The comments there that say "21 mud days per mud month" are out of date:
MUD_MONTHis 14.
Example
dilbegin nightwatch();
code
{
heartbeat := PULSE_SEC * 60;
:start:
wait(SFB_TICK, (mudhour >= 22) or (mudhour < 6));
exec("emote lights a lantern.", self);
wait(SFB_TICK, (mudhour >= 6) and (mudhour < 22));
exec("emote puts out the lantern.", self);
goto start;
}
dilend
A watchman who lights his lantern at night.
See also
The statements that steer a DIL program: choosing, looping, jumping, waiting, and ending. Each has its own page with the details; this page shows them together.
Statements and blocks
Statements end with a semicolon. Braces group several statements into one, for if, while and foreach:
if (n > 3)
{
act("The chimes fall silent.", A_ALWAYS, self, null, null, TO_ALL);
quit;
}
A block must hold at least one statement; an empty { } is a syntax error. Comments are written // to the end of the line or /* between these */.
Choosing: if and else
if (condition) statement if (condition) statement else statement
The condition can be of any type (see Expressions). else if makes a chain. No semicolon between a closing brace and else: { ... }; else is a syntax error. An else belongs to the nearest if. See if() and else.
Looping: while and foreach
while (condition) statement
Tests the condition, runs the statement while it is true, and tests again. There is no for and no do ... while. See while().
foreach (UNIT_ST_PC | UNIT_ST_NPC, u) statement
Runs the statement once for each unit of the given types around the program's unit (in the same room, for a unit in a room), with u set to each in turn. The list is made when the loop starts and the units in it are watched, so the statement can move, kill or destroy them; a while over u.next can't. One foreach can't be inside another in the same template. See foreach().
break leaves the innermost loop; continue goes on with its next round. Both are refused by vmc outside a loop. In a while, take the step (u := u.next;) before a continue, or the loop never ends.
Jumping: labels and goto
:start:
wait(SFB_CMD, command("bow"));
...
goto start;
A label is a name between colons in front of a statement; goto carries on there. It can jump forwards, backwards, and out of loops and blocks, but not out of the template. A label must be followed by a statement (:done: quit;, not :done: }). Most programs are a loop of this kind: a label, a wait, the work, and goto back.
on n goto label0, label1, skip, label3;
on ... goto jumps to the label at position n in the list, counting from 0. When the entry is skip, or n is outside the list, the program goes on after the on. on rnd(0, 2) goto a, b, c; picks one of three at random.
Waiting
wait(events, condition) stops the program until an event of the given kinds comes for which the condition is true; Messages lists the events. pause; waits for the program's next tick, which comes every heartbeat. waitnoop lets the event that woke the program finish first and then goes on, almost at once.
At every wake each unitptr and extraptr variable that isn't secured becomes null, and the built-in variables describe the new event. Copy what you need right after the wait.
Keeping a unit: secure
pc := activator; secure(pc, lost);
secure(u, label) keeps the unit in pc across waits as long as it stays near the program's unit. When it leaves or is destroyed, the program jumps to the label instead. unsecure(u) ends it. The first argument must be one of the template's own variables.
Reacting to events at any time: interrupt and on_activation
interrupt(SFB_MSG, argument == "stop", stop_it); on_activation(self.position <= POSITION_SLEEPING, skip);
interrupt(events, condition, label) jumps to the label whenever an event of those kinds makes the condition true, whatever the program is waiting for. on_activation(condition, label) is checked at every wake; with skip instead of a label it makes the program ignore every event while the condition holds, as monsters do while asleep or fighting. Both stay set until clear() or until the template returns; an on_activation with a label is removed when it jumps.
Stopping commands and other programs: block and priority
- block stops the event that woke the program from going further: a command after
SFB_CMDisn't carried out, a spell or a hit afterSFB_PREdoesn't happen, and no program after this one gets the event. - priority keeps the later programs on the same unit from getting any event, until nopriority or the end of the program. The usual loop is
:start: nopriority; wait(...); priority; ... goto start;.
Which programs are "later" is set by fnpri.
Ending
- quit ends the program for good and removes it from its unit, also when written inside a function it called.
- return leaves a procedure (
return;) or a function (return(value);) and goes back to the caller. In the template a unit runs,return;ends the program likequit. - A program that runs past the closing brace of its
codestarts again from the top, with its variables as they were. A called template does the same instead of returning, so end it withreturnon every path.
The limit on statements
Each time the program wakes, it may run about 52,000 statements before it waits again (WAITCMD_MAXINST in vme/src/dil.h). Assignments, ifs, jumps, calls and most procedures count; a round of while (i < n) i := i + 1; counts three, so such a loop stops after about 17,000 rounds. A program that reaches the limit is stopped and removed, and the zone's log gets "DIL ... in unit ... had endless loop." A long job, such as a walk over all the units in the game, needs a pause now and then; the count starts again after each wait. Calling a template counts too, so endless recursion ends the same way.
Example
dilbegin fnpri(FN_PRI_BLOCK) toll_bridge(fee : integer);
var
pc : unitptr;
paid : stringlist;
code
{
heartbeat := PULSE_SEC * 5;
on_activation(self.position <= POSITION_SLEEPING, skip);
:start:
nopriority;
wait(SFB_CMD, command("east") and (activator.type == UNIT_ST_PC));
if ((activator.name in paid) or (activator.level >= IMMORTAL_LEVEL))
goto start;
pc := activator;
block;
secure(pc, lost);
priority;
exec("say That will be " + itoa(fee) + " coins, " + pc.name + ".", self);
pause;
on rnd(0, 2) goto grumble, wait_more, wait_more;
:grumble:
exec("grumble", self);
:wait_more:
unsecure(pc);
goto start;
:lost:
exec("say Cheapskate.", self);
goto start;
}
dilend
A troll on a bridge stops players going east until they have paid (the list paid would be filled by a second program that takes the money). It blocks the command, keeps the player with secure while it talks, holds priority so its other routines wait, picks a random reaction with on ... goto, and ignores everything while asleep.
See also
if()
Instruction. Runs a statement only when a condition holds, with an optional else.
if (condition) statement if (condition) statement else statement
The condition goes in parentheses. The statement is one statement ending in ;, or a block in braces { ... }, or another if. When the condition is false and there is an else, the statement after else runs instead.
The condition can be of any type:
- integer: true when it isn't 0;
- unitptr, extraptr, zoneptr, cmdptr and string: true when it isn't null;
- stringlist and intlist: true when the list has at least one element;
- a failed value (a field of a null unit, such as
u.levelwhenuis null): false.
Notes
- No
;between a closing brace andelse:if (a) { ... }; else ...is a syntax error atelse. After a single statement,if (a) x := 1; else x := 2;is fine. else if (...)makes a chain. Anelsebelongs to the nearestifbefore it; use braces whenifstatements are nested.andandorevaluate both sides; there is no short cut. To keep away from a null unit, test it in anifof its own first.- Test text by comparing it:
if (s != ""). A bare string variable is true as soon as it holds a value, even"". The fieldstitle,descr,outside_descrandinside_descrtested bare are currently true when they are empty (a bug), so compare them with""as well. - String
==and!=ignore case.
Example
dilbegin spirit_only();
code
{
:start:
wait(SFB_CMD, activator.type == UNIT_ST_PC);
if (activator.level >= ADMINISTRATOR_LEVEL)
goto start;
if (not isset(activator.pcflags, PC_SPIRIT))
{
act("Only the dead may stay here.", A_ALWAYS, activator, null, null, TO_CHAR);
link(activator, findroom(activator.hometown));
block;
}
else if (command("cast"))
{
act("Your powers do not work in the spirit world!",
A_ALWAYS, activator, null, null, TO_CHAR);
block;
}
goto start;
}
dilend
A room where only dead players may stay, and where spells don't work. Adapted from basis.zon.
See also
goto
Instruction. Jumps to a label.
goto name; ... :name: statement
A label is a name between colons in front of a statement. goto carries on from there. It can jump forwards and backwards, and out of loops and blocks. The usual DIL program is a loop: a label, a wait or pause, the work, and goto back to the label.
Notes
- A label must be followed by a statement:
:done: }is a syntax error. Write:done: quit;or:done: return;. - Labels belong to one template (
dilbegin ... dilend); a goto can't leave it. - vmc refuses a label that is never defined ("Undefined label: ...") and one defined twice ("Redefinition of label"). Names ignore case:
:Start:and:start:are the same label. - Several labels may stand in front of one statement.
- A loop that never waits (no
wait,pauseor other wait) is stopped by the server: it logs "DIL ... had endless loop." in the zone's log and removes the program. - Labels are also used by
on ... goto,interrupt(),on_activation()andsecure().
Example
dilbegin fish_monger();
code
{
heartbeat := PULSE_SEC * 60;
:loop:
pause;
if (self.position < POSITION_STANDING)
goto loop;
exec("say Fresh fish! Fresh fish!", self);
goto loop;
}
dilend
An NPC that calls out once a minute while standing.
See also
while
Instruction. Repeats a statement as long as a condition is true.
while (condition) statement
Tests condition, and while it is true runs the statement, usually a block in
{ }, and tests again. break leaves the loop at once;
continue goes back to the test.
Notes
- The condition is true when it is a non-zero integer, a unit or string that isn't null, or a list that isn't empty. A condition that fails (a field of a null unit) is false, so
while (u.level > 5)stops whenubecomes null. - Don't test a text field or a string list entry on its own, as in
while (sl.[i])orwhile (u.title): for these the test is the wrong way round, true when the text is empty. Writewhile (sl.[i] != ""). andandorevaluate both sides:(u != null) and (u.type == UNIT_ST_PC)still readsu.type. That is harmless here, since a failed field is false.- There is no
do ... whileand nofor. - A loop that runs about 52000 instructions without a
waitorpausegets the program stopped ("had endless loop" in the zone log). A long walk over the world's units needs apausenow and then. - A loop over a room's units that moves or destroys them should be a foreach(): after
link(u, ...),u.nextis in the other place.
Example
dilbegin unitptr first_weapon(ch : unitptr);
var
u : unitptr;
code
{
u := ch.inside;
while (u != null)
{
if (u.type == UNIT_ST_OBJ)
if (u.objecttype == ITEM_WEAPON)
break;
u := u.next;
}
return(u); // null when there is none
}
dilend
Finds the first weapon a character carries, or null.
See also
break
Instruction. Leaves the loop it is in.
break;
Jumps to the first statement after the innermost while or foreach around it. These are DIL's only loop statements.
Notes
- Outside a loop vmc stops with "Using break outside loop".
- In nested loops it only leaves the innermost one.
- Leaving a
foreachearly is fine: the units it hadn't reached are dropped when the nextforeachstarts or the template returns.
Example
dilbegin wake_sleeper();
var
u : unitptr;
code
{
u := self.outside.inside;
while (u != null)
{
if ((u.type == UNIT_ST_PC) and (u.position == POSITION_SLEEPING))
break;
u := u.next;
}
if (u != null)
exec("wake " + u.name, self);
quit;
}
dilend
An NPC looks through its room for the first sleeping player and wakes them. After the loop u is that player, or null when there was none.
See also
continue
Instruction. Skips the rest of the loop's statement and starts its next round.
continue;
In a while it goes back to the loop's test; in a foreach it goes on with the next unit. It acts on the innermost loop around it.
Notes
- Outside a loop vmc stops with "Using continue outside loop".
- In a
while, take the step before thecontinue. Acontinuethat skipsu := u.next;runs the same round again and again, until the server stops the program for an endless loop.
Example
dilbegin carried_weight();
var
u : unitptr;
w : unitptr;
n : integer;
code
{
u := self.inside;
while (u != null)
{
w := u;
u := u.next;
if (w.equip != 0)
continue;
n := n + w.weight;
}
exec("say What I carry weighs " + itoa(n) + ", not counting what I wear.", self);
quit;
}
dilend
Adds up the weight of what an NPC carries but doesn't wear. The step to the next unit comes before the continue.
See also
on n goto la, lb, ..., ln:
This construct is an easy way of performing a goto operation
based on the result of an integer. The integer value 'n' must
be zero or positive and less than the number of labels specified
in the label-list. If n is outside this range, the on-goto operation
is skipped and execution continues at the next instruction.
Based on the value of 'n' execution continues at the label
corresponding to number 'n' in the list. I.e. if n is 0, then
execution continues at the first specified label, if n is 1
then at the second, etc. etc.
Example:
Assume you have an integer 'i' larger than zero, which takes on 0, 1, 2, 3, 4 or 5. Based on each value you need to take a different action, this is how you can do it:
on i goto grin, laugh, grin, nada, poke, laugh;
log("Value was not in the range 0..5");
quit;
:laugh:
exec("grin", self);
goto ...;
:grin:
exec("cackle", self);
goto ...;
:blank:
exec("cry", self);
goto ...;
:poke:
exec("smirk", self);
goto ...;
It is often used in this context
on rnd(0,4) goto l1, l2, l3, l4, l5;
:l1:
bla;
:l2:
bla;
....
---~---~---~---~---~---~---~---~---
on n goto la, lb, ..., ln:
This construct is an easy way of performing a goto operation
based on the result of an integer. The integer value 'n' must
be zero or positive and less than the number of labels specified
in the label-list. If n is outside this range, the on-goto operation
is skipped and execution continues at the next instruction.
Based on the value of 'n' execution continues at the label
corresponding to number 'n' in the list. I.e. if n is 0, then
execution continues at the first specified label, if n is 1
then at the second, etc. etc.
Example:
Assume you have an integer 'i' larger than zero, which takes on 0, 1, 2, 3, 4 or 5. Based on each value you need to take a different action, this is how you can do it:
on i goto grin, laugh, grin, nada, poke, laugh;
log("Value was not in the range 0..5");
quit;
:laugh:
exec("grin", self);
goto ...;
:grin:
exec("cackle", self);
goto ...;
:blank:
exec("cry", self);
goto ...;
:poke:
exec("smirk", self);
goto ...;
It is often used in this context
on rnd(0,4) goto l1, l2, l3, l4, l5;
:l1:
bla;
:l2:
bla;
....
---~---~---~---~---~---~---~---~---
foreach()
Instruction. Runs a statement once for each unit of some types around the program's unit.
foreach (types : integer, u : unitptr) statement
When the loop starts, it lists the units around the program's own unit whose type is in types (UNIT_ST_PC, UNIT_ST_NPC, UNIT_ST_OBJ, UNIT_ST_ROOM, combined with |). Then it puts each in turn in u and runs the statement, usually a { ... } block.
"Around" means the units in the unit that holds the program's unit: for an NPC or object in a room, the units in the room; for an object a character carries, the character's inventory and equipment; for a room, the units in it. It also lists the units inside transparent units there (an open container or room with UNIT_FL_TRANS), but not what characters carry. The program's own unit is in the list too when its type is one of types: test u == self to skip it.
The list is a snapshot, and its units are watched like secured ones: a unit that has left or died before its turn is skipped. So the statement can move, kill or destroy units safely, which a while over .next can't do.
Parameters
| Name | Type | Meaning |
|---|---|---|
| types | integer | The UNIT_ST_ types to list. 0 lists nothing.
|
| u | unitptr | The variable that gets each unit. |
Notes
- break leaves the loop; continue goes on with the next unit.
- The units come in no particular order.
- One
foreachcan't be inside another in the same template (vmc: "'foreach' may not be nested!"). Use awhilefor the inner loop. umust be aunitptrvariable. vmc doesn't check it: with another type the program stops at run time with "Type error in foreach - next".uitself isn't secured: after await()orpauseinside the loop it is null, like any unit variable. The loop goes on with the next unit all the same.
Example
dilbegin closing_time();
var
u : unitptr;
street : unitptr;
code
{
street := findroom("street@ex");
if (street == null)
quit;
foreach (UNIT_ST_PC, u)
{
if (u.level >= IMMORTAL_LEVEL)
continue;
act("$1n throws you out.", A_ALWAYS, self, null, u, TO_VICT);
link(u, street);
exec("look", u);
}
quit;
}
dilend
An innkeeper throws every mortal player out into the street. Moving the players inside the loop is safe because it is a foreach.
See also
An assignment gives a variable or a field a new value:
target := expression;
The right side is worked out first, then stored in the target. Both sides must have the same type; otherwise vmc stops with "Assigning incompatible types". Assignment is a statement, not an expression: a := b := 0; and a += 1; are syntax errors; write a := a + 1;.
What can be assigned
| Target | Example |
|---|---|
| The template's variables and arguments | n := n + 1;, pc := activator;
|
| A field marked read/write on the Fields page | self.hp := self.max_hp;, u.title := "the tired";, exd.descr := "3";
|
| An indexed field of a character | pc.skills[SKI_SEARCH] := 50;
|
| One entry of a stringlist or intlist | sl.[0] := "black";, il.[2] := 50;
|
| The built-in variables heartbeat and power | heartbeat := PULSE_SEC * 10;
|
These can't be assigned; vmc stops with "Illegal lvalue":
- the other built-in variables:
self,activator,target,medium,argument,cmdstrand the rest; - read-only fields, such as
u.name(changeu.namesinstead),u.type,u.outside,u.inside,u.zone,u.extra. Many of them are changed with a procedure instead: link() moves a unit, addextra() adds an extra. Each field's page says; - a character of a string:
s.[0] := "x";. Build a new string with left(), right() and+.
An entry outside a list (sl.[5] in a list of three) is not created; the assignment does nothing. Make the list longer with addstring() or insert().
Fields that need a trusted zone
Each zone has an access level, the fourth column of vme/etc/zonelist, from 0 (most trusted) to 255. Programs of zones with a level other than 0 can read, but not change, these fields: exp; abilities, skills, spells and weapons and their _levels; and of players, level, vlevel, profession, lifespan and max_hp. vmc can't know the level, so it compiles the assignment, and it stops the program when it runs, with "DIL SERIOUS: ... Type error in lvalue assignemt" in the zone's log. The level that counts is that of the zone of the template the unit runs, also inside a function from another zone that it calls. Each field's page says when it is restricted.
Integers stored in fewer bits
Many integer fields are kept in 8 or 16 bits. A value that doesn't fit wraps round without a warning: an 8-bit field given 300 holds 44. Integer variables are 32 bits and wrap too: 2147483647 + 1 is -2147483648. Each field's page gives its range.
Copies
- Assigning a string or a list copies it: after
sl := u.names;, changingsldoesn't change the unit's names. To change those, assign the list back:u.names := sl;. - Assigning a unit, an extra, a zone or a command copies the pointer: both variables then reach the same thing.
- Don't assign a list to itself:
sl := sl;leaves it empty.
When the value fails
A value fails when it can't be worked out: a field of null (u.level when u is null), a division by 0, a list index outside the list. Assigning a failed value:
| Variable | Result |
|---|---|
| integer | keeps its old value |
| string | becomes empty ("")
|
| stringlist, intlist | keeps its old value |
| unitptr, extraptr, zoneptr, cmdptr | keeps its old value |
So x := u.level; with u null leaves x as it was, which may be a value from the last round of a loop. Test the unit first:
if (u == null) goto nobody; x := u.level;
A string joined to a failed value is worse: s := "Hello " + u.name; with u null stops the whole program with "Type error in string assignment", and so does using such a join as an argument (sendtext("Hi " + u.name, pc)). With the failed part first (u.name + "!") the join just fails.
Assigning null
null empties any variable that isn't an integer: u := null;, s := null;, sl := null;. An emptied string is equal to both null and ""; after s := ""; it is equal to "" only. Compare strings with "", which is true in both cases. n := null; doesn't compile: give an integer 0. An empty {} doesn't compile in code either; use null to empty a list. See null.
Arguments and globals
A template's arguments are its own copies of what the caller passed: assigning to an argument doesn't change the caller's variable. A global list is the exception the other way round: assigning to it (or addstring, insert, remove) changes the list every program with that key sees.
Example
dilbegin name_pet(pet : unitptr, word : string);
var
sl : stringlist;
code
{
if (pet == null)
return;
if (word == "")
return;
sl := pet.names;
if (word in sl)
return;
insert(sl, 0, word);
pet.names := sl;
pet.title := word + ", " + pet.title;
return;
}
dilend
A procedure that gives a pet a name: the names are copied out, changed and assigned back, and the title, a writable field, gets the name in front ("Rex, a small dog"). pet.name is read-only; it is the first of pet.names, so it is now "Rex" too.
See also
An expression works out a value: the right side of an assignment, the condition of an if, while or wait(), the arguments of a call. Every expression has one of the eight types, known when vmc compiles it, and vmc refuses one of the wrong type ("Arg 1 of '+' not integer or string", "Assigning incompatible types").
What an expression is made of
- Constants. Integers in decimal (
42) or hexadecimal (0x2A); a minus sign in front makes them negative. Strings between double quotes, without\"or^inside. Lists in braces, of constants only:{"a", "b"},{1, 2}. null. Macros from the include files, such asTRUE,PULSE_SEC,UNIT_ST_PCorSKI_SEARCH, are replaced by their values before compiling. - Variables: the template's own, its arguments, and the built-in variables (
self,activator,argument...). - Fields, with a dot:
self.outside.title. Indexed fields take brackets:pc.skills[SKI_SEARCH],room.exit_to[NORTH]. A list entry or a character of a string takes.[i]:sl.[0],s.[0]; an extra by name,u.extra.["$data"]. See Fields. - Calls: built-in functions (
itoa(n),findroom(s)) and the zone's own functions (max@function(a, b); see Functions). - Operators joining these:
+ - * / %,== != < > <= >=,and or not,& |,in. See Operators. - Brackets to group:
(a + b) * 2.
A field or a call can't follow a call: findroom(s).title is a syntax error, and so is a DIL function's result passed straight to another DIL function (f(g(x))). Put the first result in a variable.
Precedence
DIL's operators have four levels, from binding most tightly to binding least:
not, which applies only to the value right after it;* / % and & in;+ - or |, and a minus sign in front of a value;- the comparisons
== != < > <= >=.
This is not the order of C or most other languages: and and or bind more tightly than the comparisons. vmc accepts
if (a == 1 and b == 2)
but reads it as (a == (1 and b)) == 2, which is false even when a is 1 and b is 2. In the same way a == 1 or a == 2 is false when a is 2. Put every comparison in brackets:
if ((a == 1) and (b == 2))
The Operators page has the whole table and more such cases.
Truth
A condition can be of any type. An integer is true when it isn't 0; a string, unit, extra, zone or command when it isn't null; a list when it isn't empty; a failed value is false. Comparisons, and, or and not give 1 (TRUE) or 0 (FALSE).
A string variable that has been given "" is not null, so it counts as true: test text with s != "". The fields title, descr, outside_descr and inside_descr tested on their own (if (u.title)) currently count the wrong way round, true when they are empty; compare them with "" as well.
Failed values
An expression that can't be worked out fails: it has no value, and no error is written. That happens with
- a field of null:
u.levelwhenuis null; - a field the unit doesn't have:
u.levelwhenuis a room; - a division by 0:
a / 0,a % 0; - an index outside a list or string:
sl.[9]in a list of three (this one writes "index of stringlist out of bounds" to the zone's log); - most built-in functions given a failed argument.
A failure spreads to the expression around it:
- arithmetic and joins with a failed part fail:
u.level + 1,u.name + "!"; - every comparison with a failed side is false.
u.level > 5andu.level <= 5are both false, and so areu.outside == nullandu.outside != nullwhenuis null. (One exception, a bug: when the right side of a==between units fails, the left side is compared with null, sonull == u.outsideis true.) andandortreat a failed side as false, andnotmakes it true:not (u.level > 5)is true whenuis null;- an
if,whileorwait()whose condition fails takes it as false; - an assignment of a failed value leaves an integer, list or pointer variable as it was, and empties a string variable (see Assignment).
Two cases stop the program instead: a string joined to a failed value with the string first ("Hello " + u.name), when it is assigned or passed to a procedure ("Type error in string assignment"); and a function's return of a failed value.
So test a unit before using its fields, in a statement of its own:
if (u == null) goto nobody;
Evaluation
Both sides of every operator are worked out, left side first. and and or don't stop early: in (u != null) and (u.level > 5) the field is read even when u is null (harmless, since it only fails), and in (n > 0) and check@myzone(n) the function is called whatever n is.
The condition of a wait() is worked out again at every event of the kinds it waits for, which can be many times a second near a busy room or fight. Keep it short, and call findunit(), loops or your own functions after the wait instead of in it.
vmc works out the parts of an expression that use only constants when it compiles: PULSE_SEC * 60 costs nothing when the program runs. A constant division by 0 (5 / 0) makes vmc itself crash.
Example
dilbegin integer can_enter(pc : unitptr, minlvl : integer);
code
{
if (pc == null)
return (FALSE);
if ((pc.type != UNIT_ST_PC) or (pc.level < minlvl))
return (FALSE);
if (("$banned" in pc.extra) != null)
return (FALSE);
return (TRUE);
}
dilend
A function that tells whether a character may pass: null is tested on its own first, each comparison is in brackets, and in on extras gives an extraptr that is compared with null.
See also
The operators of DIL, how tightly each binds, and what each does with each type. Expressions explains failed values and evaluation; Assignment covers :=, which is a statement, not an operator.
Precedence
The grammar of vmc (vme/src/vmc/dilpar.y) has four levels. Operators on a higher line bind more tightly; on one line they are worked out from left to right.
| Level | Operators | Notes |
|---|---|---|
| 1 (tightest) | not |
applies to the single value right after it: a constant, variable, field, call or bracket |
| 2 | * / % and & in |
|
| 3 | , and a minus or plus sign in front of a value | |
| 4 (loosest) | == != < > <= >= $= #= |
$= and #= can't be chained
|
Brackets ( ) override it all. Some consequences, all checked with vmc and in the game:
| Written | Read as | Value |
|---|---|---|
a == 1 and b == 2 |
(a == (1 and b)) == 2 |
false, even with a = 1 and b = 2 |
a == 1 or a == 2 |
(a == (1 or a)) == 2 |
false with a = 2 |
(a == 1) and (b == 2) or (c == 3) |
((a == 1) and (b == 2)) or (c == 3) |
as expected |
| 4 and 1 | (4 and 1) | 3 |
not a == 5 |
(not a) == 5 |
false with a = 0 |
not "x" in sl |
(not "x") in sl |
vmc: "Arg 1 of 'in' not string" |
"a" + "b" in s |
"a" + ("b" in s) |
vmc: "Arg 2 of '+' not string" |
1 < 2 < 3, 3 > 2 > 1 |
(1 < 2) < 3, (3 > 2) > 1 |
true, false |
-a * b |
-(a * b) |
the same number |
So: put every comparison in brackets when it is joined with and or or, and write not (...) with brackets.
A minus sign can't come right after another operator: a + -1, a * -1 and - -a are syntax errors. Write a - 1 or a * (-1). After a comparison or a comma it is fine: if (a == -1), rnd(-5, 5).
Arithmetic
| Operator | Types | Result |
|---|---|---|
+ |
integer + integer | the sum |
+ |
string + string | the two joined: "You have " + itoa(n) + " coins."
|
- * |
integers | difference, product |
/ |
integers | the quotient, cut towards 0: -7 / 2 is -3
|
% |
integers | the remainder, with the sign of the left side: -7 % 3 is -1, 7 % -3 is 1
|
-a, +a |
integer | minus a, a |
- Integers are 32 bits and wrap round without a warning:
2147483647 + 1is-2147483648. - Dividing by 0 with
/or%fails (see Expressions): an integer assigned from it keeps its old value. A division of two constants by 0, such as5 / 0, crashes vmc instead. - There are no numbers with a fraction. For a percentage multiply first:
(part * 100) / whole. +doesn't mix strings and integers:"a" + 5doesn't compile; use itoa(). A join with a failed part fails, but with the string on the left ("Hi " + u.namewhenuis null) it stops the program when assigned or passed to a procedure.- rnd() gives random numbers.
Comparison
| Operator | Types | Meaning |
|---|---|---|
== != |
integers | equal, not equal |
== != |
strings | equal, ignoring case: "Sword" == "sword" is true. An unset string and "" are equal.
|
== != |
unitptr, extraptr, zoneptr, cmdptr | the same unit, extra, zone or command; or both null |
== != |
stringlist, intlist | the same list, not the same contents: two list variables are never equal. sl == null is true when the list is empty.
|
< > <= >= |
integers | less, greater... |
< > <= >= |
strings | alphabetical order, ignoring case: "B" > "a" is true
|
$= |
strings | old form of == for strings; still used in some zones
|
#= |
strings, units, extras, lists | the same object in memory: two strings with the same text are not #=. Obsolete.
|
- Both sides must be of the same type, or one of them
null:if (n == "5")andif (u == exd)don't compile. Units can't be ordered:u < vdoesn't compile. - The result is 1 or 0. With a failed side it is false, for
==and!=alike (with one exception, a bug, on the Expressions page). - For an exact, case-sensitive comparison of strings use strcmp() or strncmp().
Logic
| Operator | Types | Result |
|---|---|---|
and |
any | 1 if both sides are true, else 0 |
or |
any | 1 if either side is true, else 0 |
not |
any | 1 if the value is false, null, empty or failed, else 0 |
- Any type counts as true or false, as in an
if: see Expressions. - Both sides are always worked out, left first.
(u != null) and (u.level > 5)still readsu.level, and a function call on the right is made even when the left side already decides the answer. - A failed side counts as false;
notof a failed value is 1.
Bits
| Operator | Types | Result |
|---|---|---|
& |
integers | the bits set in both: 6 & 3 is 2
|
| integers | SFB_DONE |
- vmc accepts other types here too, but the value then fails when the program runs.
- For flag fields isset(), set() and unset() are clearer:
if (isset(u.flags, UNIT_FL_TRANS)). |binds like+and&like*:1 | 2 * 2is 5.
in
s in x looks for the string s; the left side must be a string. See in.
| Right side | Result |
|---|---|
| string | 1 if s occurs anywhere in it, ignoring case ("key" in "a KEY ring"), else 0. See string in string.
|
| stringlist | the position plus one of the first entry that is s (or the first words of s), ignoring case; 0 if none. See string in stringlist.
|
| extraptr | the first extra with s as one of its names, or null. See string in extraptr.
|
There is no in for an intlist. in binds like *, more tightly than + and the comparisons.
Example
dilbegin integer good_buyer(pc : unitptr, price : integer);
var
pct : integer;
code
{
if (pc == null)
return (FALSE);
pct := (pc.hp * 100) / pc.max_hp;
if ((pc.type == UNIT_ST_PC) and (pct > 50) and
((pc.level >= 10) or (price < 100)))
return (TRUE);
if (not ("merchant" in pc.names))
return (FALSE);
return ((price % 2) == 0);
}
dilend
Brackets around each comparison and around the in after not; a percentage worked out with the multiplication first. If max_hp were 0 the division would fail, pct would keep its old value (0), and the test would just be false.
See also
in
Keyword (operator; integer or extraptr). Looks for a string in a string, a stringlist or a list of extras.
s in text : integer (text : string) s in list : integer (list : stringlist) s in extras : extraptr (extras : extraptr)
The left side is always a string. What in does depends on the right side:
- string: TRUE (1) if
soccurs anywhere intext, ignoring case, otherwise FALSE (0)."key" in "Do you have a KEY?"is TRUE, and so is"spook" in "nospook". - stringlist: the position of the first entry that matches, plus one (so 1 for the first entry), or 0 if none does. An entry matches when it is
s, or the first word or words ofs, ignoring case:"ship arrived" in {"ship"}is 1, but"arrived" in {"arrived_port"}is 0. - extraptr (such as
u.extraorpc.quests): the first extra that hassas one of its names (the whole name, ignoring case), or null.
Returns
An integer for a string or stringlist, an extraptr for extras. Both work directly in an if: 0 and null are false. If either side fails (a field of a null unit, say), the result fails, which is also false.
Notes
inbinds like*,/andand: tighter than+,-,orand comparisons, looser thannot. So writenot ("x" in sl):not "x" in slis read as(not "x") in sland vmc stops with "Arg 1 of 'in' not string". Likewise"a" + b in smeans"a" + (b in s).- The string test is a substring test. To match a whole word, split the text into words first (
getwords()) and use the stringlist form. - In the stringlist form, leading spaces in
sare skipped and runs of spaces count as one. - A list in braces works on the right:
arg in {":brief:", ":chars:"}(baselook.zon). The braces take only constants, not variables. - For quests, use quests.zon's functions (
qstOngoing@questsand friends) rather than testingpc.questsby hand.
Example
dilbegin gate_talk();
var
ex : extraptr;
n : integer;
code
{
:start:
wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC));
if (not ("password" in argument))
goto start;
n := getword(argument) in {"swordfish", "dragon"};
ex := "$gate_pass" in activator.extra;
if (n == 0)
act("$1n shakes $1s head.", A_ALWAYS, self, null, activator, TO_ROOM);
else if (ex != null)
act("$1n nods to $3n: 'Welcome back.'", A_ALWAYS, self, null, activator, TO_ROOM);
else
{
addextra(activator.extra, {"$gate_pass"}, "1");
act("$1n lets $3n through.", A_ALWAYS, self, null, activator, TO_ROOM);
}
goto start;
}
dilend
A guard who listens for "password" anywhere in what is said (string form), checks the first word against the passwords (stringlist form) and remembers who has been let through (extra form).
See also
string in string
Operator (integer).
s1 in s2 : integer
TRUE (1) when the text s1 appears anywhere in s2, FALSE (0) when it doesn't. Case is ignored, and s1 may be part of a word: "key" in "Do you have a KEY?" and "ear" in "I hear you" are both TRUE.
Returns
TRUE or FALSE. An empty s1 ("") is found in every string.
Notes
- It is a plain substring test: to match whole words, use
inwith a stringlist (for example one made withsplit()) instead. - A string variable that was never assigned has no value at all, which isn't the same as
"". With such a variable on either side the result is null instead of an integer: aniftreats it as false, but assigning it to an integer variable stops the program with "Type error in integer assignemt" in the log. - The same operator with a stringlist or an extra description list on the right works differently: see the pages below.
Example
dilbegin keyword();
code
{
heartbeat := PULSE_SEC * 5;
:start:
wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC));
if ("password" in argument)
exec("say Shh! Not so loud!", self);
goto start;
}
dilend
A monster that reacts when a player says something with "password" in it.
See also
string in stringlist
Operator (integer).
s in sl : integer
Looks for the string s in the stringlist sl and gives its position plus one: 1 for the first entry, 2 for the second, 0 when nothing matches. sl.[(s in sl) - 1] is the entry that matched.
An entry matches when it is the whole of s or the first words of it. Case is ignored, spaces before s are skipped, and double spaces inside it count as one. So with sl := {"red", "dark blue"}:
"red" in sl,"RED" in sland"red apple" in slare 1;"dark blue" in slis 2;"re" in sl,"reddish" in sland"dark" in slare 0.
Returns
An integer: the index plus one of the first entry that matches, or 0.
Notes
- It is not a substring test. The entry must match from the start of
sand end where a word ofsends:"arrived" in {"arrived_port"}is 0, but"ship arrived" in {"ship"}is 1. - The first matching entry wins; an entry that is a shorter phrase than a later one hides it.
- A string variable that was never assigned gives null instead of 0: an
iftreats it as false, but assigning it to an integer variable stops the program with a type error. - Fields that are stringlists work the same way:
"sword" in u.namestells whether "sword" is one of the unit's names.
Example
dilbegin string colourname(word : string);
var
sl : stringlist;
i : integer;
code
{
sl := {"red", "green", "dark blue"};
i := word in sl;
if (i == 0)
return ("no colour");
return ("colour number " + itoa(i) + ": " + sl.[i - 1]);
}
dilend
Tells which colour a word starts with: "Green grass" gives "colour number 2: green".
See also
string in extraptr
Operator (extraptr).
s in exlist : extraptr
Finds the extra description whose names include s, in a list of extras such as u.extra or pc.quests, and gives that extra; null when there is none. Use it to find hidden data extras ("$visits" in pc.extra) and quest entries.
Returns
The first extra in the list with a name equal to s, or null. Read its descr, names and vals fields, or change them.
Notes
- The name must match exactly, letter by letter; only case is ignored.
"$visit" in u.extradoesn't find an extra named "$visits", and no partial words or first words match, unlikeinwith a stringlist. - Spaces before
sare skipped; spaces after it are not. - An extra with no names at all is found by
"". u.extra.["$visits"]does the same search.- The extraptr is only good until the program waits: after
wait()orpauseevery extraptr variable is null, so look it up again.
Example
dilbegin integer visits(pc : unitptr);
var
exd : extraptr;
code
{
exd := "$visits" in pc.extra;
if (exd == null)
{
addextra(pc.extra, {"$visits"}, "1");
return (1);
}
exd.descr := itoa(atoi(exd.descr) + 1);
return (atoi(exd.descr));
}
dilend
Counts a player's visits in a hidden extra and gives the new count.
See also
Besides its built-in functions and procedures, DIL lets a template call other templates: as a procedure, a statement that does something, or as a function, which gives back a value. A template written for that is an ordinary dilbegin ... dilend; zones such as function.zon, quests.zon and randomt.zon hold libraries of them.
Procedures and functions
dilbegin tell_all(msg : string); // a procedure dilbegin integer max(a : integer, b : integer); // a function returning an integer
A type in front of the name makes a function; it can be any of the eight types. A function ends with return(value);, a value of that type; a procedure with return;. See return.
- Put
returnon every path. A called template that runs past its closing brace starts again from its first statement instead of going back. return(null);doesn't compile in aunitptrfunction: return a unit variable that is null instead.- Returning a value that fails (a field of null) stops the whole program ("Error return types do not match" in
vme.log). - quit inside a called template ends the whole program, the callers too. Use
returnto go back.
Declaring and calling
A template calls another after declaring it in its external section, with the same return type and argument types (the argument names don't matter):
dilbegin show_best(arg : string);
external
integer max@function(a : integer, b : integer);
tell_all(msg : string);
var
n : integer;
code
{
n := max@function(self.hp, 10);
tell_all("Best: " + itoa(n));
quit;
}
dilend
- A template in another zone is named
name@zone, in the declaration and in the call. One in the same zone can be named without@zone, but it still needs the declaration; without it vmc says "No such variable". - A procedure is called as a statement:
tell_all("...");. A function is called in an expression:n := max@function(a, b);,if (max@function(a, b) > 10),itoa(max@function(a, b)). A function can also be called as a statement; its value is then thrown away. - A DIL function's result can't be passed straight to another DIL function:
f(g(x))doesn't compile. Putg(x)in a variable first. Built-in functions take it:itoa(g(x))is fine. - A field can't follow a call:
get_room(s).titleis a syntax error. - vmc writes a declaration for each template of a zone to
<zone>.dhnext to the zone file, ready to copy. - The server checks each declaration against the real template when it boots. A missing one is logged as "Cannot resolve external reference 'name@zone'", one that doesn't match as "Error typechecking reference to 'name@zone'". Calling it later stops the program ("Error in remote call function #n not valid").
Arguments
Arguments can be of any of the eight types. They are passed by value: each becomes a variable of the called template, a copy of what the caller passed.
- Integers, strings, stringlists and intlists are copied. Assigning to an argument, or
addstring()to a list argument, changes only the copy; the caller's variable stays as it was. To give a value back, return it. - A unitptr, extraptr, zoneptr or cmdptr argument is a copy of the pointer: it reaches the same unit, so
u.hp := 1;in the called template changes the unit the caller sees. - A failed argument (a field of null) stops the program with "parameter N has incorrect type".
nullis fine.
A called template runs inside the same program, on the same unit:
selfis the caller's unit, andactivator,argumentand the other built-in variables still describe the event that woke the program. Pass anything else as arguments.- It has its own variables, which start empty at every call: 0, "", empty lists, null. Only global variables are shared.
- It shares the program's heartbeat: a function that changes it for a
pauseshould put it back, as quests.zon's functions do. - Its secures and interrupts are its own and end when it returns. When it returns, the caller's secures are tested again.
- It may wait (
wait,pause); the whole program waits with it. A program copied withrecallonly saves its place in the copied template, not inside a call. - It counts towards the program's limit of about 52,000 statements between waits (see DIL Constructs).
Recursion
A template can call itself, without declaring itself (declaring itself in its own external section is a syntax error). Each call has its own variables. There is no other limit on the depth than the statement limit, so a recursion that never ends gets the program stopped as an endless loop.
Calling a template by a name in a string
When the template to call is only known while the program runs, put its full name in a string variable and call the variable. A function needs a cast with its return type in front:
fn := "max@function";
n := (integer) fn(3, 4);
fn := "tell_all@myzone";
fn("Hello");
No external declaration is needed. boards.zon calls a function whose name is kept in an extra this way: (string) u.extra.["$BOARD_P_RES"].descr(self, u).
- The arguments are only checked when the call is made. A template that doesn't exist, or a wrong number or type of arguments, stops the program with "Error in symbolic remote call" in the zone's log.
- intlist arguments don't work through a string call (a bug: the call is refused); stringlists and the other types do.
dilcall("name@zone")(u, i, s) is another way, for functions that take exactly a unitptr, an integer and a string and return an integer; quests.zon uses it to run the check function named in a quest's data.
Templates as player commands
A command in vme/etc/commands.def with func = do_name@zone runs that template when a player (or an NPC with exec()) types it. It takes one string argument, the rest of the line, self is the character who typed it, and it ends with quit. getword() takes the words off the argument one at a time.
Example
dilbegin integer count_items(u : unitptr);
var
it : unitptr;
n : integer;
code
{
it := u.inside;
while (it != null)
{
if (it.type == UNIT_ST_OBJ)
n := n + 1 + count_items(it);
it := it.next;
}
return (n);
}
dilend
dilbegin report(pc : unitptr, n : integer);
code
{
sendtext("You carry " + itoa(n) + " things, counting what is inside them.<br/>", pc);
return;
}
dilend
dilbegin do_mycount(arg : string);
external
integer count_items(u : unitptr);
report(pc : unitptr, n : integer);
var
n : integer;
fn : string;
code
{
n := count_items(self);
report(self, n);
fn := "max@function";
n := (integer) fn(n, 10);
if (n == 10)
sendtext("You could carry more.<br/>", self);
quit;
}
dilend
count_items is a recursive function that counts the objects a unit holds, inside containers too; report is a procedure; do_mycount is a player command that calls both, and calls max@function through a string.
See also
quit
Procedure. Ends the program for good.
quit;
The program stops at once and is removed from its unit. It doesn't run again; a new copy only comes with a new unit (a reset) or a dilcopy.
Notes
- Inside a procedure or function called as
name@zone(...),quitends the whole program, the caller included. Usereturnto leave only the called template. - Its secures, interrupts and
priorityend with it. - A
blockbeforequitstill blocks the event. - A program that should run again for the next event goes back to waiting (
gototo a label before itswait) instead.
Example
dilbegin follow_note();
code
{
if (not self.master)
quit;
act("You now follow $3n.", A_ALWAYS, self, null, self.master, TO_CHAR);
quit;
}
dilend
Does its one job and ends; with no one to follow it ends at once. Adapted from basemove.zon.
See also
return
Instruction.
return; return (expression);
Ends the template that is running and goes back to the one that called it, which carries on after the call. A procedure (a template without a return type) uses return;. A function (dilbegin integer name(...), dilbegin string ...) must use return (value);, and the call gives that value.
Notes
- vmc checks the form:
return;in a function gives the error "no return expression expected" (meaning one is required), andreturn (x);in a procedure, or with a value of another type, gives "return expression not of correct type". - The value must have exactly the template's type.
return (null);doesn't compile in aunitptrfunction; return a unit variable that is null instead. - In a program that wasn't called by another (one started by
dilcopyor on a unit),returnends the program, asquitdoes. - Returning ends the template's
secure()s andinterrupt()s, and frees its local variables. A string, stringlist or intlist value is copied to the caller. - A function's result can't be passed straight into another DIL template call as an argument; put it in a variable first. Built-in functions such as
itoa()take it directly.
Example
dilbegin unitptr firstpc(room : unitptr);
var
u : unitptr;
code
{
u := room.inside;
while (u != null)
{
if (u.type == UNIT_ST_PC)
return (u);
u := u.next;
}
return (u);
}
dilend
dilbegin greetpc(u : unitptr);
code
{
if (u == null)
return;
act("Welcome, $1n.", A_SOMEONE, u, null, null, TO_CHAR);
return;
}
dilend
dilbegin greeter();
external
unitptr firstpc@ex(room : unitptr);
greetpc@ex(u : unitptr);
var
pc : unitptr;
code
{
heartbeat := PULSE_SEC * 10;
:start:
pause;
pc := firstpc@ex(self.outside);
greetpc@ex(pc);
goto start;
}
dilend
A function that returns the first player in a room (or null), and a procedure that returns early when there is nobody to greet.
See also
return
Instruction. Leaves a procedure, or a function with its value.
return; return(value);
return; leaves a procedure (a template without a return type) and goes on in the
template that called it. return(value); leaves a function and gives
value to the caller; the value must have the type the function was declared
with (dilbegin integer f(...)).
In the template a unit runs (the one copied onto it with dilcopy) there is no
caller, and return; ends the program like quit.
Notes
- vmc checks the form:
return;in a function gives "no return expression expected",return(x);in a procedure, or with a value of the wrong type, "return expression not of correct type". return(null);doesn't compile in aunitptrfunction:nullhas a type of its own. Return a unit variable that is null instead (see the example on while()).- If the value fails at run time (a field of a null unit, e.g.
return(u.level);withunull),vme.logsays "DIL: Error return types do not match." and the whole program stops. Test for null first. - quit in a procedure or function doesn't return: it ends the whole program, callers too.
- Secures made in the template end when it returns.
- A string or a list is copied for the caller.
Example
dilbegin integer is_mortal(u : unitptr);
code
{
if (u.type != UNIT_ST_PC)
return(FALSE);
return(u.level < IMMORTAL_LEVEL);
}
dilend
dilbegin greet_mortal(u : unitptr);
external
integer is_mortal(u : unitptr);
var
i : integer;
code
{
i := is_mortal(u);
if (i == FALSE)
return; // back to the caller
exec("bow " + u.name, self);
return;
}
dilend
A function that tells whether a unit is a mortal player, and a procedure that leaves early when it isn't.
See also
A field is a value stored in a unit, an extra description, a zone or a command, read with a dot: self.name, activator.hp, self.outside.title. Fields can be chained, and a field of null, or one the unit doesn't have, fails: the program goes on, but the value counts as false in every comparison.
A field marked read/write can be assigned: self.hp := 10;. A read-only one can't (vmc says "Illegal lvalue"); many of those are changed with a procedure instead, as the field's page says. Fields that hold a list are indexed: pc.skills[SKI_SEARCH], room.exit_to[NORTH].
The tables are by the kind of unit that has the field. A unit has the fields of "All units" as well; a player or an NPC also has the "Characters" fields. Using a field on a unit that doesn't have it fails, the same as a field of null.
Contents
- 1 Templates
- 2 Where DIL is written
- 3 The parts of a template
- 4 How a program runs
- 5 Compiling
- 6 A complete example
- 7 See also
- 8 The eight types
- 9 Values and copies
- 10 What a variable keeps
- 11 Truth values
- 12 Failed values
- 13 Converting between types
- 14 Comparing
- 15 See also
- 16 string
- 17 stringlist
- 18 integer
- 19 integerlist
- 20 extraptr
- 21 cmdptr
- 22 unitptr
- 23 zoneptr
- 24 SFB_CMD
- 25 SFB_DONE
- 26 SFB_TICK
- 27 SFB_COM
- 28 SFB_DEAD
- 29 SFB_MSG
- 30 SFB_PRE
- 31 cmdstr
- 32 excmdstr
- 33 excmdstr_case
- 34 self
- 35 activator
- 36 target
- 37 medium
- 38 power
- 39 argument
- 40 heartbeat
- 41 null
- 42 weather
- 43 realtime
- 44 mudhour, mudday, mudmonth, mudyear
- 44.1 Notes
- 44.2 Example
- 44.3 See also
- 44.4 Statements and blocks
- 44.5 Choosing: if and else
- 44.6 Looping: while and foreach
- 44.7 Jumping: labels and goto
- 44.8 Waiting
- 44.9 Keeping a unit: secure
- 44.10 Reacting to events at any time: interrupt and on_activation
- 44.11 Stopping commands and other programs: block and priority
- 44.12 Ending
- 44.13 The limit on statements
- 44.14 Example
- 44.15 See also
- 45 if()
- 46 goto
- 47 while
- 48 break
- 49 continue
- 50 foreach()
- 50.1 Parameters
- 50.2 Notes
- 50.3 Example
- 50.4 See also
- 50.5 What can be assigned
- 50.6 Fields that need a trusted zone
- 50.7 Integers stored in fewer bits
- 50.8 Copies
- 50.9 When the value fails
- 50.10 Assigning null
- 50.11 Arguments and globals
- 50.12 Example
- 50.13 See also
- 50.14 What an expression is made of
- 50.15 Precedence
- 50.16 Truth
- 50.17 Failed values
- 50.18 Evaluation
- 50.19 Example
- 50.20 See also
- 50.21 Precedence
- 50.22 Arithmetic
- 50.23 Comparison
- 50.24 Logic
- 50.25 Bits
- 50.26 in
- 50.27 Example
- 50.28 See also
- 51 in
- 52 string in string
- 53 string in stringlist
- 54 string in extraptr
- 55 quit
- 56 return
- 57 return
- 58 extraptr
- 59 unitptr
- 60 UNIT_ST_OBJ
- 61 UNIT_ST_ROOM
- 62 UNIT_ST_PC and UNIT_ST_NPC
- 63 UNIT_ST_NPC
- 64 UNIT_ST_PC
- 64.1 Fields
- 64.2 Notes
- 64.3 Example
- 64.4 See also
- 64.5 Strings
- 64.6 Numbers and bits
- 64.7 Finding units
- 64.8 Making and testing units
- 64.9 Characters and combat
- 64.10 Spells, skills and weapons
- 64.11 Money
- 64.12 Players
- 64.13 Files
- 64.14 Time
- 64.15 Events and messages
- 64.16 DIL programs
- 64.17 See also
- 65 asctime()
- 66 strcmp()
- 67 strncmp()
- 68 textformat()
- 69 spellindex()
- 70 spellinfo()
- 71 beginedit()
- 72 cancarry()
- 73 fits()
- 74 replace()
- 75 restore()
- 76 meleeattack()
- 77 meleedamage()
- 78 mid()
- 79 moneystring()
- 80 equipment()
- 81 tolower()
- 82 toupper()
- 83 visible()
- 84 opponent()
- 85 purse()
- 86 atoi()
- 87 check_password()
- 88 command()
- 89 delstr()
- 90 delunit()
- 91 dildestroy()
- 92 dilfind()
- 93 itoa()
- 94 isaff()
- 95 islight()
- 96 isplayer()
- 97 isset()
- 98 paycheck()
- 99 findunit()
- 100 findrndunit()
- 101 filesize()
- 102 findroom()
- 103 findsymbolic()
- 104 getword()
- 105 getwords()
- 106 ghead()
- 107 split()
- 108 left()
- 109 length()
- 110 load()
- 111 loadstr()
- 112 openroll()
- 113 pathto()
- 114 pagestring()
- 115 right()
- 116 rnd()
- 116.1 Parameters
- 116.2 Returns
- 116.3 Notes
- 116.4 Example
- 116.5 See also
- 116.6 Strings, lists and bits
- 116.7 Text to players
- 116.8 Messages between programs
- 116.9 Waiting and events
- 116.10 DIL programs
- 116.11 Moving and changing units
- 116.12 Characters and combat
- 116.13 Players and the server
- 116.14 See also
- 117 follow()
- 118 flog()
- 119 logcrime()
- 120 acc_modify()
- 121 strdir()
- 122 set_password()
- 123 store()
- 124 position_update()
- 125 send done()
- 126 send_pre()
- 127 set()
- 128 unset()
- 129 addcolor()
- 130 delcolor()
- 131 getcolor()
- 132 changecolor()
- 133 gamestate()
- 134 addextra()
- 135 addstring()
- 136 subextra()
- 137 substring()
- 138 stop_fighting()
- 139 subaff()
- 140 addaff()
- 141 destroy()
- 142 walkto()
- 143 link()
- 144 weapon name()
- 145 weapon_info()
- 146 skill name()
- 147 reboot
- 148 killedit()
- 149 experience()
- 150 act()
- 151 exec()
- 152 wait()
- 153 savestr()
- 154 remove()
- 155 reset_level()
- 156 reset_vlevel()
- 157 reset race()
- 158 secure()
- 159 unitdir()
- 160 unsecure()
- 161 block
- 162 priority
- 163 nopriority
- 164 addequip()
- 165 unequip()
- 166 delete_player()
- 167 dilcopy()
- 168 sendtext()
- 169 change_speed()
- 170 transfermoney()
- 171 set_fighting()
- 172 setweight()
- 173 setbright()
- 174 log()
- 175 send()
- 176 sendto()
- 177 sendtoall()
- 178 sendtoalldil()
- 179 cast_spell()
- 180 attack_spell()
- 181 insert()
- 182 interrupt()
- 183 clear()
- 184 on_activation()
All units
Every unit has these: rooms, objects, NPCs and players.
| Field | Type | Access | What it holds |
|---|---|---|---|
| alignment | integer | read/write | How good or evil the unit is, from -1000 (evil) to 1000 (good). |
| baseweight | integer | read-only | The weight of the unit itself, in pounds, without anything it carries or contains: an empty bag, a character's body. |
| bright | integer | read-only | How much light the unit gives off: positive for a light source (a lit torch), negative for something that swallows light, 0 for most units. |
| capacity | integer | read/write | How much the unit can hold inside it, in pounds: the capacity line in the zone file, 0 when it has none.
|
| editing | integer | read-only (meaningful for PC) | TRUE while the player is writing in the text editor (a board post, a letter, a beginedit() text), FALSE otherwise. |
| extra | extraptr | read-only | The first of the unit's extra descriptions, or null when it has none. |
| flags | integer | read/write | The unit flags, a bit set of UNIT_FL_* values from vme.h, shared by all kinds of unit.
|
| gnext | unitptr | read-only | The next unit in the game's global list of all units, or null after the last. |
| gprevious | unitptr | read-only | The unit before u in the game's global list of all units, or null for the first.
|
| hasfunc | integer | read-only | TRUE when the unit has at least one program attached, a DIL program or one of the server's special functions; FALSE when it has none. |
| height | integer | read/write | The size of a unit, set with height in the zone file.
|
| hp | integer | read/write | The unit's current hit points. |
| idx | integer | read-only | A number that tells one unit from another with the same symname. |
| illum | integer | read-only | The part of a unit's bright that comes from what is inside it. |
| inside | unitptr | read-only | The first unit inside u, or null when it is empty.
|
| inside_descr | string | read/write | What is seen from inside the unit. |
| key | string | read/write (used on objects) | The key that locks and unlocks the unit, as "keyname@zone", set with key in the zone file.
|
| light | integer | read-only | The light level inside the unit. |
| loadcount | integer | read-only | How many units made from the same definition (the same nameidx@zoneidx) are in the game right now, this one included.
|
| manipulate | integer | read/write (used on objects) | What players can do with the unit, a bit set of MANIPULATE_* values from vme.h.
|
| max_hp | integer | read/write ¹ | The unit's maximum hit points; hp holds the current ones. |
| minv | integer | read/write | The unit's wizard invisibility level. |
| name | string | read-only | The unit's first name (the first of its names); for a player, the player's name.
|
| nameidx | string | read-only | The unit's name in its zone file: "cityguard" for cityguard@midgaard.
|
| names | stringlist | read/write | The names players use for the unit; the first is its name. |
| next | unitptr | read-only | The next element of the list the value is in, or null after the last one. |
| opendiff | integer | read/write (used on containers) | How hard the unit's lock is to pick. |
| openflags | integer | read/write (used on containers and other units that open) | Whether the unit opens, and whether it is closed or locked: a bit set of EX_* values from vme.h.
|
| outside | unitptr | read-only | The unit that u is in.
|
| outside_descr | string | read/write | The line a unit shows when it is seen from outside. |
| spells | integer | read/write ¹ | A character's skill in spell i; for an object or a room, its magic resistance.
|
| symname | string | read-only | The unit's symbolic name, "nameidx@zoneidx": "corpse@death", or "papi@_players" for a player.
|
| title | string | read/write | The unit's title: for an object or an NPC, the short name the game's messages use. |
| type | integer | read-only | What kind of unit it is: a UNIT_ST_* constant.
|
| weight | integer | read-only | The total weight of the unit in pounds: its own weight (baseweight) plus everything inside it. |
| zone | string | read-only | The name of the zone the unit is in now: the zone of the room at the top of whatever holds it. |
| zoneidx | string | read-only | The name of the zone the unit's definition comes from: "midgaard" for cityguard@midgaard.
|
Characters
NPCs and players (UNIT_ST_NPC, UNIT_ST_PC).
| Field | Type | Access | What it holds |
|---|---|---|---|
| abilities | integer | read/write ¹ | One of the character's abilities. |
| attack_type | integer | read/write | The weapon type a character fights with when not wielding a weapon. |
| charflags | integer | read/write | The character flags: a bit field of CHAR_* values, defined in vme.h.
|
| defensive | integer | read/write | A flat bonus (or, below 0, penalty) to the character's defence. |
| endurance | integer | read/write | A character's current endurance: the points that moving, fighting and some skills use up. |
| exp | integer | read/write ¹ | On a player, the experience points gained in total; on an NPC, the experience it is worth. |
| fighting | unitptr | read-only | The character this character is hitting in melee: its current opponent. null when it is not fighting. |
| follower | unitptr | read-only | The first character that follows ch, or null when no one does.
|
| followercount | integer | read-only | How many characters follow this one directly: not their own followers. 0 when none. |
| level | integer | read/write ¹ | The character's level. |
| mana | integer | read/write | A character's current mana: the points that spells cost. |
| master | unitptr | read-only | The character that ch follows, or null when it follows no one.
|
| max_endurance | integer | read-only | The most endurance the character can have. |
| max_mana | integer | read-only | The character's maximum mana; mana holds the current amount. |
| natural_armour | integer | read/write | The armour type of a character's own skin, used where no worn armour covers the spot that is hit. |
| offensive | integer | read/write | A flat bonus (or, below 0, penalty) to the character's attacks. |
| opponentcount | integer | read-only | How many characters this one is in combat with. |
| position | integer | read/write | The character's position, a POSITION_* constant from vme.h.
|
| race | integer | read/write | The character's race, a RACE_ constant from values.h.
|
| sex | integer | read/write | The character's sex: SEX_NEUTRAL (0), SEX_MALE (1) or SEX_FEMALE (2), from vme.h.
|
| speed | integer | read-only | The character's combat speed: lower is faster. |
| switched | unitptr | read-only | Who is controlled through a switch.
|
| weapons | integer | read/write ¹ | A character's skill, in percent, with a weapon. |
Players
Players only (UNIT_ST_PC), besides the character fields.
| Field | Type | Access | What it holds |
|---|---|---|---|
| ability_costs | integer | read-only | The player's racial modifier for training ability i.
|
| ability_levels | integer | read/write ¹ | How many times the player has trained ability i since the last level gained.
|
| ability_points | integer | read/write | The player's unspent ability points: training an ability (strength, dexterity, ...) at a teacher costs them. |
| acc_balance | integer | read-only | The credit left on the player's account, in coin units, when the game runs with accounting. |
| acc_total | integer | read-only | The total credit paid in to the player's account to date, in coin units, when the game runs with accounting. |
| birth | integer | read/write | When the player was born, in real seconds since 1970 like realtime. |
| crimes | integer | read/write | A count of the crimes the player has been charged with, saved with the player. |
| drunk | integer | read/write | How drunk the player is: 0 is sober. |
| exptol | integer | read-only | The experience a player still needs for the next level. |
| full | integer | read/write | How well fed the player is. |
| guild | string | read/write | The name of the player's main (default) guild, e.g. "Udgaard Fighter".
|
| hometown | string | read/write | The symbolic name of the player's home room, such as "temple@udgaard".
|
| info | extraptr | read-only | A player's administrative extra descriptions. |
| lastroom | unitptr | read-only | Meant to give the room the server will put the player back in: the room the player was in when last saved, or when the connection was lost. |
| lifespan | integer | read/write ¹ | How old, in mud years, the player can grow. |
| pcflags | integer | read/write | A player's option and status bits. |
| playtime | integer | read-only | How long the player has been logged in, in total, in real seconds. |
| profession | integer | read/write ¹ | The player's profession: a PROFESSION_ constant from values.h, PROFESSION_FIGHTER to PROFESSION_BARBARIAN.
|
| prompt | string | read/write | The player's prompt template, as set with the prompt command.
|
| quests | extraptr | read-only | The player's quest list: a list of extras, like .extra, saved with the player.
|
| skill_costs | integer | read-only | Despite the name, not a price: the player's racial modifier for the skill with that index, from -3 to +3. |
| skill_levels | integer | read/write ¹ | How many times the player has trained the skill with that index since gaining the current level. |
| skill_points | integer | read/write | The player's unspent skill points. |
| skills | integer | read/write ¹ | A player's skill, in percent, in the skill with that index. |
| spell_costs | integer | read-only | How easy spell i is for the player's race to learn.
|
| spell_levels | integer | read/write ¹ | How many times the player has practised spell i since the last level gained.
|
| thirst | integer | read/write | How well watered the player is. |
| vlevel | integer | read/write ¹ | The player's virtual level. |
| weapon_costs | integer | read-only at run time | The player's race modifier for the weapon idx, from the race <name> = N lines in vme/etc/weapons.def.
|
| weapon_levels | integer | read/write ¹ | How many times the player has trained the weapon idx since gaining the current level.
|
NPCs
NPCs only (UNIT_ST_NPC), besides the character fields.
| Field | Type | Access | What it holds |
|---|---|---|---|
| defaultpos | integer | read/write | An NPC's default position, a POSITION_* constant from vme.h.
|
| npcflags | integer | read/write | An NPC's NPC flags, a bit field set in the zone file with npcflags {...} in the mobile.
|
Objects
Objects only (UNIT_ST_OBJ).
| Field | Type | Access | What it holds |
|---|---|---|---|
| cost | integer | read/write | What the object is worth, in the money's base unit (an iron piece is IRON_MULT, 10; a gold piece GOLD_MULT; vme.h).
|
| equip | integer | read-only | Where the object is worn or held. |
| objectflags | integer | read/write | The object's flags, set with romflags in the object's zone definition (flags there sets the unit flags).
|
| objecttype | integer | read/write | What kind of object it is: one of the ITEM_* constants in vme.h.
|
| rent | integer | read/write | What the object costs its owner to keep, per real day, in the money's base unit (as cost). |
| value | integer | read/write | The object's five numbers, value[0] to value[4], set with value[i] lines in the zone file.
|
Rooms
Rooms only (UNIT_ST_ROOM).
| Field | Type | Access | What it holds |
|---|---|---|---|
| exit_diff | integer | read/write | The difficulty of the room's exit in direction dir, set with difficulty on the exit in the zone file (0 to 250).
|
| exit_info | integer | read/write | The flags of the exit in direction dir: whether it has a door and what state it is in.
|
| exit_key | string | read/write | The key that locks and unlocks the room's exit in direction dir, as "keyname@zone" in lower case, set with key on the exit in the zone file.
|
| exit_names | stringlist | read/write | The names of the door or opening in direction dir: what a player types to open, close, lock or unlock it.
|
| exit_to | unitptr | read-only | The room that the exit in direction dir leads to, or null when the room has no exit that way.
|
| mapx | integer | read-only | The room's X coordinate on the graphical map, set with gmap(x, y) in the zone file; -1 when the room has none.
|
| mapy | integer | read-only | The room's Y coordinate on the graphical map, set with gmap(x, y) in the zone file; -1 when the room has none.
|
| movement | integer | read/write | The room's terrain, set with movement in the zone file.
|
| roomflags | integer | read/write | Bit flags of a room, set with romflags in the zone file.
|
extraptr
Fields of an extra description (an extraptr).
| Field | Type | Access | What it holds |
|---|---|---|---|
| descr | string | read/write | The text of an extra description: what a player sees on look at the extra's name.
|
| name | string | read-only | The extra description's first name (keyword). |
| names | stringlist | read/write | The keywords the extra description answers to. |
| next | extraptr | read-only | The next element of the list the value is in, or null after the last one. |
| vals | intlist | read/write | The list of integers kept with an extra description. |
zoneptr
Fields of a zone.
| Field | Type | Access | What it holds |
|---|---|---|---|
| access | integer | read-only | The zone's access level: the fourth column of vme/etc/zonelist, 0 to 255, where 0 is the most trusted.
|
| creators | stringlist | read/write | The names of the zone's creators. |
| fname | string | read-only | The zone's name, the same as name on a zoneptr: "midgaard".
|
| help | string | read-only in practice | The zone's help text for players: the help text in the zone file's %zone header.
|
| loadlevel | integer | read-only | The level a god needs to load objects and NPCs from the zone, unless the god's name is in the zone's creators.
|
| name | string | read-only | The zone's name, as in sym@zone.
|
| next | zoneptr | read-only | The next element of the list the value is in, or null after the last one. |
| notes | string | read-only in practice | The zone's notes from its creators: the notes text in the zone file's %zone header.
|
| npccount | integer | read-only | Meant to be the number of NPCs the zone defines, but the server never counts them: it is always 0. |
| npcs | unitptr | read-only | A copy, in the game, of the zone's NPC whose symbolic name sorts first. |
| objcount | integer | read-only | Meant to be the number of objects the zone defines, but the server never counts them: it is always 0. |
| objs | unitptr | read-only | A copy, in the game, of the zone's object whose symbolic name sorts first. |
| payonly | integer | read-only | Whether the zone is only for paying players: the sixth column of vme/etc/zonelist (0 when missing).
|
| resetmode | integer | read-only | How the zone resets, as set with reset in the zone file's %zone header.
|
| resettime | integer | read-only | The minutes between two resets of the zone. |
| roomcount | integer | read-only | The number of rooms the zone defines: the rooms read from its .data file at boot.
|
| rooms | unitptr | read-only | One room of the zone: the one whose symbolic name sorts first. |
| title | string | read-only in practice | The zone's title, from title in its %zone header.
|
cmdptr
Fields of a command from the game's command table.
| Field | Type | Access | What it holds |
|---|---|---|---|
| level | integer | read-only in practice | The lowest level that may use the command. |
| loglevel | integer | read-only | The loglevel a command has in vme/etc/commands.def.
|
| name | string | read-only | The command's full name, such as "wiz".
|
| next | cmdptr | read-only | The next element of the list the value is in, or null after the last one. |
| position | integer | read/write | The lowest position in which the command can be used. |
| speed | integer | read-only | The command's combat speed, from turns in commands.def.
|
| type | integer | read-only | The command's type: TYPE_SOCIAL, TYPE_SKILL or 0 for an ordinary command.
|
¹ Fields only zones with access level 0 can assign
Some fields that decide a player's strength can be assigned only by a program in a zone with access level 0 (the fourth column of vme/etc/zonelist, as for basis.zon). What counts is the zone of the program running on the unit, not that of a function it calls. In other zones vmc accepts the assignment, but at run time the program logs "DIL SERIOUS: ... Type error in lvalue assignemt" and stops. Reading works in every zone.
- On players only (NPCs can be changed from any zone): abilities, level, max_hp, spells, weapons.
- On players and NPCs alike, wherever the field exists: ability_levels, exp, lifespan, profession, skill_levels, skills, spell_levels, vlevel, weapon_levels.
Money in a player's account (acc_balance, acc_total) can't be assigned at all; acc_modify() changes it, again only from a zone with access level 0.
See also
- Data Types
- unitptr, extraptr, zoneptr, cmdptr
- Built-In Procedures, for changing what a field can't
extraptr
Type. A pointer to an extra description.
var exd : extraptr;
Extra descriptions are the texts a unit shows when looked at (look at sign), and DIL also uses them to store data on units: quest flags, counters, settings. look doesn't show an extra whose first name starts with $, so such names hold data. Each extra has these fields:
| Field | Type | Meaning |
|---|---|---|
| names | stringlist | the names it is found by |
| name | string | the first of the names |
| descr | string | its text (read and write) |
| vals | intlist | numbers stored with it |
| next | extraptr | the next extra on the same unit |
u.extra is the first extra of a unit. To find one by name, use "name" in u.extra or u.extra.["name"]; both give null when there is none.
Notes
- An extraptr variable is cleared at every wait (
wait,pause, a heartbeat), and it can't be secured. Look the extra up again after waiting. - A field of a null extraptr fails; test
exd == nullfirst. addextra()andsubextra()add and remove extras. An extra made with empty text is not added.- Extras themselves are saved with the unit; extraptr variables are not (they come back null).
Example
dilbegin visit_count();
var
pc : unitptr;
exd : extraptr;
code
{
:start:
wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC)
and (activator.outside == self));
pc := activator;
exd := "$visits" in pc.extra;
if (exd == null)
{
addextra(pc.extra, {"$visits"}, "1");
sendtext("Welcome, stranger.<br/>", pc);
}
else
{
exd.descr := itoa(atoi(exd.descr) + 1);
sendtext("Welcome back, visit number " + exd.descr + ".<br/>", pc);
}
goto start;
}
dilend
On a room: counts each player's visits in a hidden extra on the player.
See also
unitptr
Type. A pointer to a unit: a room, an object, an NPC or a player.
var u : unitptr;
Through a unitptr a program reads and changes a unit's fields (u.name, u.hp, u.outside...), and hands the unit to functions and procedures. u.type says which kind of unit it is: UNIT_ST_ROOM, UNIT_ST_OBJ, UNIT_ST_NPC or UNIT_ST_PC. Which fields a unit has depends on that type.
A unitptr is null or points to a unit. Built-in variables such as self, activator, medium and target are unitptrs, and so are the results of findunit(), findroom(), findsymbolic() and load().
Notes
- A unitptr variable is cleared at every wait. When the program wakes from
wait,pauseor a heartbeat, every unitptr variable is null again, unless that unit issecured. Find the unit again after waiting, or secure it.selfis always the program's own unit. - A field of a null unit fails, and a failed value is false in every comparison:
u.level > 5andu.level <= 5are both false whenuis null. Testu == null(ornot u) first, on its own:anddoesn't stop early. - A field on a call's result is a syntax error:
findroom(s).titledoesn't compile. Put the unit in a variable first. ==and!=tell whether two unitptrs point to the same unit.- Units in a room (or carried, or in a container) form a list:
u.insideis the first one,.nextthe next. When the loop moves or destroys units, useforeachinstead. - unitptr variables are not saved with a unit: after loading they are null.
Example
dilbegin do_count(arg : string);
var
u : unitptr;
pcs, others, things : integer;
code
{
u := self.outside.inside;
while (u != null)
{
if (u.type == UNIT_ST_PC)
pcs := pcs + 1;
else if (u.type == UNIT_ST_NPC)
others := others + 1;
else if (u.type == UNIT_ST_OBJ)
things := things + 1;
u := u.next;
}
sendtext("Here: " + itoa(pcs) + " players, " + itoa(others) + " others and "
+ itoa(things) + " things.<br/>", self);
quit;
}
dilend
A command that counts the players, NPCs and objects in the room (npcs and objs are reserved words, so the variables have other names).
See also
UNIT_ST_OBJ
Constant (integer, vme.h: 0x08).
An object: a weapon, a container, a key, money, a corpse. u.type == UNIT_ST_OBJ. The type of a unit is in its type field; the four unit types are bits, so they can be combined with |.
Fields
Only objects have: objecttype, value, objectflags, cost, rent, equip. What the five value[] numbers mean depends on objecttype (ITEM_* in values.h).
Notes
- Every unit, whatever its type, has the general fields: name, names, title, descr, outside_descr, inside_descr, extra, type, symname, nameidx, zoneidx, zone, key, outside, inside, next, gnext, gprevious, flags, manipulate, openflags, opendiff, weight, baseweight, capacity, height, light, bright, illum, minv, alignment, hp, max_hp, loadcount, hasfunc, spells.
spells[]on an object is its magic resistance; the index is not used.- An object that is worn has a
equipposition other than 0;addequip()andunequip()change it. - Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
Example
dilbegin integer pricey(obj : unitptr);
code
{
if (obj.type != UNIT_ST_OBJ)
return (FALSE);
return (obj.cost > 10000);
}
dilend
Tells whether a unit is an expensive object.
See also
UNIT_ST_ROOM
Constant (integer, vme.h: 0x04).
A room. u.type == UNIT_ST_ROOM. The type of a unit is in its type field; the four unit types are bits, so they can be combined with |.
Fields
Only rooms have: exit_names, exit_info, exit_key, exit_diff, exit_to, roomflags, movement, mapx, mapy. The exit fields take a direction as index, from NORTH (0) to MAX_EXIT (9) (vme.h).
Notes
- Every unit, whatever its type, has the general fields: name, names, title, descr, outside_descr, inside_descr, extra, type, symname, nameidx, zoneidx, zone, key, outside, inside, next, gnext, gprevious, flags, manipulate, openflags, opendiff, weight, baseweight, capacity, height, light, bright, illum, minv, alignment, hp, max_hp, loadcount, hasfunc, spells.
spells[]on a room is its magic resistance; the index is not used.- A room can be inside another room.
self.outsideof a room is the room around it, or null. - Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
Example
dilbegin integer exits(room : unitptr);
var
i : integer;
n : integer;
code
{
if (room.type != UNIT_ST_ROOM)
return (0);
i := 0;
n := 0;
while (i <= MAX_EXIT)
{
if (room.exit_to[i] != null)
n := n + 1;
i := i + 1;
}
return (n);
}
dilend
Counts a room's exits.
See also
UNIT_ST_PC and UNIT_ST_NPC
Constants (integer, vme.h: 0x02 and 0x01).
Characters: players (UNIT_ST_PC) and monsters (UNIT_ST_NPC). Test for both with u.type & (UNIT_ST_PC | UNIT_ST_NPC); the same mask works in foreach and findunit(). The type of a unit is in its type field; the four unit types are bits, so they can be combined with |.
Fields
Every character has: abilities, attack_type, charflags, defensive, endurance, exp, exptol, fighting, follower, followercount, level, mana, master, max_endurance, max_mana, natural_armour, offensive, opponentcount, position, race, sex, speed, switched, weapons. Players have more fields (see UNIT_ST_PC), and monsters two of their own (see UNIT_ST_NPC).
Notes
- Every unit, whatever its type, has the general fields: name, names, title, descr, outside_descr, inside_descr, extra, type, symname, nameidx, zoneidx, zone, key, outside, inside, next, gnext, gprevious, flags, manipulate, openflags, opendiff, weight, baseweight, capacity, height, light, bright, illum, minv, alignment, hp, max_hp, loadcount, hasfunc, spells.
dex_redcompiles but has no value: reading it stops the program with "unknown field type" in the log.spells[]exists on every unit, but holds spell skills only on characters.- Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
Example
dilbegin countchars();
var
u : unitptr;
n : integer;
code
{
n := 0;
foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
n := n + 1;
log(itoa(n) + " characters around " + self.name);
quit;
}
dilend
Counts the players and monsters around the unit.
See also
UNIT_ST_NPC
Constant (integer, vme.h: 0x01).
A non-player character: a monster, a shopkeeper, a guard. u.type == UNIT_ST_NPC. The type of a unit is in its type field; the four unit types are bits, so they can be combined with |.
Fields
Monsters have the fields of all characters (see UNIT_ST_PC and UNIT_ST_NPC) and these two, which only monsters have: defaultpos, npcflags.
Notes
- Every unit, whatever its type, has the general fields: name, names, title, descr, outside_descr, inside_descr, extra, type, symname, nameidx, zoneidx, zone, key, outside, inside, next, gnext, gprevious, flags, manipulate, openflags, opendiff, weight, baseweight, capacity, height, light, bright, illum, minv, alignment, hp, max_hp, loadcount, hasfunc, spells.
spells[]andweapons[]of a monster only go up to the group numbers (SPL_GROUP_MAX,WPN_GROUP_MAXminus one); a player's go up toSPL_TREE_MAXandWPN_TREE_MAXminus one.- Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
Example
dilbegin integer npcdefpos(npc : unitptr);
code
{
if (npc.type != UNIT_ST_NPC)
return (-1);
return (npc.defaultpos);
}
dilend
Gives a monster's default position, or -1 for anything else.
See also
UNIT_ST_PC
Constant (integer, vme.h: 0x02).
A player character. u.type == UNIT_ST_PC is true for a player, also one who is switched into a monster (the monster itself stays UNIT_ST_NPC). The type of a unit is in its type field; the four unit types are bits, so they can be combined with |.
Fields
Players have the fields of all characters (see UNIT_ST_PC and UNIT_ST_NPC) and these, which only players have: acc_balance, acc_total, ability_costs, ability_levels, ability_points, birth, crimes, drunk, editing, full, guild, hometown, idx, info, lastroom, lifespan, pcflags, playtime, profession, prompt, quests, skill_costs, skill_levels, skill_points, skills, spell_costs, spell_levels, thirst, vlevel, weapon_costs, weapon_levels.
Notes
- Every unit, whatever its type, has the general fields: name, names, title, descr, outside_descr, inside_descr, extra, type, symname, nameidx, zoneidx, zone, key, outside, inside, next, gnext, gprevious, flags, manipulate, openflags, opendiff, weight, baseweight, capacity, height, light, bright, illum, minv, alignment, hp, max_hp, loadcount, hasfunc, spells.
- In the global list all players come first:
ghead()starts with them, and a walk with.gnextcan stop at the first unit that isn'tUNIT_ST_PC. - On a player,
level,vlevel,exp,max_hp,profession,lifespan,abilities,skills,spells,weaponsand their*_levelscan only be assigned by a program in a zone with access level 0 (the fourth column ofvme/etc/zonelist). Elsewhere they can be read, but an assignment stops the program with a type error in the log. - Reading a field the unit doesn't have fails, and a failed value is false in every comparison: test the type first.
Example
dilbegin hungry(pc : unitptr);
code
{
if (pc.type != UNIT_ST_PC)
return;
if (pc.full < 4)
sendtext("Your stomach rumbles.<br/>", pc);
return;
}
dilend
Tells a player who is getting hungry; full exists only on players.
See also
A function computes a value and returns it, so it is used inside an expression: n := rnd(1, 6);. Functions that change things (such as load() or transfermoney()) return a value as well, and the value can be ignored. For writing your own functions, see Functions.
Each line gives the call with its arguments, the type of the value it returns, and what it does. Click a name for the full page: arguments, return values on failure, notes and an example that compiles. The Full Listing has every keyword on one page.
Strings
Text in and out of strings, and numbers as text.
| Function | Returns | What it does |
|---|---|---|
atoi(s : string) |
integer | The number written at the start of a string. |
itoa(i : integer) |
string | An integer written as text. |
length(s : string)length(sl : stringlist)length(il : intlist) |
integer | The length of a string, or the number of entries in a list. |
left(s : string, n : integer) |
string | Returns the first characters of a string. |
right(s : string, n : integer) |
string | Returns the last characters of a string. |
mid(s : string, first : integer, last : integer) |
string | Returns the characters from one position to another. |
getword(s : string) |
string | Takes the first word off a string. |
getwords(s : string) |
stringlist | Splits a string into its words. |
split(s : string, sep : string) |
stringlist | Cuts a string into pieces at a separator. |
replace(old : string, new : string, s : string) |
string | Replaces every occurrence of one text in a string with another. |
tolower(s : string) |
string | Returns a string in lower case. |
toupper(s : string) |
string | Returns a string in upper case. |
strcmp(s1 : string, s2 : string) |
integer | Compares two strings, minding upper and lower case. |
strncmp(s1 : string, s2 : string, n : integer) |
integer | Compares the first characters of two strings, minding upper and lower case. |
textformat(s : string) |
string | Turns the escapes \n and \r in a text into real line breaks.
|
Numbers and bits
| Function | Returns | What it does |
|---|---|---|
rnd(from : integer, to : integer) |
integer | A random whole number in a range. |
openroll(dice : integer, end : integer) |
integer | Rolls an open-ended die: high rolls add another roll, low rolls subtract one. |
isset(value : integer, bits : integer) |
integer | Tells whether any of some bits are set in an integer. |
Finding units
Units by name, symbolic name or kind, and the game's global lists.
| Function | Returns | What it does |
|---|---|---|
findunit(u : unitptr, s : string, flags : integer, list : unitptr)findunit(u : unitptr, s : string, flags : integer, list : unitptr, type : integer) |
unitptr | Finds a unit by name, the way commands find what a player names. |
findrndunit(u : unitptr, where : integer, types : integer) |
unitptr | Picks a random unit of the wanted kinds in one place. |
findroom(sym : string) |
unitptr | Finds a room by its symbolic name. |
findsymbolic(sym : string)findsymbolic(sym : string, idx : integer)findsymbolic(u : unitptr, sym : string, flags : integer) |
unitptr | Finds a unit by its symbolic name, the name@zone it was defined with.
|
findzone(zname : string) |
zoneptr | Finds a zone by its name. |
getcmd(s : string) |
cmdptr | Finds a command from its name or an abbreviation. |
ghead() |
unitptr | The first unit in the game's global unit list. |
global_head() |
unitptr | Another name for ghead(): the first unit in the game's global unit list.
|
npc_head() |
unitptr | The first NPC in the game's global unit list. |
obj_head() |
unitptr | The first object in the game's global unit list. |
pc_head() |
unitptr | The first player in the game's global unit list. |
room_head() |
unitptr | The first room in the game's global unit list. |
zhead() |
zoneptr | The first zone in the game. |
zone_head() |
zoneptr | Another name for zhead(): the first zone in the game.
|
chead() |
cmdptr | The first command in the game's command table. |
command_head() |
cmdptr | Another name for chead(): the first command in the game's command table.
|
Making and testing units
| Function | Returns | What it does |
|---|---|---|
load(sym : string) |
unitptr | Makes a new NPC or object from its zone definition. |
clone(u : unitptr) |
unitptr | Makes a copy of an existing NPC or object. |
equipment(ch : unitptr, pos : integer) |
unitptr | The object a character wears or wields in a given position. |
visible(ch : unitptr, u : unitptr) |
integer | Tells whether a character can see a unit. |
islight(u : unitptr) |
integer | Tells whether there is light in a room. |
fits(ch : unitptr, obj : unitptr, pos : integer) |
string | Tells whether an object is the right size for a character. |
can_carry(ch : unitptr, u : unitptr, n : integer) |
integer | Tells whether a character can carry more of something, and if not, why. |
pathto(from : unitptr, to : unitptr) |
integer | Gives the first step of the shortest way from one unit's room to another's. |
isaff(u : unitptr, id : integer) |
integer | Tells whether a unit carries an affect with a given id. |
getaffects(u : unitptr) |
stringlist | Lists the affects on a unit, one string of numbers each. |
Characters and combat
| Function | Returns | What it does |
|---|---|---|
meleeattack(att : unitptr, def : unitptr, bonus : integer, wtype : integer, primary : integer) |
integer | Makes a character attack another once in melee, starting a fight. |
meleedamage(att : unitptr, def : unitptr, bonus : integer, wtype : integer) |
integer | Makes a character strike another once, without first putting it into combat. |
opponent(ch : unitptr, vict : unitptr) |
integer | Tells whether two characters are fighting each other. |
getopponent(ch : unitptr, i : integer) |
unitptr | Gets one of a character's opponents by its place in the list. |
getfollower(ch : unitptr, i : integer) |
unitptr | Gets one of a character's followers by its place in the list. |
getinteger(what : integer, u : unitptr, i : integer) |
integer | Gets one of several numbers that the server computes, chosen by an index. |
Spells, skills and weapons
| Function | Returns | What it does |
|---|---|---|
attack_spell(spell : integer, caster : unitptr, medium : unitptr, target : unitptr, bonus : integer, effect : string) |
integer | Hits a target with an offensive spell and returns the damage. |
cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr, effect : string)cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr) |
integer (or none, as a procedure) | Casts a spell without mana or the caster's own casting. |
spellindex(s : string) |
integer | Finds a spell's number from its name or an abbreviation of it. |
spellinfo(i : integer, realm : integer, sphere : integer, mana : integer, offensive : integer, resist : integer, media : integer, targets : integer) |
string | Returns a spell's name and puts its properties in seven integer variables. |
skill_name(i : integer) |
string | Gives the name of a skill from its number. |
weapon_name(i : integer) |
string | Gives the name of a weapon type from its number. |
weapon_info(i : integer) |
intlist | The figures etc/weapons.def gives a weapon type. |
Money
| Function | Returns | What it does |
|---|---|---|
moneystring(amt : integer, verbose : integer) |
string | Writes an amount of money out in coins. |
purse(u : unitptr, coin : string) |
integer | Counts the coins of one kind that a unit carries. |
transfermoney(from : unitptr, to : unitptr, amount : integer) |
integer | Moves money from one character to another, or creates or destroys it. |
paycheck(pc : unitptr, place : unitptr) |
integer | Tells whether a player's account allows them into the zone of a unit. |
Players
| Function | Returns | What it does |
|---|---|---|
isplayer(pname : string) |
integer | Tells whether a player character of that name exists. |
check_password(pc : unitptr, pwd : string) |
integer | Tells whether a password is a player's password. |
getcolor(key : string) |
string | Returns the HTML tag that starts text in a named colour. |
addcolor(pc : unitptr, key : string, colour : string) |
integer | Gives a player their own colour for a colour name. |
changecolor(pc : unitptr, key : string, colour : string) |
integer | Changes one of a player's own colours. |
delcolor(pc : unitptr, key : string) |
integer | Removes one of a player's own colours. |
Files
Strings and units saved on the server, and the server's logs and programs.
| Function | Returns | What it does |
|---|---|---|
loadstr(filename : string, s : string) |
integer | Reads a whole file into a string variable. |
savestr(filename : string, s : string, mode : string) |
integer | Writes a string to a file, to read back later with loadstr(). |
delstr(filename : string) |
integer | Deletes a string file. |
strdir(pattern : string) |
stringlist | Lists the string files that DIL has saved, by a pattern. |
restore(filename : string, u : unitptr) |
unitptr | Loads units saved with store() back into the game. |
delunit(filename : string) |
integer | Deletes a unit file. |
unitdir(pattern : string) |
stringlist | Lists the unit files that DIL has stored, by a pattern. |
flog(filename : string, s : string, mode : string) |
integer | Writes a string to a file of its own in the server's log directory. |
shell(cmd : string) |
integer | Starts a program from the server's allow directory.
|
Time
| Function | Returns | What it does |
|---|---|---|
asctime(t : integer) |
string | Writes a time in seconds as a date, such as "Mon Nov 18 18:49:08 1996". |
Events and messages
Which event woke the program, and what other programs say.
| Function | Returns | What it does |
|---|---|---|
command(name : string)command(no : integer) |
integer | Tells whether the event that woke the program is a given command. |
interrupt(flags : integer, condition, label) |
integer | Sets up a jump to a label when a certain event wakes the program, whatever it is waiting for. |
on_activation(condition, label)on_activation(condition, skip) |
integer | Sets a check that runs every time the program is woken, by any event, before the event reaches the program's wait() or pause.
|
send_pre(cmd : string, who : unitptr, med : unitptr, tgt : unitptr, pwr : integer, arg : string, other : unitptr) |
integer | Asks the programs around a character whether a command may go ahead. |
sact(text : string, show : integer, a1 : unitptr or string, a2 : unitptr or string, a3 : unitptr or string, to : integer) |
string | Gives the text an act() would show, instead of sending it. |
DIL programs
Programs on units, and calling functions by name.
| Function | Returns | What it does |
|---|---|---|
dilfind(tmpl : string, u : unitptr) |
integer | Tells whether a unit runs a DIL program from a given template. |
dildestroy(tmpl : string, u : unitptr) |
integer | Stops a DIL program on a unit and removes it. |
dilcall(tmpl : string)(u : unitptr, i : integer, s : string) |
integer | Calls a DIL function whose name is only known when the program runs. |
See also
- Built-In Procedures
- Built-In Variables
- Fields
- Operators, for
and,or,notandin
asctime()
Function (string). Writes a time in seconds as a date, such as "Mon Nov 18 18:49:08 1996".
asctime(t : integer)
Converts t, a real-world time in seconds since 1 January 1970 (the value of
realtime), into a date and time in the server's time zone. It is
the C library's ctime() without the newline at the end.
Parameters
| Name | Type | Meaning |
|---|---|---|
| t | integer | Seconds since 1 January 1970, usually realtime or a value saved from it.
|
Returns
String: "Www Mmm dd hh:mm:ss yyyy", for instance "Sat Nov 14 09:05:31 2026".
It fails when the argument is a failed value.
Notes
- Give it a variable or an expression, never a bare number. vmc compiles
asctime(0)orasctime(3600 * 24)without its argument, and running that stops the server.asctime(realtime),asctime(t)orasctime(pc.birth)are fine.
- DIL integers are 32 bits, so dates after January 2038 can't be shown.
- For the time in the game world use mudhour(),
mudday() and the like.
Example
dilbegin bug_note(pc : unitptr, txt : string);
var
i : integer;
code
{
i := flog("bugs", pc.name + " " + asctime(realtime) + ": " + txt + "<br/>", "a");
sendtext("Thank you, it is noted.<br/>", pc);
quit;
}
dilend
Writes a player's report with the date and time into a log file, as the bug
command in commands.zon does.
See also
strcmp()
Function (integer). Compares two strings, minding upper and lower case.
strcmp(s1 : string, s2 : string)
DIL's == and != on strings ignore case ("Sofa" == "sofa" is
true). Use strcmp() when case matters, as with passwords: it compares the two strings byte by
byte, as the C function of that name does.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s1 | string | The first string. |
| s2 | string | The second string. |
Returns
Integer: 0 when the strings are the same, less than 0 when s1 sorts before
s2, more than 0 when after. Test the sign only: the value need not be -1 or 1.
A string variable that was never set counts as "". It fails when an argument is a
failed value.
Notes
- Capitals sort before small letters:
strcmp("Z", "a")is less than 0. - All of DIL's string comparisons ignore case:
==,!=,<,>,<=and>=. Only strcmp() and strncmp() mind it.
Example
dilbegin integer same_pwd(first : string, second : string);
code
{
return (strcmp(first, second) == 0);
}
dilend
Tells whether a password was typed the same way twice, capitals included, as the password
change in commands.zon checks with excmdstr_case.
See also
strncmp()
Function (integer). Compares the first characters of two strings, minding upper and lower case.
strncmp(s1 : string, s2 : string, n : integer)
Like strcmp(), but looks at no more than the first
n characters of each string. Use it to test how a string begins when case matters.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s1 | string | The first string. |
| s2 | string | The second string. |
| n | integer | How many characters to compare at most. |
Returns
Integer: 0 when the first n characters are the same (or both strings end sooner,
alike), less than 0 when s1 sorts before s2, more than 0 when after.
Test the sign only.
A string variable that was never set counts as "". It fails when a string
argument is a failed value.
Notes
n0 always gives 0. A negativencompares the whole strings.- A shorter string sorts first:
strncmp("ab", "abc", 3)is less than 0. - For a test that ignores case,
"word" in sandleft()with
== are simpler.
Example
dilbegin integer is_god_tag(s : string);
code
{
return (strncmp(s, "GOD:", 4) == 0);
}
dilend
Tells whether a text begins with the capitals GOD:, so that god:
doesn't count.
See also
textformat()
Function (string). Turns the escapes \n and \r in a text into real line breaks.
textformat(s : string)
Returns a copy of s in which each two-character sequence \n becomes a
newline and each \r a carriage return. It is the same translation vmc makes in the
strings of a zone file, so it only matters for text that comes from elsewhere at run time: a
file read with loadstr(), an extra, or what a player typed.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text. |
Returns
String: the translated copy. A string variable that was never set fails.
Notes
- Nothing else changes. The
&codes of old DikuMUD versions (&n,
&sand the like) and the player's settings play no part any more; text in the game is HTML, with<br/>for a new line.
- Any other backslash pair is kept as it is, and a doubled backslash is no escape:
\\n still gives a backslash and a newline.
Example
dilbegin show_motd(pc : unitptr);
var
err : integer;
motd : string;
code
{
err := loadstr("motd", motd);
if (err > 0)
sendtext(textformat(motd) + "<br/>", pc);
quit;
}
dilend
Reads the message of the day from its file and shows it to a player, as the login in basis.zon does.
See also
spellindex()
Function (integer). Finds a spell's number from its name or an abbreviation of it.
spellindex(s : string)
Looks for s among the spell names from spells.def and returns that spell's
number, the same number as its SPL_* constant (values.h, vme.h).
Every word may be abbreviated: "cu li wo" finds cure light wounds. Case doesn't
matter, and spaces in front are skipped.
The spell spheres are in the same list: numbers 0 to 11 (SPL_ALL to
SPL_EXTERNAL) are theory, divine sphere and so on to acid sphere.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The spell's name, whole or with its words abbreviated. |
Returns
Integer: the spell number, or -1 when no spell matches (also for "").
It fails when s is a string variable that was never set: i := spellindex(s)
then leaves i as it was, so set i or test s first.
Notes
- The words of
sare matched one by one against the words of each name. The name
that matches the most words wins; on a tie the lowest number wins. So"fire"finds the fire sphere (7), not fireball, and"cure"finds the first spell whose name begins with cure. Words after a full match are ignored:"cure light wounds now"still finds cure light wounds.
- Spells only; skills and weapons are other lists.
- Spell numbers run from 0 to
SPL_TREE_MAX- 1 (499), with gaps.
Example
dilbegin spell_num(arg : string);
var
si : integer;
code
{
si := spellindex(arg);
if (si == -1)
sendtext("There is no spell called '" + arg + "'.<br/>", self);
else
sendtext("'" + arg + "' is spell number " + itoa(si) + ".<br/>", self);
quit;
}
dilend
A player command (func = in commands.def) that tells the number of the
spell named, as the god command in commands.zon that sets a unit's spell skill looks it up.
See also
spellinfo()
Function (string). Returns a spell's name and puts its properties in seven integer variables.
spellinfo(i : integer, realm : integer, sphere : integer, mana : integer,
offensive : integer, resist : integer, media : integer, targets : integer)
Returns the name of spell number i and sets the other seven arguments from the
spell's entry in spells.def. Arguments 2 to 8 must be integer variables (or
elements of an integerlist variable): vmc refuses constants and expressions. When you only want
the name, give one variable seven times, as spellinfo(i, t, t, t, t, t, t, t).
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | The spell number, 0 to SPL_TREE_MAX - 1 (499). spellindex() finds it from a name.
|
| realm | integer variable | Set to ABIL_MAG (0) or ABIL_DIV (1): the ability the spell is cast with.
|
| sphere | integer variable | Set to the sphere the spell belongs to, SPL_DIVINE (1) to SPL_EXTERNAL (11). That is a spell number too, so spellinfo() on it gives the sphere's name.
|
| mana | integer variable | Set to the mana the spell costs. |
| offensive | integer variable | Set to non-zero for an attack spell, 0 otherwise. |
| resist | integer variable | Set to SPLCST_CHECK (1), SPLCST_RESIST (2) or SPLCST_IGNORE (3) (the check line in spells.def).
|
| media | integer variable | Set to the bits of what may carry the spell: 1 spell, 2 potion, 4 wand, 8 staff, 16 scroll (MEDIA_*).
|
| targets | integer variable | Set to the bits of what it may target: FIND_UNIT_* and the TAR_* bits.
|
Returns
String: the spell's name, or "" for a number in range that has no spell. For a
number below 0 or above 499 it fails and the seven variables are not changed.
Notes
- The
SPLCST_*,MEDIA_*andTAR_*constants are in
spelldef.h, whichmacros.hdoesn't include: add#include <spelldef.h>at the top of the zone. OnlySPLCST_*can be used there:MEDIA_*andTAR_*are written with<<, which DIL doesn't have, so vmc stops with a syntax error at the<. Use the numbers:MEDIA_*as above;TAR_IGNORE32,TAR_CHAR64,TAR_OBJ128,TAR_ROOM256,TAR_FIGHT_SELF512,TAR_FIGHT_VICT1024,TAR_SELF_ONLY2048,TAR_SELF_NONO4096,TAR_AUTO_SELF8192.
- The spells are numbered without gaps from 0 to the last one (236 in spells.def today); a number past the last gives an empty name.
Example
dilbegin spell_facts(arg : string);
var
si : integer;
nrealm : integer;
nsphere : integer;
nmana : integer;
boffense : integer;
nresist : integer;
bvmedia : integer;
bvtargets : integer;
t : integer;
sname : string;
sphname : string;
code
{
si := spellindex(arg);
if (si == -1)
{
sendtext("No such spell.<br/>", self);
quit;
}
sname := spellinfo(si, nrealm, nsphere, nmana, boffense, nresist, bvmedia, bvtargets);
sphname := spellinfo(nsphere, t, t, t, t, t, t, t);
if (nrealm == ABIL_DIV)
sendtext(sname + " is a divine spell of the " + sphname, self);
else
sendtext(sname + " is a magic spell of the " + sphname, self);
sendtext(" and costs " + itoa(nmana) + " mana.<br/>", self);
if (boffense)
sendtext("It is an attack spell.<br/>", self);
if (nresist == SPLCST_RESIST)
sendtext("Its victim may resist it.<br/>", self);
if (isset(bvmedia, 2)) // MEDIA_POTION, see the notes
sendtext("It can be put in a potion.<br/>", self);
quit;
}
dilend
A player command that describes the spell named. The zone needs
#include <spelldef.h> for SPLCST_RESIST.
See also
beginedit()
Procedure. Lets a player type several lines of text, which the program then gets.
beginedit(pc : unitptr)
Puts the player in the line editor: they are told "Terminate with a '@'." and what they type
from then on is collected instead of being run as commands, until they type a line that ends
in @. The text then comes to the program as an SFB_EDIT event, with
the lines joined by <br/> and in argument. Use it for longer
texts: bug reports, descriptions, board messages.
While the player is in the editor, their editing field is true.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player who writes. Must be a connected player. |
Notes
- Wait for the text right after the call:
wait(SFB_EDIT, self == activator);then
readargument. The event's activator is the unit whose program called beginedit(), not the player; with a player's own command (selfis the player) they are the same.
- The
@ends the text only as the last character of a line, and is not part of
the text. The whole text is cut at about 12,000 characters ("String too long - Truncated.").
- With an NPC, or a player with no connection (link-dead), the program stops with a type
error in the zone's log. A null pc is only logged.
- To take a player out of the editor before they finish, use
killedit. If the unit that called beginedit() is destroyed, the editor ends with it ("Unit was extracted, sorry.").
- Don't call it for a player who is already in the editor (test
pc.editing): what
they wrote so far is lost, and the new text never reaches the program.
Example
dilbegin cmd_report(arg : string);
var
t : string;
i : integer;
code
{
if (self.type != UNIT_ST_PC)
quit;
sendtext("Write your report. End it with @ on the last line.<br/>", self);
beginedit(self);
wait(SFB_EDIT, self == activator);
t := argument;
if (length(getwords(t)) < 2)
{
sendtext("Too short, nothing saved.<br/>", self);
quit;
}
i := flog("reports", self.name + " " + asctime(realtime) + "<br/>" + t + "<br/>", "a");
sendtext("Thank you.<br/>", self);
quit;
}
dilend
A player command that takes a report of several lines and adds it to a log file, like the
bug command in commands.zon.
See also
cancarry()
Obsolete. DIL has no function cancarry(); vmc doesn't know the name.
The function is can_carry(ch, u, n), with an underscore: whether the character ch can carry n copies of the unit u. See can_carry().
fits()
Function (string). Tells whether an object is the right size for a character.
fits(ch : unitptr, obj : unitptr, pos : integer)
Compares the size (height) of obj with that of ch for
wearing it in position pos, and returns "" when it fits or a few words
saying why not.
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character (PC or NPC) who would wear it. |
| obj | unitptr | The object. |
| pos | integer | A WEAR_* position from vme.h, or -1 for the position the object is made for (from its manipulate flags).
|
Returns
String: "" when it fits, otherwise way too small, too small, too large
or way too large (and error when the character's height is 0). It fails when
ch is null or not a character, or obj is null or not an object.
Notes
- The object's height is taken as a percentage of the character's. For most positions it fits
from 50% to 150%: below 25% is way too small, above 225% way too large. Body armour
(WEAR_BODY) is stricter: 60% to 140%, way below 30% or above 210%.
- An object with no height (0) is way too small for everyone.
- Always
""for something not worn in that position: an object that can't be
worn with -1, a held object that isn't a weapon (WEAR_HOLD), or aposthat isn't aWEAR_*value.
- It only checks the size, not whether the position is free or the character may use it.
Example
dilbegin string fit_note(pc : unitptr, item : unitptr);
var
s : string;
code
{
s := fits(pc, item, -1);
if (s == "")
return("");
return("(" + s + " for you) ");
}
dilend
A note for a shop list when an item doesn't fit the customer, as the shops in function.zon show it.
See also
replace()
Function (string). Replaces every occurrence of one text in a string with another.
replace(old : string, new : string, s : string)
Returns a copy of s in which every old is replaced by
new. Note the order: what to look for, what to put instead, and last the string to
work on. s itself is not changed; assign the result.
Parameters
| Name | Type | Meaning |
|---|---|---|
| old | string | The text to look for. |
| new | string | What to put in its place; "" deletes old.
|
| s | string | The string to work on. |
Returns
String: s with the replacements made. When old is empty, or not in
s, it is s unchanged.
Notes
- The search is case-sensitive, unlike
==andinon strings. - It works from left to right and doesn't search the text it has put in, so
replace("a", "aa", s) doubles every a once and stops.
- A string variable that was never set counts as
"".
Example
dilbegin string fill_in(text : string, pc : unitptr);
var
s : string;
code
{
s := replace("%n", pc.name, text);
s := replace("%l", itoa(pc.vlevel), s);
s := replace("&&", "<br/>", s);
return(s);
}
dilend
Fills in a text with a player's name and level and turns && into line breaks,
as replace("&&", "<br/>", arg) in comm.zon does.
See also
restore()
Function (unitptr). Loads units saved with store() back into the game.
restore(filename : string, u : unitptr)
Reads the file that store() wrote and loads the units in it into
u, or into the unit running the program when u is null. Units inside
other units come back inside them, and equipment a character wore is worn again. With
store() this keeps things through a reboot: a chest's contents, a room's donations,
parcels in a mail system.
Parameters
| Name | Type | Meaning |
|---|---|---|
| filename | string | The file's name, as given to store(): letters, digits, _ and . only, at most 512 characters.
|
| u | unitptr | The unit to put them in, or null for the unit running the program. |
Returns
unitptr: the first unit loaded, whether u is null or not. That is the container
when it was stored with store(u, name, TRUE), and otherwise the first of the stored
contents (the others are in u too). Null when there is no such file, or it is
empty.
Notes
- A program read from a file (a room's or object's program when the zone boots, a unit brought back with restore(), a
recallprogram on a player) doesn't run until the first event reaches it, and that event only takes it as far as itswait(): the event itself is lost. A room program waiting for a command misses the first one after a boot. Programs on units that%resetloads start at once and aren't affected. - The files are in the
unitsfolder of the zone's DIL file directory, or of the
server'sdil_file_dir(server.cfg) when the zone has none.
- A name with other characters (a
/, a space) is refused with a line in the zone's
log, and the result is null.
- Restoring doesn't remove the file: restore it twice and you have two copies. Remove it with
delunit() when it has served.
store()of a unit with nothing in it writes no file, so an older file stays and
is restored. Use delunit() when the unit is empty, as in the example.
- A unit whose definition no longer exists in its zone comes back as slime
(The slimy remains of ...).
- Only zones whose access level in
zonelistis 10 or less may use it. In other
zones the program stops at once, and the attempt is logged.
- It reads the disk: don't call it often.
Example
dilbegin keep_chest();
var
u : unitptr;
i : integer;
fn : string;
code
{
fn := "chest_" + self.nameidx + "." + self.zoneidx;
u := restore(fn, self); // put back what was in it before the reboot
heartbeat := PULSE_SEC * 300;
:start:
pause;
if (self.inside == null)
i := delunit(fn); // store() of an empty chest writes nothing
else
store(self, fn, FALSE); // the contents, not the chest
goto start;
}
dilend
A chest that keeps its contents through reboots: it puts back what it held, then saves its contents every five minutes.
See also
meleeattack()
Function (integer). Makes a character attack another once in melee, starting a fight.
meleeattack(att : unitptr, def : unitptr, bonus : integer, wtype : integer, primary : integer) : integer
att makes one ordinary melee attack on def: hit roll, armour, shield, damage and the usual combat messages, exactly as a round of combat does. It's how skills like kick and bash do their damage. If att isn't fighting yet, the attack starts the fight, and att is set to the fighting position.
Parameters
| Name | Type | Meaning |
|---|---|---|
| att | unitptr | The attacking character. |
| def | unitptr | The character attacked. |
| bonus | integer | Added to the attack's hit roll (negative for a penalty). |
| wtype | integer | A weapon type WPN_* from vme/include/values.h (such as WPN_KICK, WPN_BITE, WPN_FIST) to attack with that type and the attacker's skill in it, ignoring any weapon. Any other value, such as 0 (WPN_ROOT) or -1, attacks with the weapon (see primary).
|
| primary | integer | When wtype isn't a weapon type: TRUE uses the weapon in WEAR_WIELD, FALSE the one in WEAR_HOLD (an off-hand attack). Without that weapon, the character's natural attack is used.
|
Returns
The damage done; 0 for a miss, a fumble or a blow the shield took. -1 when no attack happened: att is incapacitated (below sleeping), def is dead, they are the same unit, or they aren't in the same place. When either unit is null or not a character, the call fails and the variable assigned keeps its old value.
Notes
- A weapon type is a value from 7 (
WPN_GROUP_MAX) to 199. The group values 0 to 6 (WPN_ROOT,WPN_UNARMED,WPN_SPECIAL...) are not weapon types:meleeattack(self, u, 0, WPN_UNARMED, TRUE)hits with the wielded weapon. - The attack costs combat time like an ordinary blow (the weapon's speed), and the dual-wield penalty applies.
- A sleeping victim is always hit.
- It doesn't check whether the attack is allowed, such as in a peaceful room; skills in skills.zon call
provoked_attackfirst. When neither may attack the other under the player-killing rules, the blow does 0 damage. - The blow can kill
def. Afterwards the program's secures are checked at once, so a secure on the victim can jump to its label. - The draft and older manual versions show four arguments;
primaryis required.
Example
dilbegin bite_foe();
var
u : unitptr;
i : integer;
code
{
heartbeat := PULSE_SEC * 6;
:loop:
wait(SFB_TICK, self.fighting != null);
u := self.fighting;
if (rnd(1, 100) <= 25)
{
act("$1n bares $1s teeth!", A_SOMEONE, self, null, null, TO_ROOM);
i := meleeattack(self, u, 75, WPN_BITE, TRUE);
}
goto loop;
}
dilend
An NPC that sometimes bites its opponent as an extra attack; the spiders in haon_dor.zon bite the same way.
See also
meleedamage()
Function (integer). Makes a character strike another once, without first putting it into combat.
meleedamage(att : unitptr, def : unitptr, bonus : integer, wtype : integer) : integer
Works like meleeattack() with the main hand: one blow from att on def with the hit roll, armour, shield, damage and combat messages. The difference: the call itself doesn't make att fight def or change its position, and att doesn't need to be fighting anyone. skills.zon uses it for throwing: the thrown item is put in the wield position for the blow and taken out again.
Parameters
| Name | Type | Meaning |
|---|---|---|
| att | unitptr | The attacking character. |
| def | unitptr | The character hit. |
| bonus | integer | Added to the hit roll (negative for a penalty). |
| wtype | integer | A weapon type WPN_* from vme/include/values.h (7 to 199) to strike with that type, ignoring any weapon; any other value, such as 0, uses the weapon in WEAR_WIELD, or the natural attack when there is none.
|
Returns
The damage done; 0 for a miss, a fumble or a blow the shield took. -1 when no blow happened: att is incapacitated (below sleeping), def is dead, they are the same unit, or they aren't in the same place. When either unit is null or not a character, the call fails and the variable assigned keeps its old value.
Notes
- Every blow, a miss too, has the usual effects of an attack: a victim that isn't fighting starts fighting
att, a victim that is makesattfight it, it counts as an attack for the law (crimes), and when neither may attack the other under the player-killing rules the damage is 0. - The blow costs combat time like an ordinary one (the weapon's speed).
- The blow can kill
def. Afterwards the program's secures are checked at once, so a secure on the victim can jump to its label.
Example
dilbegin throw_at(targ : unitptr, thing : unitptr);
var
wielded : unitptr;
dam : integer;
code
{
wielded := equipment(self, WEAR_WIELD);
if (wielded != null)
unequip(wielded);
addequip(thing, WEAR_WIELD);
act("You throw $2n at $3n!", A_ALWAYS, self, thing, targ, TO_CHAR);
act("$1n throws $2n at you!", A_SOMEONE, self, thing, targ, TO_VICT);
dam := meleedamage(self, targ, 0, 0);
unequip(thing);
if (wielded != null)
addequip(wielded, WEAR_WIELD);
quit;
}
dilend
Throws an item from the inventory at someone, as the throw skill in skills.zon does.
See also
mid()
Function (string). Returns the characters from one position to another.
mid(s : string, first : integer, last : integer)
Returns the characters of s from position first to position
last, both included, counting from 1: mid("sprocket", 3, 6) is
"rock".
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The string. |
| first | integer | Position of the first character to take; 1 is the start. |
| last | integer | Position of the last character to take. |
Returns
String: the characters from first to last. A first below 1
counts as 1 and a last past the end as the end; when first is past the
end the result is "". When last is smaller than first it
fails and writes Illegal: mid(1,2,3) 3 > 2 to the zone's log; a string variable assigned
the result is then empty.
Notes
- The third argument is a position, not a length:
mid(s, 5, 2)is an error (or
""whensis shorter than 5).
- It counts bytes, so a letter outside ASCII (UTF-8) counts as two or more.
Example
dilbegin string stamp(line : string);
code
{
// asctime(realtime) is like "Sat Nov 14 12:34:56 2026": characters 12 to 16 are "12:34"
return(mid(asctime(realtime), 12, 16) + " " + line);
}
dilend
Puts the time of day in front of a line, as the logs in commands.zon do.
See also
moneystring()
Function (string). Writes an amount of money out in coins.
moneystring(amt : integer, verbose : integer)
Turns amt, in the game's base units, into the fewest coins of the default currency,
largest coins first: moneystring(1230, TRUE) is
a silver piece, 7 copper pieces and 3 iron pieces; moneystring(1230, FALSE) is
1 sp, 7 cp and 3 ip.
Parameters
| Name | Type | Meaning |
|---|---|---|
| amt | integer | The amount in base units: an iron piece is 10, copper 80, silver 640, gold 5120, platinum 40960 (IRON_MULT ... PLATINUM_MULT in vme.h).
|
| verbose | integer | TRUE for the coins' names (7 copper pieces, an iron piece), FALSE for their abbreviations (7 cp).
|
Returns
String: the coins, separated by commas and with and before the last.
Notes
- The amount is rounded to whole iron pieces (to the nearest 10).
- Anything under one iron piece, 0 and negative amounts included, comes out as
an iron piece (1 ip), never as nothing: test for 0 yourself.
- Always the default currency (the coins in
vme/etc/money). - Use
TRUEorFALSEforverbose.
Example
dilbegin quote_price(price : integer);
code
{
:start:
wait(SFB_CMD, command("value") and (activator.type == UNIT_ST_PC));
block;
act("$1n says, 'That costs " + moneystring(price, TRUE) + " (" +
moneystring(price, FALSE) + ").'", A_ALWAYS, self, null, null, TO_ROOM);
goto start;
}
dilend
A shopkeeper that tells the price when someone types value, written out both ways,
as the shops in midgaard.zon quote their prices.
See also
equipment()
Function (unitptr). The object a character wears or wields in a given position.
equipment(ch : unitptr, pos : integer) : unitptr
Looks through what ch carries and returns the first object that is equipped in position pos, or null when nothing is there.
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character (player or NPC) to look at. |
| pos | integer | A WEAR_* position from vme/include/vme.h, such as WEAR_WIELD, WEAR_HOLD, WEAR_SHIELD, WEAR_BODY or WEAR_FINGER_R.
|
Returns
The equipped object, or null when that position is empty. When ch is null or not a character, the call fails: a variable it is assigned to keeps its old value.
Notes
- The position is read as a number from 0 to 255. Position 0 means "not equipped", so
equipment(ch, 0)returns the first object in the inventory that isn't worn. UseWEAR_*values only. - It doesn't check the object's type:
equipment(ch, WEAR_WIELD)can be something other than a weapon. - The position of an object itself is its
equipfield.
Example
dilbegin show_wielded();
var
wpn : unitptr;
code
{
wpn := equipment(self, WEAR_WIELD);
if (wpn == null)
sendtext("You wield nothing.<br/>", self);
else
act("You wield $2n.", A_ALWAYS, self, wpn, null, TO_CHAR);
quit;
}
dilend
Tells the character what it is wielding.
See also
tolower()
Function (string). Returns a string in lower case.
tolower(s : string)
Returns a copy of s with every capital letter made small:
tolower("HELLO!") is "hello!". s itself is not changed.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The string. |
Returns
String: s in lower case; "" for an empty string or one never set.
Notes
- Only the letters A to Z change; letters outside ASCII stay as they are.
==on strings already ignores case. Usetolower()where case does
matter: file names, getcmd(), replace(),<and>.
Example
dilbegin got_mail();
var
ml : unitptr;
code
{
ml := restore(tolower(self.name), null);
if (ml != null)
{
act("<div class='mail'>You have a sudden urge to visit the post office.</div>",
A_ALWAYS, self, null, null, TO_CHAR);
destroy(ml);
}
quit;
}
dilend
From mail.zon: at login, checks whether mail was stored for the player under their name in lower case.
See also
toupper()
Function (string). Returns a string in upper case.
toupper(s : string)
Returns a copy of s with every small letter made a capital:
toupper("hello!") is "HELLO!". s itself is not changed.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The string. |
Returns
String: s in upper case; "" for an empty string or one never set.
Notes
- Only the letters a to z change; letters outside ASCII stay as they are.
- To capitalise only the first letter, combine it with left() and
right() as in the example.
Example
dilbegin string capital(s : string);
code
{
return(toupper(left(s, 1)) + right(s, length(s) - 1));
}
dilend
Returns the string with its first letter a capital, as helpzon.zon does with a help topic.
See also
visible()
Function (integer). Tells whether a character can see a unit.
visible(ch : unitptr, u : unitptr)
The same test the game uses when it decides whether a character sees someone or something: blindness, light, invisibility, wizard invisibility and burial count. It doesn't check where the unit is: a unit in another room can be "visible".
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character who looks (a player or an NPC). |
| u | unitptr | The unit looked at: a character, an object or a room. |
Returns
TRUE when ch can see u, otherwise FALSE. It fails when ch is null or not a character, or u is null; a failed value is false in an if, so not visible(...) is then true.
Notes
ch sees u when all of these hold:
chis not blind (CHAR_BLIND). This holds for gods too.uis not buried (UNIT_FL_BURIED), unlesschis insideu.ch's level is at leastu's wizard invisibility level (minv).chis a creator (level 230 or more), or else both: the placechis in is lit, anduis not invisible (UNIT_FL_INVISIBLE) orchhasCHAR_DETECT_INVISIBLE.
The light that counts is where ch is, not where u is. Hiding and sneaking are not part of this test.
Example
dilbegin unitptr find_evil();
var
u : unitptr;
found : unitptr;
code
{
foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
{
if ((u != self) and visible(self, u) and (u.alignment <= -350))
{
found := u;
break;
}
}
return (found);
}
dilend
Finds an evil character in the room that the NPC can see, as the guards in justice.zon do.
See also
opponent()
Function (integer). Tells whether two characters are fighting each other.
opponent(ch : unitptr, vict : unitptr)
A character in a fight has a list of opponents: everyone fighting it and everyone it fights. It melee-attacks only one of them, the one in its fighting field. opponent() looks in the whole list, so it is also true for an opponent that is not the melee target.
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character whose opponents are checked. |
| vict | unitptr | The character looked for among them. |
Returns
TRUE when vict is among ch's opponents, FALSE when it isn't or ch is not fighting. It fails when either unit is null or not a character (false in an if).
Notes
- Opponents always come in pairs: when one character gets the other as an opponent, the other gets it too. So
opponent(a, b)andopponent(b, a)give the same answer. - The number of opponents is opponentcount; getopponent() gets each of them.
Example
dilbegin hit_back(victim : unitptr, ch : unitptr);
code
{
if (victim.position <= POSITION_SLEEPING)
return;
if (opponent(victim, ch))
return;
set_fighting(victim, ch);
}
dilend
Makes a victim who is awake fight back, unless the two are already fighting, as provoked_attack does in skills.zon.
See also
purse()
Function (integer). Counts the coins of one kind that a unit carries.
purse(u : unitptr, coin : string)
The coin kind is given by its abbreviation from vme/etc/money. vme/include/vme.h has a name for each:
| Constant | Abbreviation | Value of one coin |
|---|---|---|
IRON_PIECE |
"ip" | IRON_MULT (10)
|
COPPER_PIECE |
"cp" | COPPER_MULT (80)
|
SILVER_PIECE |
"sp" | SILVER_MULT (640)
|
GOLD_PIECE |
"gp" | GOLD_MULT (5120)
|
PLATINUM_PIECE |
"pp" | PLATINUM_MULT (40960)
|
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit whose inventory is searched: a character, a container or a room. |
| coin | string | The coin abbreviation, e.g. GOLD_PIECE.
|
Returns
The number of coins (not their value). 0 when u has none, or the abbreviation is unknown. It fails when u is null or coin is empty.
Notes
- The second argument is a string. The old page said integer; vmc refuses one ("Arg 2 of 'purse' not a string").
- Only coins directly in
ucount, not coins inside a bag it carries. - To take a price from a character, use transfermoney(): it works with values, picks the coins and gives change.
Example
dilbegin integer coin_value(u : unitptr);
code
{
return (purse(u, PLATINUM_PIECE) * PLATINUM_MULT +
purse(u, GOLD_PIECE) * GOLD_MULT +
purse(u, SILVER_PIECE) * SILVER_MULT +
purse(u, COPPER_PIECE) * COPPER_MULT +
purse(u, IRON_PIECE) * IRON_MULT);
}
dilend
Adds up the value of the coins a unit carries, as the pick pocket skill in skills.zon reckons a victim's purse.
See also
atoi()
Function (integer). The number written at the start of a string.
atoi(s : string) : integer
Reads a whole number from the start of s, the C way: spaces before it are skipped, a + or - sign is allowed, and reading stops at the first character that isn't a digit.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text to read, such as a word the player typed. |
Returns
The number. A string that doesn't start with a number gives 0: atoi("abc") and atoi("") are 0, atoi("12 apples") is 12, atoi("-5") is -5. A string variable that has never been given a value makes the call fail, and the variable assigned keeps its old value.
Notes
- Since a non-number gives 0, check the text when 0 is a valid answer.
- Numbers beyond the integer range (about ±2.1 billion) don't come out right.
Example
dilbegin do_count(arg : string);
var
w : string;
n : integer;
code
{
w := getword(arg);
n := atoi(w);
if ((n < 1) or (n > 100))
{
sendtext("Count to what? A number from 1 to 100.<br/>", self);
quit;
}
sendtext("You count to " + itoa(n) + ".<br/>", self);
quit;
}
dilend
A player command that reads a number from what was typed.
See also
check_password()
Function (integer). Tells whether a password is a player's password.
check_password(pc : unitptr, pwd : string) : integer
Hashes pwd the way set_password() does and compares it with the player's stored password. It works from any zone.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. |
| pwd | string | The password to try, in plain text. |
Returns
TRUE when it is the password, FALSE when it isn't. Only the first 8 characters count, of the stored password and of pwd. It fails, and the zone log says "Unit must be a pc to check password", when pc is an NPC, object or room.
Notes
- Test
pcfor null first: on a unit variable that holds null the server crashes. - Nothing in the game uses it today.
Example
dilbegin ask_password();
var
good : integer;
code
{
if (self.type != UNIT_ST_PC)
quit;
sendtext("Type your password to go on:<br/>", self);
wait(SFB_CMD, self == activator);
block;
good := check_password(self, excmdstr_case);
if (good)
sendtext("Password accepted.<br/>", self);
else
sendtext("Wrong password.<br/>", self);
quit;
}
dilend
Asks the player for the password and checks it. The answer is typed as a command, so block keeps the game from running it; excmdstr_case keeps its case, as the password command in commands.zon does.
See also
command()
Function (integer). Tells whether the event that woke the program is a given command.
command(name : string) command(no : integer)
Right after a wait(), command() tells what woke the program up. With a string it is TRUE when the character typed that command, the way the game itself understands commands: command("say") is true for "say hello" and for any abbreviation the game takes as say. With an integer it compares the event's command number with one of the CMD_AUTO_* constants, for events that aren't typed: a heartbeat tick, a combat round, a death, and so on.
It is mostly used in the condition of wait(): wait(SFB_CMD, command("pull")).
Parameters
| Name | Type | Meaning |
|---|---|---|
| name | string | One command word, in lower case, such as "say" or "pull".
|
| no | integer | A CMD_AUTO_* constant from vme/include/vme.h.
|
Returns
Integer: 1 if the event is that command, otherwise 0. It fails if the argument fails.
Notes
- A command the game knows (one in
commands.def): the string is looked up like a typed word, and the command it stands for is compared with the command the character typed. So it doesn't matter how the character abbreviated it, andcommand("say")is safer thancmdstr == "say"or"say" in cmdstr(which is also true for "essay"). - A word the game doesn't know (
"pull","ring"): it matches when the character typed that word or the start of it ("pul"), as long as what was typed isn't itself taken as a real command (a short start such as "pu" usually is). - The lookup of a known command is case sensitive: write the name in lower case.
command("Say")never matches. - Give one word.
cmdstrholds the command word andargumentthe rest of the line. - The integer form:
CMD_AUTO_TICK(heartbeat),CMD_AUTO_COMBAT(combat round),CMD_AUTO_DAMAGE,CMD_AUTO_DEATH,CMD_AUTO_MSG(a message fromsendto(),sendtoall()orsendtoalldil()),CMD_AUTO_ENTER,CMD_AUTO_EXTRACT,CMD_AUTO_PLAY,CMD_AUTO_LEAVE,CMD_AUTO_SAVE,CMD_AUTO_EDITandCMD_AUTO_UNKNOWN(a word that isn't a command), all invme.h. Every command fromcommands.defhas the number 0 (CMD_AUTO_NONE). There are no constants such asCMD_SAY. - Like
activatorandargument, it describes the latest event only. After apauseor anotherwaitit describes that one. commandis a reserved word, so it can't be a variable name.
Example
dilbegin bell_ringer();
code
{
heartbeat := PULSE_SEC * 30;
:start:
wait(SFB_CMD | SFB_TICK, command(CMD_AUTO_TICK) or command("ring"));
if (command(CMD_AUTO_TICK))
{
act("The bell sways in the wind.", A_ALWAYS, self, null, null, TO_ROOM);
goto start;
}
if (activator.type != UNIT_ST_PC)
goto start;
block;
act("$1n rings the bell. DONG!", A_ALWAYS, activator, null, null, TO_ROOM);
goto start;
}
dilend
A bell that sways every 30 seconds and that players can ring; block stops the game from answering "ring is not a known command".
See also
delstr()
Function (integer). Deletes a string file.
delstr(filename : string)
Deletes a file written by savestr() and read by loadstr(): boards, clans and competitions use it to remove messages and lists.
Parameters
| Name | Type | Meaning |
|---|---|---|
| filename | string | The file's name, as given to savestr(): letters, digits, _ and . only, at most 512 characters.
|
Returns
integer. As the server is now, FALSE (0) when the file was deleted and TRUE (1) when it wasn't (no such file); the opposite of what the name suggests. FALSE as well for a name with other characters. Don't rely on the value: no zone does, and it may be corrected. Use loadstr() first to see whether the file exists.
Notes
- The file is in the
stringsfolder of the zone's DIL file directory (the last column of the zone's line invme/etc/zonelist), or ofdil_file_dirinserver.cfgwhen the zone has none. - Only zones with access level 10 or less (the fourth column of
zonelist) may use it. In other zones the program stops and the zone log says "attempt to violate system access security (delstr)". - A name with other characters (a
/, a space) is refused with a line in the zone log. - The result fails (it is neither true nor false) when the argument does, e.g. a field of a null unit.
Example
dilbegin clear_notes(pc : unitptr);
var
fn : string;
s : string;
i : integer;
code
{
fn := tolower(pc.name) + ".notes";
i := loadstr(fn, s);
if (i < 1)
{
sendtext("You have no notes.<br/>", pc);
return;
}
i := delstr(fn); // the result can't be trusted, see Returns
sendtext("Your notes are deleted.<br/>", pc);
return;
}
dilend
Deletes a player's notes file, after loadstr() has shown that there is one.
See also
delunit()
Function (integer). Deletes a unit file.
delunit(filename : string)
Deletes a file written by store(). A file that restore() has loaded is still there, and would be loaded again; delete it once it has served, as death.zon does with corpse files and mail.zon with parcels.
Parameters
| Name | Type | Meaning |
|---|---|---|
| filename | string | The file's name, as given to store(): letters, digits, _ and . only, at most 512 characters.
|
Returns
integer. As the server is now, FALSE (0) when the file was deleted and TRUE (1) when it wasn't (no such file); the opposite of what the name suggests. FALSE as well for a name with other characters. Don't rely on the value: no zone does, and it may be corrected.
Notes
- The file is in the
unitsfolder of the zone's DIL file directory (the last column of the zone's line invme/etc/zonelist), or ofdil_file_dirinserver.cfgwhen the zone has none. - Only zones with access level 10 or less (the fourth column of
zonelist) may use it. In other zones the program stops and the zone log says "attempt to violate system access security (delunit)". - A name with other characters (a
/, a space) is refused with a line in the zone log. store()removes the file itself when there is nothing to save, so emptying a container and storing it again is enough.
Example
dilbegin fetch_parcel(pc : unitptr);
var
fn : string;
u : unitptr;
i : integer;
code
{
fn := tolower(pc.name) + ".parcel";
u := restore(fn, pc);
if (u == null)
{
sendtext("There is no parcel for you.<br/>", pc);
return;
}
i := delunit(fn); // so it can't be fetched twice
act("You receive $2n.", A_ALWAYS, pc, u, null, TO_CHAR);
return;
}
dilend
Gives a player the parcel stored for them (see store()) and deletes the file.
See also
dildestroy()
Function (integer). Stops a DIL program on a unit and removes it.
dildestroy(tmpl : string, u : unitptr) : integer
Finds the first running program on u made from the template tmpl and removes it. Just before, that program gets an SFB_DILDESTROY event, so it can tidy up (a wait or an interrupt() on SFB_DILDESTROY); then it is stopped as if it had run quit.
Parameters
| Name | Type | Meaning |
|---|---|---|
| tmpl | string | The template's name with its zone, "name@zone". Without the @zone nothing is found.
|
| u | unitptr | The unit the program is on. |
Returns
TRUE when a program was found and removed, FALSE when u has none from that template (or the template doesn't exist). FALSE too when u is null.
Notes
- Only one program is removed per call. A unit can carry several copies of the same template (spells put on twice, for example); to remove them all, loop with dilfind() as in the example.
- It looks at the template each program was started from. A program that is busy in a template it called still counts as its starting template.
- Programs that have already ended are skipped.
Example
dilbegin cure_all(u : unitptr);
var
i : integer;
code
{
while (dilfind("spl_poison@spells", u))
i := dildestroy("spl_poison@spells", u);
while (dilfind("spl_sleep@spells", u))
i := dildestroy("spl_sleep@spells", u);
quit;
}
dilend
Removes every poison and magical sleep program from a character, as remove_aff in death.zon does.
See also
dilfind()
Function (integer). Tells whether a unit runs a DIL program from a given template.
dilfind(tmpl : string, u : unitptr) : integer
Looks through the programs on u for one that was started from the template tmpl and hasn't ended. Use it to avoid putting the same program on a unit twice, or to see whether a spell or a curse is still at work.
Parameters
| Name | Type | Meaning |
|---|---|---|
| tmpl | string | The template's name with its zone, "name@zone". Without the @zone nothing is found.
|
| u | unitptr | The unit to look at. |
Returns
TRUE when u has such a program, FALSE when not (or the template doesn't exist). FALSE too when u is null.
Notes
- It checks the template each program was started from, not one the program is busy in after calling it.
- The name must match the template, not the unit:
dilfind("guard@midgaard", u)asks about a program called guard, not about an NPC.
Example
dilbegin bleed_once(u : unitptr);
code
{
if (not dilfind("bleeding@ex", u))
dilcopy("bleeding@ex", u);
quit;
}
dilend
dilbegin bleeding();
code
{
heartbeat := PULSE_SEC * 10;
:loop:
wait(SFB_TICK, TRUE);
act("You bleed.", A_ALWAYS, self, null, null, TO_CHAR);
goto loop;
}
dilend
Puts a bleeding program on a character unless it already bleeds, as barbarian.zon does with its blood poison. The example zone is called ex.
See also
itoa()
Function (string). An integer written as text.
itoa(i : integer) : string
Turns a number into its decimal text, with a minus sign when it is negative, so it can be joined to other strings with +. DIL doesn't turn numbers into text by itself: "You have " + self.hp doesn't compile.
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | The number. |
Returns
The text: itoa(42) is "42", itoa(-7) is "-7". When i fails (for example a field of a null unit), the call fails too and a string variable assigned from it is emptied.
Example
dilbegin show_hp();
code
{
sendtext("You have " + itoa(self.hp) + " of " + itoa(self.max_hp)
+ " hit points.<br/>", self);
quit;
}
dilend
Shows a character its hit points.
See also
isaff()
Function (integer). Tells whether a unit carries an affect with a given id.
isaff(u : unitptr, id : integer)
Looks through the affects on u (spells, poisons, curses and other timed effects added with addaff()) and is TRUE if one of them has the id id. It works on any unit: characters, objects and rooms.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit to look at. |
| id | integer | The affect id, an ID_* constant.
|
Returns
Integer: 1 if u has at least one affect with that id, otherwise 0. If u is null, the result fails: false in an if, so not isaff(null, ...) is true.
Notes
- The
ID_*constants are invme/include/vme.h(ID_CORPSE,ID_BLIND_CHAR,ID_INVISIBILITY,ID_CURSE, ...) andvme/include/values.h. There is noID_BLIND. - It only tests for the affect, not its strength or time left.
getaffects()lists a unit's affects. - An affect isn't the same as a flag: blindness, for instance, can come from an affect (
ID_BLIND_CHAR) or from the flagCHAR_BLINDincharflags, so baselook.zon tests both.
Example
dilbegin integer is_blind(u : unitptr);
code
{
if (u == null)
return (FALSE);
return (isaff(u, ID_BLIND_CHAR) or isset(u.charflags, CHAR_BLIND));
}
dilend
Tells whether a character is blind, from an affect or from the flag, as baselook.zon does.
See also
islight()
Function (integer). Tells whether there is light in a room.
islight(u : unitptr)
Returns TRUE when u is lit and FALSE when it is dark. Give
it a room, usually self.outside: that is how the look and exits commands decide
whether to say It is pitch black. It does not tell whether an object gives light; that is
the bright field.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The room (or other unit) to test. |
Returns
Integer: TRUE or FALSE. It fails when u is null.
Notes
- The light is
u.light(the unit's own light plus what the light sources in it
give), plus thelightof the unit it is in, plus daylight unlessuhasUNIT_FL_INDOORS: +1 by day, 0 at sunrise and sunset, -1 at night. It is lit when the sum is 0 or more.
- So a room with no light setting is always lit indoors and dark outdoors at night. The macros
inwmacros.hset it:ALWAYS_LIGHT(light 1),IN_ALWAYS_DARKandOUT_DARK_NON_NOON(light -1),OUT_ALWAYS_DARK(light -2); a torch carried in adds its light.
- On a character it adds the character's own light, the room's and daylight even indoors
(a character has no UNIT_FL_INDOORS), which says nothing useful: pass the room.
Example
dilbegin do_peer(arg : string);
code
{
if (not islight(self.outside))
{
act("It is pitch black.", A_ALWAYS, self, null, null, TO_CHAR);
quit;
}
act("You peer around $2n.", A_ALWAYS, self, self.outside, null, TO_CHAR);
quit;
}
dilend
A player command that does nothing in the dark, as direc_dil in basemove.zon
(the exits command) starts.
See also
isplayer()
Function (integer). Tells whether a player character of that name exists.
isplayer(pname : string) : integer
Checks whether a saved player of that name exists, whether the player is in the game or not. Case doesn't matter. It looks for the player's file in the player directory (plydir in server.cfg), so a player made a moment ago counts once the character has been saved.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pname | string | The player's name. |
Returns
TRUE when the player exists, FALSE when not. An empty string gives FALSE (and the line "Empty string in find_player_id." in the log). A string variable that has never been given a value makes the call fail.
Notes
- It says nothing about whether the player is online; for that, look for the player in the game (see pc_head()).
- Give it a plain name. Text a player typed should be checked first: it is used to build a file name.
Example
dilbegin do_whois(arg : string);
var
pname : string;
code
{
pname := getword(arg);
if (pname == "")
{
sendtext("Whose name?<br/>", self);
quit;
}
if (not isplayer(pname))
sendtext("There is no player called " + pname + ".<br/>", self);
else
sendtext(pname + " is a player of this realm.<br/>", self);
quit;
}
dilend
A command that tells whether a name belongs to a player, as the postman in mail.zon checks an address.
See also
isset()
Function (integer). Tells whether any of some bits are set in an integer.
isset(value : integer, bits : integer)
Most flag fields (flags, charflags, manipulate, openflags, exit_info[dir], ...) hold several flags as bits of one integer. isset(value, bits) is TRUE (1) when value and bits have at least one bit in common, and FALSE (0) when they have none.
Parameters
| Name | Type | Meaning |
|---|---|---|
| value | integer | The integer to look at, usually a flag field. |
| bits | integer | The bit or bits to look for: a flag constant such as EX_CLOSED, or several joined with |.
|
Returns
Integer: 1 if any bit of bits is set in value, otherwise 0. If either argument fails (for example a field of a null unit), the result fails, and a failed value is false in every test.
Notes
- With several bits,
isset(u.charflags, CHAR_BLIND | CHAR_HIDE)is true when either is set. To require all of them, test each:isset(f, A) and isset(f, B). - The flag constants are in
vme/include/vme.h(UNIT_FL_*,CHAR_*,MANIPULATE_*,EX_*, ...) andvalues.h. set()andunset()change the bits;isset()only reads them.- A field of a null unit fails, so
isset(u.flags, X)andnot isset(u.flags, X)behave oddly whenuis null: testu == nullfirst.
Example
dilbegin integer door_closed(rm : unitptr, dir : integer);
code
{
if (rm == null)
return (FALSE);
if (rm.type != UNIT_ST_ROOM)
return (FALSE);
return (isset(rm.exit_info[dir], EX_CLOSED));
}
dilend
Tells whether the exit in direction dir of a room is closed.
See also
paycheck()
Function (integer). Tells whether a player's account allows them into the zone of a unit.
paycheck(pc : unitptr, place : unitptr)
For servers that charge for play (accounting on in server.cfg). A zone can be
marked pay-only with its payonly value; this checks that value for
the zone place belongs to against the player's account. Use it before moving a
player somewhere, as the movement code in skills.zon does with the room an exit leads to.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The character to check. Must be a character. |
| place | unitptr | A unit of the zone to check, usually the room the player is going to. |
Returns
Integer: TRUE when the player may go there, FALSE when not. When it
says no, the player has already been sent the server's pay message.
TRUE always when accounting is off (most servers), and for non-players, gods,
players connected from the local network and zones that aren't pay-only. A zone's
payonly 1 needs credit on the account, 2 a flat rate that hasn't run out, and 3 is
for players who have neither.
It fails when pc is null or not a character, or place is null; with
accounting off it gives TRUE without looking at the arguments.
Notes
- The player comes first. The old manual had the arguments the other way round.
- The zone is the one
placewas defined in, not the zone it is in now: pass a
room, not an object or a character who may have walked elsewhere.
Example
dilbegin go_to(pc : unitptr, room : unitptr);
code
{
if (not paycheck(pc, room))
{
act("You don't have access to that location.", A_ALWAYS, pc, null, null, TO_CHAR);
quit;
}
link(pc, room);
quit;
}
dilend
Moves a player to a room only if their account allows it, as the movement code in skills.zon does.
See also
findunit()
Function (unitptr). Finds a unit by name, the way commands find what a player names.
findunit(u : unitptr, s : string, flags : integer, list : unitptr) : unitptr findunit(u : unitptr, s : string, flags : integer, list : unitptr, type : integer) : unitptr
Looks for a unit called s in the places flags names, as seen by u: what it wears, carries, what is around it, and so on. It reads names the way the game's commands do, so it is the right tool for the words a player typed: "sword", "the 2.sword", "long sword". To find one particular NPC or object of a zone, use findsymbolic() instead; a name can belong to anyone, players included.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit that looks. The places searched are relative to it, and when it is a character it only finds what it can see. |
| s | string | The name to look for. Leading filler words (a, an, at, from, in, into, of, on, the, to, with) are skipped, and 2.sword means the second sword.
|
| flags | integer | : FIND_UNIT_EQUIP (what u wears), FIND_UNIT_INVEN (what it carries), FIND_UNIT_SURRO (its surroundings: the room it is in and the units there), FIND_UNIT_ZONE (anywhere in the zone u is in), FIND_UNIT_WORLD (anywhere). FIND_UNIT_IN_ME is equip and inventory, FIND_UNIT_HERE adds the surroundings, FIND_UNIT_GLOBAL is all of them. 0 searches only list.
|
| list | unitptr | null, or a unit to search together with the units after it in the same place. To search what a container holds, pass its inside.
|
| type | integer | . Without it, any kind. |
Returns
The unit found, or null. When u is null or s is empty, the call fails and the variable assigned keeps its old value: clear it first if you test it for null afterwards.
Notes
- It changes
s. Whensis a string variable (orargument), the words it matched, and the filler words before them, are taken off its start. Copy the string first if you need it again. - When names of different lengths fit the start of
s, the longest wins: for "long sword", a unit named "long sword" beats one named "long". Among equally long matches the order is equipment, inventory, surroundings, zone, world, list. "self"withFIND_UNIT_SURROfindsuitself.- When nothing matches the whole word and
uis a player, a word of up to three letters also matches the start of a name: "bra" finds Brawla. - When
uis a character it must be able to see the unit: not blind, light in the room, the unit not invisible (unlessudetects invisible), not buried, and not wizard-invisible aboveu's level. Gods fromCREATOR_LEVELup see in the dark and see invisible units. - When
uis not a character (an object or a room running the program),flagsare ignored and onlylistis searched. FIND_UNIT_PAYandFIND_UNIT_NOPAYare ignored here.FIND_UNIT_ZONEandFIND_UNIT_WORLDgo through every unit in the game; to find a player by exact name, walk the player list frompc_head()instead.
Example
dilbegin do_poke(arg : string);
var
u : unitptr;
code
{
u := null;
if (arg != "")
u := findunit(self, arg, FIND_UNIT_SURRO, null, UNIT_ST_PC | UNIT_ST_NPC);
if (u == null)
{
sendtext("Poke whom?<br/>", self);
quit;
}
act("You poke $3n.", A_ALWAYS, self, null, u, TO_CHAR);
act("$1n pokes you.", A_SOMEONE, self, null, u, TO_VICT);
act("$1n pokes $3n.", A_SOMEONE, self, null, u, TO_NOTVICT);
quit;
}
dilend
A player command that finds a character in the room by the name typed.
See also
findrndunit()
Function (unitptr). Picks a random unit of the wanted kinds in one place.
findrndunit(u : unitptr, where : integer, types : integer) : unitptr
Returns a unit chosen at random among those of the kinds types in the place where, relative to u: a random player in the room, a random room in the world, a random NPC of the zone. u itself is never picked.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit the search is relative to, usually self.
|
| where | integer | One of FIND_UNIT_SURRO, FIND_UNIT_INVEN, FIND_UNIT_EQUIP, FIND_UNIT_ZONE, FIND_UNIT_WORLD (vme/include/vme.h), optionally with FIND_UNIT_PAY or FIND_UNIT_NOPAY added. Not a combination of places: to search two, call it twice.
|
| types | integer | . |
Returns
A random unit, or null when there is none (or where is a combination of places). When u is null the call fails, and the variable assigned keeps its old value.
Notes
FIND_UNIT_SURRO: what is aroundu, as forfindunit().FIND_UNIT_INVEN: whatuholds and doesn't wear.FIND_UNIT_EQUIP: whatuwears; only whentypesincludesUNIT_ST_OBJ, and the later items are more likely to be picked than the first ones.FIND_UNIT_ZONEmeans the zoneuwas defined in, not the one it stands in, and counts the units defined in that zone wherever they are now, plus the players standing in it. Called on a player, it counts every player in the game.FIND_UNIT_ZONEandFIND_UNIT_WORLDgo through every unit in the game. Don't call them often.- With
FIND_UNIT_PAYonly players who pay and rooms of pay zones count; withFIND_UNIT_NOPAYthe others. Objects and NPCs never count then. - It doesn't check whether
ucan see the unit.
Example
dilbegin pickpocket();
var
u : unitptr;
code
{
heartbeat := PULSE_SEC * 30;
:loop:
wait(SFB_TICK, TRUE);
u := findrndunit(self, FIND_UNIT_SURRO, UNIT_ST_PC);
if (u != null)
act("$1n brushes past $3n.", A_SOMEONE, self, null, u, TO_NOTVICT);
goto loop;
}
dilend
An NPC that picks a random player in its room now and then, as basis.zon does.
See also
filesize()
Obsolete. DIL has no function filesize(); vmc doesn't know the name, and nothing replaces it.
To see whether a file saved with savestr() exists, read it with loadstr(), which tells whether it could be read, and take its length with length().
findroom()
Function (unitptr). Finds a room by its symbolic name.
findroom(sym : string) : unitptr
Returns the room defined as sym, "name@zone", for example to move someone there with link().
Parameters
| Name | Type | Meaning |
|---|---|---|
| sym | string | The room's symbolic name, "name@zone" (or "zone/name"). Case doesn't matter.
|
Returns
The room, or null when there is no room of that name: an unknown zone or name, a name without @zone, or the symbolic name of an NPC or object.
Notes
- The result can't take a field directly:
findroom(s).titledoesn't compile. Put it in a variable first. - A unit variable doesn't keep its value across a
waitorpause; look the room up again afterwards. - To move a character through an exit, use
exec("north", u); uselink()with findroom where no exit leads.
Example
dilbegin to_temple(pc : unitptr);
var
rm : unitptr;
code
{
rm := findroom("temple@udgaard");
if (rm == null)
{
log("to_temple: no temple@udgaard");
quit;
}
act("$1n disappears in a flash of light.", A_SOMEONE, pc, null, null, TO_ROOM);
link(pc, rm);
act("$1n appears in a flash of light.", A_SOMEONE, pc, null, null, TO_ROOM);
quit;
}
dilend
Moves a character to the temple of Udgaard, as death.zon does.
See also
findsymbolic()
Function (unitptr). Finds a unit by its symbolic name, the name@zone it was defined with.
findsymbolic(sym : string) : unitptr findsymbolic(sym : string, idx : integer) : unitptr findsymbolic(u : unitptr, sym : string, flags : integer) : unitptr
Every NPC, object and room comes from a definition in a zone file, and its symbolic name says which: "janitor1@midgaard". Unlike findunit(), which goes by the names players use, this finds a copy of exactly that definition, whatever it is called and whether or not anyone can see it.
- With one argument it returns a copy of
symanywhere in the game, the most recently made one. - With an index it returns the one copy whose
idxfield isidx, so a program can find a particular unit again later, after a wait, with only itssymnameandidxstored as text. - With a unit and flags it looks only in places around
u, like findunit does.
Parameters
| Name | Type | Meaning |
|---|---|---|
| sym | string | The symbolic name, "name@zone" (or "zone/name"). Case doesn't matter. A unit's own is its symname field.
|
| idx | integer | The unit's idx field, read earlier.
|
| u | unitptr | The unit to search around. |
| flags | integer | : FIND_UNIT_EQUIP (worn by u), FIND_UNIT_INVEN (carried by u, not worn; for a room or container, what is in it), FIND_UNIT_SURRO (the room u is in and what is there), FIND_UNIT_ZONE (a copy in the zone u is in), FIND_UNIT_WORLD (a copy anywhere). FIND_UNIT_IN_ME is equip and inventory.
|
Returns
The unit, or null when there is no such unit (the name has no definition, or no copy exists right now, or none in the places searched). When u is null, or a string variable that has never been given a value is passed, the call fails or returns null.
Notes
- It finds rooms too:
findsymbolic("temple@udgaard")is the room. findroom() does the same for rooms only. - Without
@zonenothing is found: the zone is never taken from the program's own. - For a player,
symnameandidxfind the player while he or she is in the game, and nothing once logged out. An NPC or object found again byidxis the same unit only while it exists; after it is gone, null. - The places are searched in the order equipment, inventory, surroundings, zone, world, and the first copy found is returned.
- It's quick: it goes through the copies of that one definition, not through every unit in the game.
Example
dilbegin call_janitor();
var
u : unitptr;
code
{
if (findsymbolic(self, "torch@midgaard", FIND_UNIT_IN_ME) != null)
{
sendtext("You already have a torch.<br/>", self);
quit;
}
u := findsymbolic("janitor1@midgaard");
if (u == null)
{
sendtext("The janitor is nowhere to be found.<br/>", self);
quit;
}
sendto("torch please", u);
quit;
}
dilend
Checks the character's own things for a Midgaard torch, then sends a message to the programs of a Midgaard janitor, wherever he is.
See also
getword()
Function (string). Takes the first word off a string.
getword(s : string)
Returns the first word of s. When s is a string variable, the word and the spaces after it are also removed from that variable, so repeated calls walk through the words one by one. This is the usual way to take a command's argument apart.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text. Its first word is cut off if it is a variable (or argument).
|
Returns
String: the first word, with its case kept. "" when s is empty or only spaces. It fails if s fails or is a string variable that has never had a value.
Notes
- Only a string variable,
argument, or an assignable string field such aspc.guildorpc.hometownis shortened (the field really changes). An expression such asgetword(s + "")leavessalone. - On
argumentthe change lasts until the program waits again; after that,argumentbelongs to the next event anyway. - Leading spaces are skipped; a word ends at the first space, tab, line break or other control character. Only spaces are skipped, though: a string that starts with a tab or a line break gives "" and stays as it is, so a loop like
while (s != "") w := getword(s);never ends on such a string. Usegetwords()orsplit()for text that may hold line breaks. - It is a function:
getword(s);on its own line is a syntax error. Writew := getword(s);. getwords()returns all the words at once without changing the string.
Example
dilbegin puller();
var
rest : string;
what : string;
code
{
:start:
wait(SFB_CMD, command("pull") and (activator.type == UNIT_ST_PC));
rest := argument;
what := getword(rest);
if (what == "")
{
act("Pull what?", A_ALWAYS, activator, null, null, TO_CHAR);
goto start;
}
if (not (what in {"lever", "handle"}))
goto start;
block;
act("You pull the lever. (Rest of the line: '" + rest + "')",
A_ALWAYS, activator, null, null, TO_CHAR);
goto start;
}
dilend
Takes the first word of "pull lever hard"; rest is then "hard".
See also
getwords()
Function (stringlist). Splits a string into its words.
getwords(s : string)
Returns a stringlist with one entry per word of s, in order. Words are separated by spaces; any number of spaces counts as one separator, and no empty entries are made. s itself is not changed (unlike getword()).
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text to split. |
Returns
Stringlist: the words. Empty when s is "" or only spaces. It fails if s fails or is a string variable that has never had a value; assigning a failed list leaves the variable as it was.
Notes
- Only the space character separates words. Tabs and line breaks stay inside the words:
getwords("a\nb")is one entry. For lines, usesplit(text, "\n"), orsplit(text, "<br/>")for text kept as HTML. length()gives the number of words;words.[0]is the first.
Example
dilbegin integer count_words(s : string);
var
words : stringlist;
code
{
words := getwords(s);
return (length(words));
}
dilend
Counts the words in a string: " open the door " gives 3.
See also
ghead()
Function (unitptr). The first unit in the game's global unit list.
ghead()
The global list holds every unit in the game, kept in this order: all players (the one who entered the game last first), then all NPCs, then all objects, then all rooms. Each unit's gnext is the next one in the list, and null after the last room.
ghead() is the start of that list: the player who entered the game last, or the first NPC when no players are on. It is mostly used to walk through the players, stopping at the first unit that isn't one.
Returns
Unitptr: the first unit of the list.
Notes
- The walk for one kind stops at the first unit of another kind:
while (u.type == UNIT_ST_PC). A field of null fails, and a failed comparison is false, so the loop also ends cleanly at the end of the list. - The other sections start at
pc_head(),npc_head(),obj_head()androom_head().global_head()is another name forghead(). - To find a player by exact name, walk the players like this.
findunit()matches partial names and only finds what the searcher can see. - A program runs at most 52,000 instructions between two waits (
WAITCMD_MAXINSTinvme/src/dil.h); past that it is stopped with "had endless loop" invme.log. The game holds many thousands of objects, NPCs and rooms, so a loop of a few instructions per unit over a whole section can run into that limit. You can't pause half-way either: unit variables are cleared at every wait unlesssecured.
Example
dilbegin unitptr find_player(pname : string);
var
pc : unitptr;
code
{
pc := ghead();
while ((pc.type == UNIT_ST_PC) and (pc.name != pname))
pc := pc.gnext;
if (pc.type != UNIT_ST_PC)
pc := null;
return (pc);
}
dilend
Finds a player in the game by name (the comparison ignores case), or returns null.
See also
split()
Function (stringlist). Cuts a string into pieces at a separator.
split(s : string, sep : string)
Returns the parts of s between the occurrences of sep, in order. The separator can be several characters long ("<br/>", "\n", ", ") and is matched with case. If sep doesn't occur, the result has one entry, the whole string.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text to cut. |
| sep | string | The separator. Must not be empty. |
Returns
Stringlist: the pieces. It fails if s or sep fails or is a string variable that has never had a value; assigning a failed list leaves the variable as it was.
Notes
- Each piece is tidied: spaces at its start and end are removed and runs of spaces inside it become one. So
split(text, sep)can't be used to put text back together exactly. - Empty pieces are kept:
split("a,,b", ",")has three entries, the middle one "", andsplit("a,", ",")ends with "".split("", ",")has one entry, "". - Don't pass an empty separator: the server's search reads past its end (see the source,
str_strin textutil.cpp), and what happens is not defined. - To split into words,
getwords()is simpler: it drops empty entries. - A file read with
loadstr()is usually split into lines withsplit(buf, "\n")(clans.zon) or, for text kept as HTML,split(buf, "<br/>")(boards.zon).
Example
dilbegin show_list(pc : unitptr, csv : string);
var
sl : stringlist;
i : integer;
n : integer;
code
{
sl := split(csv, ",");
n := length(sl);
i := 0;
while (i < n)
{
sendtext(itoa(i + 1) + ". " + sl.[i] + "<br/>", pc);
i := i + 1;
}
return;
}
dilend
Shows "sword, shield, helmet" as a numbered list of three lines.
See also
left()
Function (string). Returns the first characters of a string.
left(s : string, n : integer)
Returns the first n characters of s: left("shorten me", 5)
is "short".
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The string. |
| n | integer | How many characters to take. |
Returns
String: the first n characters. The whole string when n is its length
or more; "" when n is 0 or less, or s is empty.
Notes
- It counts bytes, so a letter outside ASCII (UTF-8) counts as two or more, and can be cut
in half.
Example
dilbegin string shorten(s : string, n : integer);
code
{
if (length(s) <= n)
return(s);
return(left(s, n - 3) + "...");
}
dilend
Shortens a long text to n characters, ending in ....
See also
length()
Function (integer). The length of a string, or the number of entries in a list.
length(s : string) length(sl : stringlist) length(il : intlist)
For a string, the number of bytes in it. For a stringlist or an intlist, the number of entries. The usual loop over a list runs i from 0 to length(list) - 1.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s, sl, il | string, stringlist or intlist | What to measure. vmc refuses other types. |
Returns
Integer: the length, 0 for "" or an empty list (and for a string variable that has never had a value). It fails if the argument fails, for example a field of a null unit: length(u.name) > 0 and length(u.name) == 0 are then both false.
Notes
- It counts bytes, not letters on the screen: colour and HTML codes such as
<br/>count, and a letter like "æ" is two bytes. lengthis a reserved word, so it can't be a variable name.- Read the length once into a variable before a loop if the list doesn't change; it saves the call on every round.
Example
dilbegin integer too_long(pc : unitptr, msg : string);
code
{
if (length(msg) > 80)
{
sendtext("Keep it under 80 characters.<br/>", pc);
return (TRUE);
}
return (FALSE);
}
dilend
Refuses a message longer than 80 characters. For a list, see the example in split().
See also
load()
Function (unitptr). Makes a new NPC or object from its zone definition.
load(sym : string) : unitptr
Creates a new copy of the NPC or object defined as sym, "name@zone", and puts it inside the unit running the program: in an NPC's inventory, in an object, or in a room. Move it where it should be with link().
Parameters
| Name | Type | Meaning |
|---|---|---|
| sym | string | The symbolic name, "name@zone" (or "zone/name"). Case doesn't matter.
|
Returns
The new unit, or null when it couldn't be made: no such unit (the log says "DIL load(...) - unit does not exist."), or a room ("DIL trying to load a room ..."). A string variable that has never been given a value makes the call fail.
Notes
- The reset limits of the zone don't apply: every call makes another one.
- The new unit's DIL programs start at once, before
load()returns. - An NPC loaded by a program on an NPC or object starts inside that unit;
link()it to the room. - Rooms can't be loaded.
- A unit variable is cleared at the next
waitorpause: give or move the unit before waiting, orsecureit.
Example
dilbegin baker_gift();
var
u : unitptr;
code
{
:loop:
wait(SFB_CMD, command("bow") and (activator.type == UNIT_ST_PC));
u := load("bread@midgaard");
if (u == null)
goto loop;
act("$1n gives $3n $2n.", A_SOMEONE, self, u, activator, TO_NOTVICT);
act("$1n gives you $2n.", A_SOMEONE, self, u, activator, TO_VICT);
link(u, activator);
goto loop;
}
dilend
An NPC that hands a loaf of bread to each player who bows.
See also
loadstr()
Function (integer). Reads a whole file into a string variable.
loadstr(filename : string, s : string)
Reads the file strings/filename under the zone's DIL file directory (the last
column of the zone's line in vme/etc/zonelist, or dil_file_dir from
server.cfg when it has none) and puts its text in the variable s. The
files are usually written by savestr(), but any text file in
that directory will do: basis.zon reads motd and welcome this way.
Parameters
| Name | Type | Meaning |
|---|---|---|
| filename | string | The file's name inside the strings directory: letters, digits, _ and . only, at most 512 characters.
|
| s | string | A string variable of the program. It receives the text. |
Returns
Integer, constants from vme/include/vme.h:
FILE_LOADED(1): read.FILE_NOT_FOUND(0): no such file, or the name has other characters (also
written to the zone's log).
FILE_TO_LARGE(-1): the file is over 1,000,000 bytes.FILE_OUT_OF_MEMORY(2).
It fails when either argument is a failed value.
Notes
- Test the result. When the file is missing or empty,
skeeps the value it had
before the call.
- The second argument must be a plain string variable. vmc also takes a constant or a
field such as u.title, but when the file is read, the server then writes into
memory that isn't a variable and crashes.
- Only zones with access level 10 or lower (the fourth column of
vme/etc/zonelist)
may use it. Elsewhere it writes "attempt to violate system access security (loadstr)" to the zone's log and the program stops.
- The text comes as it is in the file. Use textformat() to
turn \n written in it into new lines.
- Disk access is slow; keep the files small and read them only when needed.
Example
dilbegin show_news(pc : unitptr);
var
err : integer;
buf : string;
code
{
err := loadstr("news", buf);
if (err == FILE_LOADED)
pagestring(buf, pc);
else
sendtext("There is no news.<br/>", pc);
quit;
}
dilend
Shows the news file to a player, page by page.
See also
openroll()
Function (integer). Rolls an open-ended die: high rolls add another roll, low rolls subtract one.
openroll(dice : integer, end : integer)
Rolls a number from 1 to dice.
- If it is in the top
endnumbers (fromdice-end+ 1 up),
it rolls again and adds, and goes on while the new roll is also in the top end.
- If it is below
end(1 toend- 1), it rolls again and subtracts, and
goes on subtracting while that roll is in the top end.
- Otherwise the result is the roll.
With openroll(100, 5), 96 to 100 (5% of rolls) go on upwards and 1 to 4 (4%) go
below 1. There is no upper or lower limit.
Parameters
| Name | Type | Meaning |
|---|---|---|
| dice | integer | The size of the die. |
| end | integer | How many numbers at the top make the roll open-ended. |
Returns
Integer: the roll. It is 0 unless dice and end are above 0 and
end is smaller than dice/2 - 1 (so openroll(20, 10) is
always 0).
Notes
- The game's own skill and spell checks use
openroll(100, 5)(spells.zon,
function.zon).
Example
dilbegin integer contest(att : integer, defence : integer);
code
{
// above 0 is a success; usually between -50 and +50, now and then far more
return(openroll(100, 5) + att - defence - 50);
}
dilend
A contest between an attack and a defence value, as the skill checks in function.zon work.
See also
pathto()
Function (integer). Gives the first step of the shortest way from one unit's room to another's.
pathto(from : unitptr, to : unitptr)
Finds the room each unit is in (a room stands for itself) and returns the direction of the first step on the way from the first room to the second. Call it again after each step.
Parameters
| Name | Type | Meaning |
|---|---|---|
| from | unitptr | Where the way starts: usually self.
|
| to | unitptr | Where it should end: a room, or a unit in it. |
Returns
Integer, one of the DIR_* constants in vme.h:
| Value | Meaning |
|---|---|
DIR_NORTH ... DIR_SOUTHWEST (0 to 9, up to MAX_EXIT) |
Take that exit. |
DIR_ENTER (10) |
Enter a room that lies inside this one. |
DIR_EXIT (11) |
Leave this room for the room it lies in. |
DIR_IMPOSSIBLE (12) |
There is no way. |
DIR_HERE (13) |
Both are in the same room. |
DIR_TRYAGAIN (14) |
The routes from this room are still being worked out; ask again a little later. |
It fails when either unit is null.
Notes
- It only finds a way between rooms that can reach each other both ways. Across a one-way exit
the answer is DIR_IMPOSSIBLE, even when a way exists. Rooms made after boot
have no routes at all.
- The routes are worked out in the background: the first call from a room often returns
DIR_TRYAGAIN. Wait (apause) and ask again.
- The way may go through closed, locked or hidden doors (they only count as longer), so the
walker may have to open or unlock them. walk_room@function handles doors,
entering and leaving, and gives up after a number of failed tries.
DIR_SL_SHORTandDIR_SL_LONGinvme.hare the names of
the values, to use as a stringlist.
- Take the step with
exec("<dir>", self)so it is an ordinary move, then check
self.outside to see whether it worked.
Example
dilbegin step_toward(place : string);
var
dest : unitptr;
d : integer;
dirs : stringlist;
code
{
dirs := DIR_SL_LONG;
heartbeat := PULSE_SEC * 4;
:start:
pause;
dest := findroom(place);
if (dest == null)
{
log("step_toward: no room " + place);
quit;
}
d := pathto(self, dest);
if (d == DIR_HERE)
quit; // arrived
if (d == DIR_TRYAGAIN)
goto start; // the route is being worked out
if (d > MAX_EXIT)
{
log("step_toward: no way from " + self.outside.nameidx + " to " + place);
quit; // DIR_IMPOSSIBLE, or DIR_ENTER / DIR_EXIT
}
exec(dirs.[d], self);
goto start;
}
dilend
An NPC that walks to a room one step every few seconds; a short version of
walk_room@function in function.zon, which also deals with doors.
See also
pagestring()
Procedure. Sends a long text to a player, to be shown a page at a time.
pagestring(s : string, u : unitptr)
Sends s to the player u marked as paged text (wrapped in
<paged>), so that the player's client can show it a screenful at a time
instead of letting it scroll past. Use it for lists and other long output; for short text use
sendtext().
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text, with <br/> between lines.
|
| u | unitptr | The player. |
Notes
- Only characters: on an object or a room the zone log gets "Type error in not a pc/npc unit" and the program stops. With a null unit nothing is sent, apart from a line in the zone log ("pagestring with no unit").
- An NPC, or a player who isn't connected, gets nothing (unless a player is switched into the NPC).
- A god snooping the player sees the text too.
- An empty string sends nothing.
Example
dilbegin list_players();
var
pc : unitptr;
s : string;
code
{
s := "<u>Players in the game</u><br/>";
pc := pc_head();
while (pc != null)
{
if (pc.type != UNIT_ST_PC)
break;
s := s + pc.name + "<br/>";
pc := pc.gnext;
}
pagestring(s, self);
quit;
}
dilend
Lists the players in the game, a page at a time.
See also
right()
Function (string). Returns the last characters of a string.
right(s : string, n : integer)
Returns the last n characters of s:
right("This is Easy", 4) is "Easy".
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The string. |
| n | integer | How many characters to take from the end. |
Returns
String: the last n characters. The whole string when n is its length
or more; "" when n is 0 or less, or s is empty.
Notes
right(s, length(s) - 1)is everything but the first character, and
""for an emptys.
- It counts bytes, so a letter outside ASCII (UTF-8) counts as two or more.
Example
dilbegin string say_verb(s : string);
code
{
if (right(s, 1) == "?")
return("ask");
if (right(s, 1) == "!")
return("exclaim");
return("say");
}
dilend
Picks the verb for something said from its last character, as comm.zon does.
See also
rnd()
Function (integer). A random whole number in a range.
rnd(from : integer, to : integer) : integer
Returns a random number from from to to, both included, each equally likely. rnd(1, 100) <= 25 is the usual way to say "a 25% chance".
Parameters
| Name | Type | Meaning |
|---|---|---|
| from | integer | The lowest value. |
| to | integer | The highest value. |
Returns
The random number. When from is bigger than to the two are swapped, so rnd(10, 1) works like rnd(1, 10). When either argument fails (for example a field of a null unit), the call fails and the variable assigned keeps its old value.
Notes
rnd(5, 5)is always 5.- To pick an entry of a list, use
rnd(0, length(list) - 1)as the index.
Example
dilbegin squeak();
code
{
heartbeat := PULSE_SEC * 20;
:loop:
wait(SFB_TICK, TRUE);
if (rnd(1, 100) <= 25)
act("$1n squeaks loudly.", A_SOMEONE, self, null, null, TO_ROOM);
goto loop;
}
dilend
An NPC that squeaks at one tick in four.
See also
A procedure does something and returns no value, so it is a statement of its own: exec("say Hello", self);. cast_spell() can be called either way: see Built-In Functions.
Each line gives the call with its arguments and what it does. Click a name for the full page. Statements such as if, while and goto are in DIL Constructs.
Strings, lists and bits
| Procedure | What it does |
|---|---|
addstring(sl : stringlist, s : string) |
Adds a string to the end of a stringlist. |
substring(sl : stringlist, s : string) |
Removes a string from a stringlist. |
insert(list : stringlist or intlist, i : integer, value : string or integer) |
Puts a new entry into a stringlist or an intlist at a given position. |
remove(list : stringlist or intlist, i : integer) |
Takes the entry at a given position out of a stringlist or an intlist. |
set(i : integer, bits : integer) |
Turns bits on in an integer variable or field. |
unset(i : integer, bits : integer) |
Turns bits off in an integer variable or field. |
Text to players
| Procedure | What it does |
|---|---|
act(text : string, show : integer, char : unitptr, medium : unitptr or string, victim : unitptr or string, to : integer) |
Shows a message to the characters around someone, worded for each of them. |
sendtext(text : string, u : unitptr) |
Sends a text to one character's screen, exactly as it is. |
pagestring(s : string, u : unitptr) |
Sends a long text to a player, to be shown a page at a time. |
beginedit(pc : unitptr) |
Lets a player type several lines of text, which the program then gets. |
killedit(u : unitptr) |
Takes a player out of the text editor. |
Messages between programs
Messages are covered in Messages.
| Procedure | What it does |
|---|---|
send(msg : string) |
Sends a message to the DIL programs around the unit. |
sendto(msg : string, u : unitptr) |
Sends a message to the DIL programs on one unit. |
sendtoall(m : string, s : string) |
Sends a message to every copy of a unit in the game. |
sendtoalldil(m : string, s : string) |
Sends a message to every running copy of a DIL template. |
send_done(cmd : string, activator : unitptr, medium : unitptr, target : unitptr, power : integer, arg : string, other : unitptr, auto : integer) |
Tells the programs around that a command has been carried out. |
dispatch(s : string) |
Sends a line to programs outside the game, such as the Discord bot. |
Waiting and events
How a program waits for events and handles them.
| Procedure | What it does |
|---|---|
wait(events : integer, condition) |
Stops the program until an event of the given kinds comes, for which a condition holds. |
block |
Stops the event that woke the program from going any further. |
priority |
Keeps the unit's later programs from getting any event until nopriority.
|
nopriority |
Ends the priority set by this program.
|
clear(i : integer) |
Removes an interrupt set up with interrupt(). |
secure(u : unitptr, label) |
Keeps a unit in a variable across waits, and names where to go when it leaves. |
unsecure(u : unitptr) |
Ends the secure on a unit. |
quit |
Ends the program for good. |
DIL programs
| Procedure | What it does |
|---|---|
dilcopy(s : string, u : unitptr) |
Starts a copy of a DIL template on a unit. |
Moving and changing units
| Procedure | What it does |
|---|---|
exec(cmd : string, ch : unitptr) |
Makes a character carry out a command, as if they had typed it. |
link(u : unitptr, into : unitptr) |
Moves a unit into another unit, with no checks and no messages. |
destroy(u : unitptr) |
Removes a unit from the game. |
store(u : unitptr, filename : string, container : integer) |
Saves a unit, or what is inside it, to a file. |
follow(ch : unitptr, leader : unitptr) |
Makes one character follow another, or stop following. |
setbright(u : unitptr, light : integer) |
Sets how much light a unit gives. |
set_weight(u : unitptr, weight : integer) |
Sets a unit's total weight. |
set_weight_base(u : unitptr, weight : integer) |
Sets a unit's own weight. |
addextra(list : extraptr, names : stringlist, text : string)addextra(list : extraptr, names : stringlist, text : string, vals : intlist) |
Adds an extra description to a unit's extras, quests or info. |
subextra(list : extraptr, name : string) |
Removes an extra description by name. |
addaff(u : unitptr, id : integer, duration : integer, beat : integer, data0 : integer, data1 : integer, data2 : integer, tif_first : integer, tif_tick : integer, tif_last : integer, apf : integer) |
Adds an affect to a unit. |
subaff(u : unitptr, id : integer) |
Removes an affect from a unit. |
addequip(u : unitptr, pos : integer) |
Puts an object a character carries on, at a given position. |
unequip(u : unitptr) |
Takes off an object a character is wearing. |
setroomexit(room : unitptr, dir : integer, toroom : unitptr) |
Points a room's exit in one direction at another room, making the exit if the room has none that way. |
zonereset(z : zoneptr) |
Resets a zone now. |
Characters and combat
| Procedure | What it does |
|---|---|
set_fighting(u : unitptr, t : unitptr) |
Starts a fight between two characters. |
stop_fighting(u : unitptr, t : unitptr) |
Ends a character's fight with one opponent, or with all. |
change_speed(u : unitptr, delay : integer) |
Delays a fighting character's next attacks. |
position_update(u : unitptr) |
Sets a character's position from its hit points, and kills it at -11 or below. |
experience(amount : integer, pc : unitptr) |
Gives a player experience points, or takes them away. |
logcrime(criminal : unitptr, victim : unitptr, crime : integer) |
Reports a crime to the justice system: who did it, to whom, and what. |
Players and the server
All of these except gamestate() and log() work only in a zone with access level 0.
| Procedure | What it does |
|---|---|
acc_modify(pc : unitptr, amount : integer) |
Pays money into a player's account or takes it out. |
gamestate(pc : unitptr, gs : integer) |
Takes a player out of the game to the menu, back into the game, or out altogether. |
set_password(pc : unitptr, pwd : string) |
Sets a player's password. |
delete_player(pname : string) |
Deletes a player character for good. |
reset_level(pc : unitptr) |
Sets a mortal player's level back to 1. |
reset_vlevel(pc : unitptr) |
Sets a mortal player's virtual level back to 1. |
reset_race(pc : unitptr) |
Rolls a player's body again from the race's values: weight, height, lifespan and age. |
log(s : string) |
Writes a line to the server log. |
reboot(code : integer) |
Shuts the game server down. |
See also
follow()
Procedure. Makes one character follow another, or stop following.
follow(ch : unitptr, leader : unitptr)
Makes ch follow leader at once, whatever state either is in: asleep,
fighting, wounded. If ch was following someone else, that ends first. With
leader null, ch stops following. It is what the follow
command in commands.zon uses, and how the deputies in midgaard.zon lead a cuffed prisoner away.
Parameters
| Name | Type | Meaning |
|---|---|---|
| ch | unitptr | The character who follows. |
| leader | unitptr | The character to follow, or null to stop following. |
Notes
- Stop following only someone who follows.
follow(ch, null)when
chhas no master (or is not a character) stops the server. Testch.master != nullfirst. A failedleader(a field of null) counts as null.
- When both are characters,
chloses the group flag (CHAR_GROUP) and
gets thedilfollow@basemoveprogram, which tells it "You now follow ..." and walks it after the leader. AnSFB_DONE"follow" event is sent withchas activator and the leader as target. The leader is told nothing.
- When
leaderis given but either of them is not a character, nothing happens. - There is no check for circles: don't make a leader follow their own follower.
Example
dilbegin lead_away(prisoner : unitptr);
code
{
if (prisoner.type != UNIT_ST_PC)
quit;
act("$1n takes $3n by the arm.", A_SOMEONE, self, null, prisoner, TO_NOTVICT);
act("$1n takes you by the arm.", A_SOMEONE, self, null, prisoner, TO_VICT);
follow(prisoner, self);
quit;
}
dilend
dilbegin let_go(prisoner : unitptr);
code
{
if (prisoner.master != null)
follow(prisoner, null);
quit;
}
dilend
A guard makes a prisoner follow him, and later lets go only if the prisoner still follows someone.
See also
flog()
Function (integer). Writes a string to a file of its own in the server's log directory.
flog(filename : string, s : string, mode : string)
Keeps a zone's records out of vme.log: the text goes to
filename in the log directory (logdir in server.cfg,
../log/ from vme/bin). The bug, idea and
typo commands in commands.zon collect their reports this way.
Parameters
| Name | Type | Meaning |
|---|---|---|
| filename | string | The file's name in the log directory. A name with .. in it is refused.
|
| s | string | The text, written as it is: no newline or time stamp is added. |
| mode | string | "a" to add to the end of the file, "w" to write from its start. Only the first letter counts, and it must be lower case.
|
Returns
Integer: FILE_SAVED (1) when written; FILE_ILEGAL_OPP (-1) for a bad
mode, an empty or unset name or mode, a name with .., or a name too long for the
path; FILE_NOT_SAVED (-2) when s is empty. The constants are in
vme/include/vme.h. It fails when an argument is a failed value.
Notes
- Only zones with access level 0 or 1 (the fourth column of
vme/etc/zonelist) may
use it. Elsewhere it writes "attempt to access logs w/o access" to the zone's log and the program stops.
"w"does not empty the file first: a shorter text leaves the end of the old one
behind. Logs are normally written with "a".
- End each entry with a newline or a
<br/>yourself, or the entries run
together.
Example
dilbegin zone_note(s : string);
var
i : integer;
code
{
i := flog(self.zoneidx + ".log", asctime(realtime) + " " + s + "<br/>", "a");
return;
}
dilend
Adds a dated line to a log file named after the zone the unit came from.
See also
logcrime()
Procedure. Reports a crime to the justice system: who did it, to whom, and what.
logcrime(criminal : unitptr, victim : unitptr, crime : integer)
Starts the justice system's witness program (set_witness@justice) on the victim and
on every character around the victim who can see the criminal. Those witnesses then remember the
crime, and guards and the town's justice act on it as justice.zon sets out. The skills in
skills.zon call it when a theft is noticed.
Parameters
| Name | Type | Meaning |
|---|---|---|
| criminal | unitptr | The main suspect. Must be a character. |
| victim | unitptr | Who the crime was done to. Must be a character. |
| crime | integer | The crime, a CRIME_ constant from vme/include/vme.h: CRIME_STEALING (3), CRIME_MURDER (8) or CRIME_PK (64).
|
Notes
- Nothing happens when either one is null or not a character.
- Nothing happens when the victim is an NPC without the
CHAR_PROTECTEDflag:
killing or robbing ordinary monsters is no crime.
CRIME_MURDERandCRIME_PKagainst a victim with the justice
system's CHAR_LEGAL_TARGET flag are ignored.
- Only those who can see the criminal witness it. A thief who failed while hidden or invisible
should be made visible first if the crime is to be seen.
Example
dilbegin caught_stealing(vict : unitptr);
code
{
act("$3n catches you trying to steal!", A_SOMEONE, self, null, vict, TO_CHAR);
act("You catch $1n trying to steal from you!", A_SOMEONE, self, null, vict, TO_VICT);
logcrime(self, vict, CRIME_STEALING);
quit;
}
dilend
A failed theft that the victim notices becomes a crime, as in the steal skill of skills.zon.
See also
acc_modify()
Procedure. Pays money into a player's account or takes it out.
acc_modify(pc : unitptr, amount : integer)
Only does something when the game runs with accounting (accounting = 1 in server.cfg; it is off by default). A positive amount is paid in: the balance (acc_balance) and the total paid in (acc_total) go up. A negative one is taken out: both go down, the total no further than 0. Amounts are in cents: 100 is one unit of money.
Every change is written to vme.log ("... inserted 100 on account ...") and to the account log, account.log in the log directory, under the name of the unit running the program.
Only a program started in a zone with access level 0 (the fourth column of vme/etc/zonelist) can use it. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command. Elsewhere the zone log gets "attempt to violate system access security (amod)" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. |
| amount | integer | Cents to pay in (positive) or take out (negative). |
Notes
- Nothing happens with accounting off, for a unit that isn't a player, or for null; in those cases there is no access check either. An amount of 0 changes nothing.
- Nothing in the game uses it today.
Example
dilbegin give_credit(pc : unitptr, cents : integer);
code
{
if (pc.type != UNIT_ST_PC)
return;
acc_modify(pc, cents);
sendtext("Your account now holds " + itoa(pc.acc_balance) + " cents.<br/>", pc);
}
dilend
Pays an amount into a player's account and tells the player the new balance.
See also
strdir()
Function (stringlist). Lists the string files that DIL has saved, by a pattern.
strdir(pattern : string)
Returns the names of the files in the strings directory that match pattern: the files savestr() writes and loadstr() and delstr() read. Competition.zon, for instance, uses strdir(".*.comp") to find its saved competitions at boot.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pattern | string | A regular expression that must match the whole file name. "" means all files. |
Returns
Stringlist: the matching file names, in no particular order (the order the directory gives them). Empty when nothing matches or the directory doesn't exist. It fails if pattern fails or is a string variable that has never had a value; assigning a failed list leaves the variable as it was.
Notes
- The pattern is a regular expression (Perl style), not a shell wildcard:
".*"is everything,"dead[.].*"is every name starting with "dead.", and a plain.matches any character. A shell-style"*"is not a valid expression. - If the pattern is not a valid expression, the program stops with a type error in
vme.log(unlikeunitdir(), which just fails). - The directory is
strings/under the zone's DIL file directory: the sixth column of the zone's line invme/etc/zonelist, or elsedil_file_dirinserver.cfg. The zone is that of the program the unit runs; a function from another zone that it calls (f@otherzone) still looks in the calling program's directory. - Only file names are returned, without a path, ready for
loadstr().
Example
dilbegin wanted_list(pc : unitptr);
var
files : stringlist;
parts : stringlist;
i : integer;
n : integer;
code
{
files := strdir("dead[.].*");
n := length(files);
if (n == 0)
{
sendtext("Nobody is wanted.<br/>", pc);
return;
}
i := 0;
while (i < n)
{
parts := split(files.[i], ".");
sendtext("Wanted dead: " + parts.[1] + "<br/>", pc);
i := i + 1;
}
return;
}
dilend
Lists the players for whom a file "dead.name" was saved with savestr().
See also
set_password()
Procedure. Sets a player's password.
set_password(pc : unitptr, pwd : string)
The password is stored the classic Unix way, hashed with crypt() with the character's name as the salt. Only the first 8 characters count: "secretpassword" and "secretpa" are the same password. The new password is kept with the character and written to disk when the player is next saved.
Only a program started in a zone with access level 0 (the fourth column of vme/etc/zonelist) can use it. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command. Elsewhere the zone log gets "attempt to violate system access security (setpassword)" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. |
| pwd | string | The new password, in plain text. |
Notes
- Players only: on an NPC, object or room the program stops with "Type error in Not a pc unit" in the zone log.
- A null unit variable is logged ("set_password with no unit") and nothing changes; so does an empty (null) string.
- It doesn't check the password at all. The
passwordcommand in commands.zon asks twice and wants 5 to 16 characters. - If
crypt()fails, the old password stays and vme.log says so.
Example
dilbegin new_password(pc : unitptr, pwd : string);
code
{
if (pc.type != UNIT_ST_PC)
return;
if ((length(pwd) < 5) or (length(pwd) > 16))
{
sendtext("A password has 5 to 16 characters.<br/>", self);
return;
}
log("PASSWORD: " + self.name + " changed " + pc.name + "'s password.");
set_password(pc, pwd);
sendtext("Password changed.<br/>", self);
}
dilend
A god sets another player's password and it is logged, as the set command does for its pwd field (set.zon).
See also
store()
Procedure. Saves a unit, or what is inside it, to a file.
store(u : unitptr, filename : string, container : integer)
Writes the objects and NPCs inside u, with everything inside them, to a file.
When container is TRUE, u itself is saved too, with its contents.
restore() loads the file back, so things can be kept through a
reboot: a clan chest, a parcel for a player, an arena fighter's belongings.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit to save. |
| filename | string | The file's name: letters, digits, _ and . only, at most 512 characters.
|
| container | integer | TRUE: save u and its contents. FALSE: only the contents, never u itself: to keep one unit (a piece of furniture, a chest) through a reboot, use TRUE.
|
Notes
- The file goes in the
unitsfolder of the zone's DIL file directory (the last column of the zone's line invme/etc/zonelist), or ofdil_file_dirinserver.cfgwhen the zone has none. An existing file is replaced. - Only zones with access level 10 or less (the fourth column of
zonelist) may use it. In other zones the program stops and the zone log says "attempt to violate system access security (storeall)". The zone that counts is that of the program's template (the one copied onto the unit), not that of a function it called. - A name with other characters (a
/, a space) is refused with a line in the zone log; nothing is saved. - Only objects and NPCs are saved, never players, and not units with
UNIT_FL_NOSAVE. Worn equipment is saved as worn. - A room can't be saved, its contents neither: with TRUE the zone log says "attempt to save a container that is either a room or pc", with FALSE nothing is written. A player's inventory can be saved with FALSE.
- When there is nothing to save, the file is removed: an old file would bring back what is gone. So
store(u, f, FALSE)with nothing inudeletesf, and a laterrestore(f, ...)finds nothing (basic_save_contentsin reception.cpp). delunit() removes a file on purpose. - The units are only copied: they stay in the game.
- It writes to disk: don't call it often.
Example
dilbegin send_parcel(bag : unitptr, toname : string);
code
{
if (bag.type != UNIT_ST_OBJ)
return;
store(bag, tolower(toname) + ".parcel", TRUE); // the bag and what is in it
destroy(bag);
return;
}
dilend
Puts a bag and what is in it in storage for another player, who fetches it with restore() (see delunit()).
See also
position_update()
Procedure. Sets a character's position from its hit points, and kills it at -11 or below.
position_update(u : unitptr)
Call it after changing a character's hp, so that its position fits:
| Hit points | Position |
|---|---|
| 1 or more | unchanged; a stunned or worse character stands up (POSITION_STANDING)
|
| 0 to -2 | POSITION_STUNNED
|
| -3 to -5 | POSITION_INCAP
|
| -6 to -10 | POSITION_MORTALLYW
|
| -11 or less | POSITION_DEAD, and the character dies at once
|
The constants are in vme.h.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The player or NPC. |
Notes
- On an object, a room or a null unit nothing happens.
- At -11 or below the character dies as from any other death: programs nearby get
SFB_DEAD, and the death program in death.zon makes the corpse and, for a player, starts the death sequence. Nobody gets experience for it. The unit can be gone afterwards, so don't use it again; asecureon it fires. - The change of position itself gives no message; write your own with act().
- With 1 or more hit points a sleeping, resting or sitting character stays as it is.
Example
dilbegin falling_log(pc : unitptr);
code
{
if ((pc.type != UNIT_ST_PC) and (pc.type != UNIT_ST_NPC))
return;
act("A heavy log swings down and knocks you senseless!",
A_ALWAYS, pc, null, null, TO_CHAR);
act("A heavy log swings down and knocks $1n senseless!",
A_SOMEONE, pc, null, null, TO_REST);
pc.hp := 0; // 0 hit points: stunned, not dead
position_update(pc);
return;
}
dilend
A trap that knocks a character out without killing it, as the guild guards do in barbarian.zon.
See also
send done()
Procedure. Tells the programs around that a command has been carried out.
send_done(cmd : string, activator : unitptr, medium : unitptr, target : unitptr,
power : integer, arg : string, other : unitptr, auto : integer)
Sends an SFB_DONE event, as the server does after a built-in command has succeeded. The programs around that wait for it, such as wait(SFB_DONE, command("close") and (target == self)), wake up and see activator, medium, target, power and argument. Commands written in DIL (basemove.zon, baseget.zon, baselook.zon) end with it, so that other scripts see them like built-in commands. It does nothing else: the command itself is not carried out.
Parameters
| Name | Type | Meaning |
|---|---|---|
| cmd | string | The command's name, as in commands.def: "get", "open", ...
|
| activator | unitptr | Who did it; the event goes to the units around them. |
| medium | unitptr | What it was done with, or null.
|
| target | unitptr | What it was done to, or null.
|
| power | integer | A number for the receivers' power, e.g. an amount of money; usually 0.
|
| arg | string | The receivers' argument.
|
| other | unitptr | A unit elsewhere that should get the event too, or null.
|
| auto | integer | CMD_AUTO_NONE (0) normally; CMD_AUTO_ENTER for an "entered" event (vme.h).
|
Notes
- The event reaches the same units as a command the activator types: the activator, what it carries and wears, its room, everything in the room (also inside transparent units) and what the other characters there wear, and the room around when the activator is in a transparent unit.
othergets it as well when it isn't among them. - With a null activator nothing is sent.
- A name that isn't a command sends nothing and logs "send_done: DIL '...' attempted to send a non-existent command '...'" in the zone's log.
- With
autoset toCMD_AUTO_ENTER,cmdis ignored and the receivers seecommand(CMD_AUTO_ENTER), as when a unit enters something. Any otherCMD_AUTO_value logs "Unknown CMD_AUTO_ value" and sends nothing. - The program that calls
send_donedoesn't get the event itself. - A receiver that calls
blockkeeps the event from the programs after it.
Example
dilbegin close_item(item : unitptr);
code
{
if (isset(item.openflags, EX_CLOSED))
{
act("$2n is already closed.", A_ALWAYS, self, item, null, TO_CHAR);
return;
}
act("You close $2n.", A_ALWAYS, self, item, null, TO_CHAR);
act("$1n closes $2n.", A_ALWAYS, self, item, null, TO_REST);
set(item.openflags, EX_CLOSED);
send_done("close", self, null, item, 0, "", null, CMD_AUTO_NONE);
return;
}
dilend
dilbegin chest_lid();
code
{
:start:
wait(SFB_DONE, command("close") and (target == self));
act("The lid of $2n clicks shut.", A_ALWAYS, activator, self, null, TO_ALL);
goto start;
}
dilend
A command written in DIL closes a container and announces it; a program on the chest hears of it. The first is adapted from basemove.zon.
See also
send_pre()
Function (integer). Asks the programs around a character whether a command may go ahead.
send_pre(cmd : string, who : unitptr, med : unitptr, tgt : unitptr, pwr : integer,
arg : string, other : unitptr)
When a DIL does something on a character's behalf that a command would normally do (moving,
fleeing), other programs expect to hear about it first: a guard that blocks an exit waits with
wait(SFB_PRE, command("north") ...). send_pre() sends that SFB_PRE
event as if who had typed the command, to the programs the command itself would
reach: those in the room, on the room, and on what who carries. Each can let it pass
or block it, and the answer tells the caller whether to go on.
send_done() is its partner, for the SFB_DONE event
after the deed.
Parameters
| Name | Type | Meaning |
|---|---|---|
| cmd | string | The command, looked up like a typed command ("north", "flee"). Receivers see it in command(...).
|
| who | unitptr | Who does it: the receivers' activator.
|
| med | unitptr | The receivers' medium, or null.
|
| tgt | unitptr | The receivers' target, or null.
|
| pwr | integer | The receivers' power.
|
| arg | string | The receivers' argument.
|
| other | unitptr | A unit outside the room that should hear it too, or null. |
Returns
Integer, from vme/include/vme.h: SFR_SHARE when nobody blocked it,
SFR_BLOCK when a program blocked it. Stop when you get SFR_BLOCK.
It fails, and writes "Can not send_preprocess. No such command" to the zone's log, when
cmd is empty or not a command. A wrong type in another argument also fails.
Notes
- With
whonull, nothing is sent and the result isSFR_SHARE. - It sends the event; it doesn't run the command. Do the deed yourself afterwards, or use
exec() when the real command will do.
- A receiver changing
powerdoesn't change yourpwr.
Example
dilbegin go_dir(dir : string, toroom : unitptr, arg : string);
var
res : integer;
code
{
res := send_pre(dir, self, null, null, 0, arg, null);
if (res != SFR_SHARE)
quit;
link(self, toroom);
act("$1n arrives.", A_HIDEINV, self, null, null, TO_ROOM);
quit;
}
dilend
Moves a character a special way only if no guard or door program blocks the direction, as the climbing code in basemove.zon does.
See also
set()
Procedure. Turns bits on in an integer variable or field.
set(i : integer, bits : integer)
Turns on every bit of bits in i (i := i | bits) and leaves the other bits as they are. Mostly used on flag fields with the constants from vme.h and values.h: UNIT_FL_* in u.flags, EX_* in u.openflags and room.exit_info[dir], CHAR_* in u.charflags, PC_* in pc.pcflags.
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | An integer variable, or an integer field that can be assigned (u.flags, room.exit_info[dir], ...).
|
| bits | integer | The bits to turn on; join several with |.
|
Notes
- vmc refuses a constant or an expression as
i: "Arg 1 of 'set' not an integer variable". - On a field of a null unit nothing happens.
- A field this zone may not change (such as
pc.levelorpc.lifespanoutside zones with access level 0) stops the program at run time, with "DIL SERIOUS: ... Type error in lvalue set" in the log. - The field keeps its own size: bits that don't fit in it are lost (
u.flagsholds 16 bits). - Only the bits change, nothing else: setting
EX_LOCKEDon one side of a door doesn't lock the other side (the example does both). unset()turns bits off;isset()tests them.
Example
dilbegin lock_door(room : unitptr, dir : integer);
external
integer rev_dir@function(i : integer);
var
rev : integer;
code
{
if (not isset(room.exit_info[dir], EX_OPEN_CLOSE))
return;
set(room.exit_info[dir], EX_CLOSED | EX_LOCKED);
act("*cluck*", A_ALWAYS, room.inside, null, null, TO_ALL);
rev := rev_dir@function(dir);
if (isset(room.exit_to[dir].exit_info[rev], EX_OPEN_CLOSE))
{
set(room.exit_to[dir].exit_info[rev], EX_CLOSED | EX_LOCKED);
act("*cluck*", A_ALWAYS, room.exit_to[dir].inside, null, null, TO_ALL);
}
return;
}
dilend
Shuts and locks a door on both sides. Adapted from spells.zon.
See also
unset()
Procedure. Turns bits off in an integer variable or field.
unset(i : integer, bits : integer)
Turns off every bit of bits in i and leaves the other bits as they are. Mostly used on flag fields with the constants from vme.h and values.h: unset(item.openflags, EX_CLOSED) opens a container, unset(u.flags, UNIT_FL_INVISIBLE) makes a unit visible.
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | An integer variable, or an integer field that can be assigned (u.flags, room.exit_info[dir], ...).
|
| bits | integer | The bits to turn off (a mask, not a bit number); join several with |.
|
Notes
- vmc refuses a constant or an expression as
i: "Arg 1 of 'unset' not an integer variable". - On a field of a null unit nothing happens.
- A field this zone may not change (such as
pc.leveloutside zones with access level 0) stops the program at run time, with "DIL SERIOUS: ... Type error in lvalue unset" in the log. - Only the bits change, nothing else: no messages, and the other side of a door keeps its flags.
set()turns bits on;isset()tests them.
Example
dilbegin open_item(item : unitptr);
code
{
if (not isset(item.openflags, EX_CLOSED))
{
act("$2n is already open.", A_ALWAYS, self, item, null, TO_CHAR);
return;
}
if (isset(item.openflags, EX_LOCKED))
{
act("$2n seems to be locked.", A_ALWAYS, self, item, null, TO_CHAR);
return;
}
act("You open $2n.", A_ALWAYS, self, item, null, TO_CHAR);
act("$1n opens $2n.", A_ALWAYS, self, item, null, TO_REST);
unset(item.openflags, EX_CLOSED);
return;
}
dilend
Opens a container. Adapted from basemove.zon.
See also
addcolor()
Function (integer). Gives a player their own colour for a colour name.
addcolor(pc : unitptr, key : string, colour : string)
Adds key to the player's personal colours with the value colour. From
then on, text inside <div class='key'> (see
getcolor()) is shown to that player in this colour instead of
the game's default. The colours are saved with the player, and the color command
lists them. A player with no colour of their own for a key gets the default from
vme/etc/color.def.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. Must be a PC. |
| key | string | The colour's name: 1 to 20 letters, digits or _.
|
| colour | string | The colour, written as in color.def: a foreground and a background, such as "cpc bn".
|
Returns
Integer: TRUE when the colour was added, FALSE when the player already
has that key. It fails, and writes a line to the zone's log, when pc is null or not
a PC, when the key is empty, too long or has other characters, or when colour is
empty.
Notes
- A key is matched by abbreviation: if the player has
clan_who,
addcolor(pc, "clan", ...)finds it and returnsFALSE. Use changecolor() to change an existing one.
- The colour isn't checked. The
colorcommand accepts a foreground of
c, an optionalp(bright) and one ofn r g y b m c w, then a background ofband one ofn r g y b m c:"cw bn"is white on black,"cpy bn"bright yellow. Stay with those.
- Personal colours only change what telnet players see. The web client gets the class name
and colours it with its own style sheet.
Example
dilbegin set_clan_col(pc : unitptr, colour : string);
var
i : integer;
code
{
if (pc.type != UNIT_ST_PC)
quit;
if (not addcolor(pc, "clan_who", colour))
i := changecolor(pc, "clan_who", colour);
sendtext(getcolor("clan_who") + "Your clan list looks like this now.</div><br/>", pc);
quit;
}
dilend
Sets a player's colour for clan_who, adding it or changing it.
See also
delcolor()
Function (integer). Removes one of a player's own colours.
delcolor(pc : unitptr, key : string)
Removes key from the player's personal colours. Text in that colour then shows in
the game's default for the key (from vme/etc/color.def), if it has one.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. Must be a PC. |
| key | string | The colour's name: 1 to 20 letters, digits or _.
|
Returns
Integer: TRUE when the colour was removed, FALSE when the player
didn't have it. It fails, and writes a line to the zone's log, when pc is null or
not a PC, or when the key is empty, too long or has other characters.
Notes
- A key is matched by abbreviation:
delcolor(pc, "cl")removes the player's first
key that begins with cl. Give the whole key.
Example
dilbegin left_clan(pc : unitptr);
var
i : integer;
code
{
i := delcolor(pc, "clan_who");
if (i)
sendtext("Your clan colour is gone.<br/>", pc);
quit;
}
dilend
Removes the colour a clan gave its member, for instance when they leave the clan.
See also
getcolor()
Function (string). Returns the HTML tag that starts text in a named colour.
getcolor(key : string)
Returns <div class='key'>, nothing more: it is a short way to write the tag.
Text inside it is shown in the reader's colour for key. For a telnet player that
is the colour they chose with the color command, or one a DIL gave them with
addcolor(), and otherwise the game's default from
vme/etc/color.def (default, say_self, clan,
...). The web client gets the class as it is and colours it with its own style sheet.
Parameters
| Name | Type | Meaning |
|---|---|---|
| key | string | The colour's name, the class of the div.
|
Returns
String: <div class='key'>. A string variable that was never set gives
<div class=>.
Notes
- It does not read a player's colours, and it takes no unit: the old manual's
getcolor(ch, key) doesn't compile.
- Close the colour with
</div>.
Example
dilbegin clan_tell(pc : unitptr, msg : string);
code
{
sendtext(getcolor("clan") + msg + "</div><br/>", pc);
quit;
}
dilend
Sends a line in the reader's clan colour, the same as writing
<div class='clan'> as clans.zon does.
See also
changecolor()
Function (integer). Changes one of a player's own colours.
changecolor(pc : unitptr, key : string, colour : string)
Gives the player's colour key the new value colour. It only changes a
colour the player already has (from the color command or
addcolor()); it doesn't add one.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. Must be a PC. |
| key | string | The colour's name: 1 to 20 letters, digits or _.
|
| colour | string | The new colour, such as "cpc bn" (see addcolor()).
|
Returns
Integer: TRUE when the colour was changed, FALSE when the player has
no such key. It fails, and writes a line to the zone's log, when pc is null or not
a PC, when the key is empty, too long or has other characters, or when colour is
empty.
Notes
- A key is matched by abbreviation:
changecolor(pc, "cl", ...)changes the
player's first key that begins with cl.
- The colour isn't checked; see addcolor() for the values the
color command accepts.
- Personal colours only change what telnet players see.
Example
dilbegin clan_col_cmd(arg : string);
var
i : integer;
code
{
if (arg == "")
{
sendtext("Which colour? For example: clancolor cpc bn<br/>", self);
quit;
}
i := changecolor(self, "clan_who", arg);
if (i == FALSE)
i := addcolor(self, "clan_who", arg);
sendtext(getcolor("clan_who") + "Like this?</div><br/>", self);
quit;
}
dilend
A player command clancolor <colour> that changes the player's
clan_who colour, or adds it the first time.
See also
gamestate()
Procedure. Takes a player out of the game to the menu, back into the game, or out altogether.
gamestate(pc : unitptr, gs : integer)
The menu is where a player is between connecting and playing; basis.zon's login program enters the game with gamestate(self, GS_PLAY). In the menu the character is out of the world: in no room, not in the list of players, out of reach of everyone.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | A player. |
| gs | integer | One of the GS_ values in vme.h, below. |
| Value | What happens |
|---|---|
| GS_PLAY (0) | Into the game: at the room the player was in when they left for the menu, or at their hometown. Their inventory is loaded from file and their DIL programs start again. Nothing happens if they are already playing. |
| GS_QUIT (1) | Out of the game: as GS_MENU, and then the character is destroyed. |
| GS_MENU (2) | Out to the menu: the player is saved (unless an unsaved guest), their inventory is taken away, they leave the room, and every DIL program on them stops except the one that called gamestate. Nothing happens if they are already in the menu. |
| GS_LINK_DEAD (3) | Closes the player's connection. |
Notes
- Players only. On an NPC the program stops with "DIL SERIOUS: ... Type error in gamestate: Not a pc unit" in the log. A null unit stops it too ("Type error in gamestate").
- Any other number does nothing.
- In the menu every line the player types goes to the programs on the player only, and never runs as a command. The program that called gamestate reads it with
wait(SFB_CMD, activator == self)and command() or excmdstr, as competition.zon's menu does. - A player in the menu can't be seen, attacked or found, so a menu open to mortals is a place to hide; keep such menus short.
- vmc reports a wrong second argument as "Arg 1 of 'gamestate' not an integer".
Example
dilbegin do_backstage(arg : string);
code
{
if (self.type != UNIT_ST_PC)
quit;
gamestate(self, GS_MENU);
:menu:
sendtext("<br/>1) Back to the game<br/>2) Show the time<br/>Make your choice: ", self);
wait(SFB_CMD, activator == self);
block;
if (command("1"))
{
gamestate(self, GS_PLAY);
exec("look", self);
quit;
}
if (command("2"))
sendtext("It is mud hour " + itoa(mudhour) + ".<br/>", self);
goto menu;
}
dilend
A player command (func = do_backstage@zone in commands.def) that takes the player to a small menu and back into the game when they type 1, as competition.zon does.
See also
addextra()
Procedure. Adds an extra description to a unit's extras, quests or info.
addextra(list : extraptr, names : stringlist, text : string) addextra(list : extraptr, names : stringlist, text : string, vals : intlist)
Makes a new extra description with the given names and text (and numbers, in the second form) and puts it first in the list. The list is a unit's field: u.extra on any unit, or pc.quests and pc.info on a player. Scripts often keep data in hidden extras whose names start with $, and a quest marks a player with an extra in pc.quests.
Parameters
| Name | Type | Meaning |
|---|---|---|
| list | extraptr | The field u.extra, pc.quests or pc.info.
|
| names | stringlist | The names of the new extra (its .names); may be null for none.
|
| text | string | Its text (.descr). "" is fine.
|
| vals | intlist | Optional: numbers for its .vals.
|
Notes
- The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'addextra' not a unit extra description".
- An extra with the same name already there stays: the new one comes first and hides it from
inandu.extra.["name"]. To replace an extra,subextra()it first. - On a field of a null unit, or
pc.questsorpc.infoon something that isn't a player, nothing happens. {...}takes only constants. Names that come from variables go in a stringlist built withaddstring().- For quests, use the functions in quests.zon (
qstSetOngoing@questsand the others) rather than writing the extras by hand, so every quest looks the same in thequestscommand.
Example
dilbegin quest_finish(pc : unitptr, qon : string, qdone : string);
var
sl : stringlist;
code
{
subextra(pc.quests, qon);
sl := null;
addstring(sl, qdone);
addextra(pc.quests, sl, "");
return;
}
dilend
Swaps a player's "ongoing" quest entry for a "complete" one. Adapted from quests.zon.
See also
addstring()
Procedure. Adds a string to the end of a stringlist.
addstring(sl : stringlist, s : string)
Adds s as the new last element of sl. sl is a stringlist variable or a stringlist field, such as a unit's names or an extra description's names.
Parameters
| Name | Type | Meaning |
|---|---|---|
| sl | stringlist | The list: a variable or a field. |
| s | string | The string to add. |
Notes
- Spaces at the start and end are removed, and a row of spaces inside becomes a single space. A string that starts with a space is also logged ("DIL ... addstring [...] has whitespace").
- It adds the string even when the list has it already. Test with
infirst to keep a list without repeats. - When
sfails (a field of a null unit), nothing is added. sl := null;empties a list (quests.zon does this before building a new one).sl := {};doesn't compile.- A list constant
{...}takes only constants; a list with values from variables is built withaddstring. insert()adds at a given place;substring()andremove()take elements out.
Example
dilbegin who_is_here();
var
u : unitptr;
sl : stringlist;
i : integer;
code
{
foreach (UNIT_ST_PC, u)
addstring(sl, u.name);
i := 0;
while (i < length(sl))
{
sendtext(itoa(i + 1) + ". " + sl.[i] + "<br/>", self);
i := i + 1;
}
quit;
}
dilend
Builds a list of the players in the room and shows it, numbered.
See also
subextra()
Procedure. Removes an extra description by name.
subextra(list : extraptr, name : string)
Removes the first extra in the list that has name as one of its names, ignoring case. The list is a unit's field: u.extra, pc.quests or pc.info. Only one extra goes per call.
Parameters
| Name | Type | Meaning |
|---|---|---|
| list | extraptr | The field u.extra, pc.quests or pc.info.
|
| name | string | The name of the extra to remove. |
Notes
- The first argument must be the field itself. An extraptr variable is refused by vmc: "Arg 1 of 'subextra' not a unit extra description".
- The name must be a whole name of the extra:
"quest"doesn't remove an extra named"quest done". - When no extra matches, or the unit is null, nothing happens.
- To remove every extra with the name, loop while
name in list. - Don't rely on an extraptr variable that pointed at the removed extra; look the extra up again with
inafterwards.
Example
dilbegin set_power(pwr : integer);
code
{
subextra(self.extra, "$power");
addextra(self.extra, {"$power"}, itoa(pwr));
return;
}
dilend
Keeps one hidden $power extra on the unit, replacing the old value. Adapted from barbarian.zon.
See also
substring()
Procedure. Removes a string from a stringlist.
substring(sl : stringlist, s : string)
Removes the first element of sl that matches s, ignoring case. Only one element goes per call. sl is a stringlist variable or a stringlist field, such as a unit's names. Despite its name, it has nothing to do with parts of a string; for those see left(), mid() and right().
Parameters
| Name | Type | Meaning |
|---|---|---|
| sl | stringlist | The list: a variable or a field. |
| s | string | The string to remove. |
Notes
- An element matches when it is
s, or the first word or words ofs: with{"ship", "boat"},substring(sl, "ship arrived")removes"ship". An element longer thansdoesn't match:"ship"doesn't remove"ship arrived". - When nothing matches, or
sfails, the list stays as it is. - To remove every copy, loop while
s in sl. remove()removes an element by its place in the list.
Example
dilbegin greeter();
var
seen : stringlist;
code
{
:start:
wait(SFB_CMD, (activator.type == UNIT_ST_PC) and (command("say") or command("quit")));
if (command("quit"))
substring(seen, activator.name);
else if (not (activator.name in seen))
{
addstring(seen, activator.name);
exec("say Welcome, " + activator.name + "!", self);
}
goto start;
}
dilend
An NPC that greets each player once, and forgets them when they quit.
See also
stop_fighting()
Procedure. Ends a character's fight with one opponent, or with all.
stop_fighting(u : unitptr, t : unitptr)
With t null, u stops fighting everyone, and everyone stops fighting
u. With a character as t, only the fight between u and
t ends; u goes on with its other opponents.
When u has no opponents left, it stands up: its position becomes standing (or
lower, as its hit points allow), and its CHAR_SELF_DEFENCE flag is cleared.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The character whose fight ends. |
| t | unitptr | The opponent to stop fighting, or null for all of them. |
Notes
umust be a character; on anything else, or null, nothing happens. Atthat isn't a character counts as null.- The first argument can't be the word
null(vmc refuses it); the second can. - Call it with a
tonly whenuis fighting (u.fighting != null): on a character not in a fight,stop_fighting(u, t)crashes the server. stop_fighting(u, null)on a character not in a fight makes it stand up: a sleeping or resting character is standing afterwards.- It gives no message, and doesn't stop anyone from attacking again.
Example
dilbegin peace_bell();
var
u : unitptr;
code
{
:start:
wait(SFB_CMD, command("ring") and ("bell" in argument));
block;
act("$1n rings the bell, and a deep calm fills the room.",
A_ALWAYS, activator, null, null, TO_ALL);
foreach (UNIT_ST_PC | UNIT_ST_NPC, u)
{
if (u.fighting != null)
stop_fighting(u, null);
}
goto start;
}
dilend
A bell that stops every fight in the room when rung.
See also
subaff()
Procedure. Removes an affect from a unit.
subaff(u : unitptr, id : integer)
Removes the first affect on u whose id is id (the ID_ constants in vme.h and values.h). It ends the way an affect that runs out does: its apply function is undone (a lowered ability goes back up, a flag is taken off) and its last-tick function runs, which usually tells the player ("You can see again.").
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The character, object or room. |
| id | integer | The affect id, e.g. ID_BLIND_CHAR. Negative ids are the transfer affects on objects.
|
Notes
- Only one affect goes, the first one with that id. If the unit can carry several (a spell cast twice), call it until isaff() says no.
- Nothing happens when the unit has no such affect or the variable is null.
- It works from any zone; addaff() only from zones with access level 0.
- Removing a transfer affect (negative id) from an object that is being worn doesn't take the bonus off the wearer, and the later unequip no longer finds it: the wearer keeps it. Unequip the object first.
Example
dilbegin cure_blind(tgt : unitptr);
code
{
if (not isaff(tgt, ID_BLIND_CHAR))
{
act("Nothing happens.", A_ALWAYS, self, null, null, TO_CHAR);
return;
}
subaff(tgt, ID_BLIND_CHAR);
act("You touch $3n's eyes.", A_ALWAYS, self, null, tgt, TO_CHAR);
}
dilend
Takes blindness off a character, as spl_cure_blind in spells.zon does.
See also
addaff()
Procedure. Adds an affect to a unit.
addaff(u : unitptr, id : integer, duration : integer, beat : integer,
data0 : integer, data1 : integer, data2 : integer,
tif_first : integer, tif_tick : integer, tif_last : integer,
apf : integer)
An affect is a timed change to a unit: blindness, a raised strength, a slowed character. It has an id that isaff() and subaff() look for, an apply function (APF_) that makes the change and undoes it at the end, and up to three tick functions (TIF_, in vme.h) that run when it starts, at every beat, and when it ends; most of them send the messages.
When added, the apply function is run, then tif_first. Every beat pulses tif_tick runs and duration goes down by one. At the beat after it has reached 0, the change is undone and tif_last runs.
Only a program started in a zone with access level 0 (the fourth column of vme/etc/zonelist) can add affects. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command, not the zone of the template that calls addaff(). Elsewhere the zone log gets "attempt to violate system access security (ada)" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | A character or room for an id from 1 to 4096; an object for an id from 1 to 4096 or from -4096 to -1. |
| id | integer | The affect id: an ID_ constant from vme.h or values.h.
|
| duration | integer | How many beats it lasts. -1 never runs out. |
| beat | integer | Pulses between ticks: WAIT_SEC * 30 is 30 seconds.
|
| data0, data1, data2 | integer | Data for the apply and tick functions (see below). |
| tif_first, tif_tick, tif_last | integer | TIF_ functions to run at the start, at each beat and at the end, or TIF_NONE.
|
| apf | integer | The APF_ apply function, or APF_NONE.
|
The apply functions, from vme.h, and the data they use:
| apf | data0 | data1 | Works on |
|---|---|---|---|
| APF_ABILITY | ABIL_ ability |
amount added | characters only |
| APF_SPELL_ADJ | spell number | amount added | characters |
| APF_SKILL_ADJ | skill number | amount added | players |
| APF_WEAPON_ADJ | weapon number | amount added | characters |
| APF_MOD_CHAR_FLAGS | CHAR_ flags set |
characters only | |
| APF_MOD_UNIT_FLAGS | UNIT_FL_ flags set |
all units | |
| APF_MOD_OBJ_FLAGS | OBJ_ flags set |
objects only | |
| APF_LIGHT_DARK | light sources added (negative for dark) | all units | |
| APF_NATURAL_ARMOUR | ARM_ armour type |
(kept by the game) | characters |
| APF_SPEED | speed change, -8 to 8 | characters |
Notes
- An id outside the ranges above, or a
TIF_orAPF_value outsideTIF_NONE..TIF_MAXorAPF_NONE..APF_MAX, adds nothing; the zone log gets "addaffect parameters OOB". - It doesn't replace an affect with the same id: the unit gets a second one. Spells test with isaff() or remove the old one with subaff() first.
- "characters only" and "objects only" in the table are not checked:
APF_ABILITYorAPF_MOD_CHAR_FLAGSon a room or an object, orAPF_MOD_OBJ_FLAGSon anything else, can crash the server. - The ability, skill, spell and weapon functions refuse when the character's current value is below 1; the affect is then dropped at once.
- With a
beatof 0 or less the affect never ticks and never runs out: onlysubaff()or the unit's end removes it. - A negative id on an object is a transfer affect: it does nothing on the object, but while the object is worn the wearer has the same affect with the positive id (
ID_TRANSFER_STR, which is-ID_RAISE_STR, gives the wearerID_RAISE_STR), removed again when it is taken off. - A player's affects don't tick while the player is link-dead.
- Nothing happens when the unit variable is null.
Example
dilbegin mire(tgt : unitptr, hm : integer);
code
{
if (isaff(tgt, ID_MIRE))
subaff(tgt, ID_MIRE);
addaff(tgt, ID_MIRE, 1 + hm / 25, WAIT_SEC * 15,
-4, 0, 0, TIF_SPEED_WORSE, TIF_NONE, TIF_SPEED_BETTER,
APF_SPEED);
}
dilend
Slows a character down by 4 for 1 + hm / 25 beats of 15 seconds, as the mire spell in spells.zon does. It only works in a program started in a zone with access level 0, as spells.zon is.
See also
destroy()
Procedure. Removes a unit from the game.
destroy(u : unitptr)
An NPC or an object is removed together with everything in it: inventory, equipment, contents. A player is saved, taken out of the game and disconnected. Rooms can't be destroyed: on a room nothing happens.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit to remove. |
Notes
- On null nothing happens.
destroy(self)ends the program at once: the statements after it don't run.- Destroying a unit this program has
secured jumps to the secure's label at once, skipping the rest. Callunsecure(u)beforedestroy(u). - To keep what is inside, move it out first:
while (u.inside) link(u.inside, u.outside);(as in the example). - A player is saved first, unless they are a guest who was never saved.
Example
dilbegin fido();
var
i : unitptr;
code
{
on_activation(self.position <= POSITION_SLEEPING, skip);
heartbeat := PULSE_SEC * 15;
:loop:
pause;
foreach (UNIT_ST_OBJ, i)
{
if ((i.objecttype == ITEM_CONTAINER) and isaff(i, ID_CORPSE))
{
act("$1n savagely devours $2n.", A_SOMEONE, self, i, null, TO_ROOM);
while (i.inside)
link(i.inside, i.outside);
destroy(i);
goto loop;
}
}
goto loop;
}
dilend
A dog that eats corpses and leaves what was in them on the floor. Adapted from midgaard.zon.
See also
walkto()
Obsolete. DIL has no procedure walkto(); vmc doesn't know the name.
To find the way, pathto() gives the direction of the next step from where a unit is towards a room. To take the step, run the direction as a command, exec("north", self), and check self.outside afterwards. The function walk_room@function("inn@udgaard", speed) in function.zon walks a monster all the way to the room with that symbolic name and returns TRUE when it got there. pathto() only finds routes that can be walked both ways, so it fails across one-way exits.
link()
Procedure. Moves a unit into another unit, with no checks and no messages.
link(u : unitptr, into : unitptr)
link puts u inside into: a character into a room, an object into a container or into a character's inventory, and so on. It is a plain move: there are no messages, and no checks of position, doors, exits, weight or capacity. Give the messages yourself with act().
To move an NPC through an exit, use exec("north", self) instead, so that it is an ordinary move, then check self.outside. Use link where there is no exit (teleports, magic, a ship moving between rooms).
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit to move. |
| into | unitptr | Where to put it. |
Notes
- Nothing happens when either is null, when
intoisuitself or is insideu, or whenuis a room andintoisn't.findroom()returns null for a room that doesn't exist, solink(pc, findroom(...))does nothing then. - An object that is worn or wielded is taken off first.
- Programs that wait for someone to walk in or out don't hear about it, and a player moved into a room doesn't see it until they look:
exec("look", pc). - When the program has
secureduand moves it out of its surroundings, the secure fires at the next wake. - In a
whileloop overu.next, the next unit afterlinkis in the other place. Useforeach()for a loop that moves units.
Example
dilbegin send_home(pc : unitptr);
var
home : unitptr;
code
{
home := findroom(pc.hometown);
if (home == null)
return;
act("$1n vanishes in a flash of light!", A_HIDEINV, pc, null, null, TO_ROOM);
link(pc, home);
act("$1n materializes.", A_HIDEINV, pc, null, null, TO_ROOM);
exec("look", pc);
return;
}
dilend
Sends a player to their home town, with messages in both rooms. Adapted from basis.zon.
See also
weapon name()
Function (string). Gives the name of a weapon type from its number.
weapon_name(i : integer)
The weapon numbers are the WPN_ constants in vme/include/values.h, for example WPN_DAGGER (20). A weapon object's type is its value[0]. The names come from the name lines in vme/etc/weapons.def, in lower case: weapon_name(WPN_DAGGER) is "dagger". Numbers 0 to 6 are the weapon groups (WPN_ROOT to WPN_SPECIAL in vme/include/vme.h), with names like "category sword".
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | The weapon number. |
Returns
The weapon's name; "" when the number is in range but has no weapon. Outside 0 to 199 (WPN_TREE_MAX - 1) it gives null.
Notes
- The null outside the range is how the weapons list in commands.zon finds the end:
while (weapon_name(i) != null). Assigned to a string variable, null makes it "". - Don't put a number that may be out of range straight into
+:"a " + weapon_name(i)with a null makes an error that stops the program. skill name() gives "" instead and has no such trap.
Example
dilbegin string weapon_kind(item : unitptr);
code
{
if (item.objecttype != ITEM_WEAPON)
return ("");
return (weapon_name(item.value[0]));
}
dilend
Gives the weapon type of an object, as the look code in baselook.zon does.
See also
weapon_info()
Function (intlist). The figures etc/weapons.def gives a weapon type.
weapon_info(i : integer) : intlist
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | A weapon type: one of the WPN_ numbers in values.h. A weapon object (ITEM_WEAPON) holds its type in value[0].
|
Returns
A new intlist of 20 numbers:
| Index | Meaning |
|---|---|
| 0 | Hands: 1 for a one-handed weapon, 2 for a two-handed one. |
| 1 | Speed (the SPEED_ values defined in weapons.def).
|
| 2 | Kind of damage: WPNT_SLASH 0, WPNT_BLUDGEON 1, WPNT_PIERCE 2, WPNT_NONE -1 for the weapon groups (spelldef.h).
|
| 3 | What a shield does against it: SHIELD_M_BLOCK 0, SHIELD_M_REDUCE 1, SHIELD_M_USELESS 2 (vme.h).
|
| 4 | The group it belongs to (its sphere), such as WPN_AXE_HAM.
|
| 5 to 19 | Its attack lines: three numbers (offset, base damage, alpha) for each armour type in the order ARM_CLOTHES, ARM_LEATHER, ARM_HLEATHER, ARM_CHAIN, ARM_PLATE (vme.h). The offset for armour type a is at 5 + 3*a.
|
For a number below 0 or from WPN_TREE_MAX (200) up, it returns null: an empty list.
Notes
- A number in range that weapons.def doesn't define gives the defaults: one hand,
WPNT_SLASH, speed 0,SHIELD_M_BLOCK, groupWPN_ROOT, and 100, 0, 100 for every armour type. - The list is a copy: changing it changes nothing in the game.
- A weapon's abilities and fumble chance from weapons.def are not in the list.
- The usual use is the hands: baselook.zon shows "two hand wielded" when
weapon_info(item.value[0]).[0]is 2 (through a variable: a field or index can't follow a call directly).
Example
dilbegin integer two_handed(wpn : unitptr);
var
il : intlist;
code
{
if (wpn == null)
return (FALSE);
if (wpn.objecttype != ITEM_WEAPON)
return (FALSE);
il := weapon_info(wpn.value[0]);
if (length(il) == 0)
return (FALSE);
return (il.[0] == 2);
}
dilend
Tells whether a unit is a two-handed weapon, as two_handed in commands.zon.
See also
skill name()
Function (string). Gives the name of a skill from its number.
skill_name(i : integer)
The skill numbers are the SKI_ constants in vme/include/values.h, for example SKI_PICK_POCKETS (31). The names come from the name lines of the skills in vme/etc/commands.def, in lower case: skill_name(SKI_PICK_POCKETS) is "pick pockets".
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | The skill number. |
Returns
The skill's name, or "" when the number has no skill or is outside 0 to 299 (SKI_TREE_MAX - 1).
Notes
- The skills are numbered without gaps from 0, so a loop can go on until the name is "", as the skills list in commands.zon does.
- weapon name() does the same for weapons, but gives null, not "", outside its range.
Example
dilbegin skill_list(pc : unitptr);
var
i : integer;
code
{
i := 0;
while (skill_name(i) != "")
{
if (pc.skills[i] > 0)
sendtext(itoa(pc.skills[i]) + "% " + skill_name(i) + "<br/>", pc);
i := i + 1;
}
}
dilend
Shows a player the skills they have learnt, as the skills command in commands.zon does.
See also
reboot
Procedure. Shuts the game server down.
reboot(code : integer)
The server stops after the current pass of its game loop: the players who are connected are saved and their connections closed, and vme exits with code as its exit status. Whether the game comes back depends on what started vme: a script or service manager that starts it again turns this into a reboot.
Only a program started in a zone with access level 0 (the fourth column of vme/etc/zonelist) can use it. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command. Elsewhere the zone log gets "attempt to violate system access security (reboot)" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| code | integer | vme's exit status. 0 means all is well; the DIL integration tests (test.zon) exit with the number of a failed test, so the test script sees the failure. |
Notes
- The argument is required:
reboot;is a syntax error. - The program goes on after
reboot()until it waits or quits, and the rest of the current game loop pass runs too. End withquit. - It warns nobody. The
rebootcommand (cmd_rebootandrebootingin commands.zon) counts down and tells the players first.
Example
dilbegin failsafe();
code
{
heartbeat := PULSE_SEC * 60 * 5;
wait(SFB_TICK, TRUE);
log("Fail safe triggered");
reboot(99);
quit;
}
dilend
Stops the server with exit status 99 after five minutes, as the integration tests in test.zon do when a test hangs.
See also
killedit()
Procedure. Takes a player out of the text editor.
killedit(u : unitptr)
Ends the editor that beginedit() started for the player
u, and puts the player back at the normal command prompt. Use it when the player
dies, is attacked or is moved away while writing, as the board scripts in boards.zon do.
If the player is still writing, the editor finishes as if the player had ended it: the
SFB_EDIT event goes out as usual, with the text written so far in
argument.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The player. |
Notes
- The argument is required:
killedit;without one is a syntax error. - Players only. On an NPC, object or room the zone log gets "Type error in not a pc unit" and the program stops.
- With a null unit nothing happens, apart from a line in the zone log ("killedit with no unit").
- A player who isn't connected (link-dead) is left as they are.
- It ends any editor the player is in, also one started by a command such as
describe, which then keeps what was written.
Example
dilbegin write_note(fn : string);
var
err : integer;
code
{
interrupt(SFB_DEAD, activator == self, stop);
interrupt(SFB_COM, activator == self, stop);
sendtext("Write your note.<br/>", self);
beginedit(self);
wait(SFB_EDIT, activator == self);
if (argument != "")
{
err := savestr(fn, argument, "w");
sendtext("Note saved.<br/>", self);
}
quit;
:stop:
killedit(self);
sendtext("You stop writing.<br/>", self);
quit;
}
dilend
Lets a player write a note to a file, and takes the player out of the editor when attacked or killed, as the reply code in boards.zon does.
See also
experience()
Procedure. Gives a player experience points, or takes them away.
experience(amount : integer, pc : unitptr)
Adds amount to the player's experience (pc.exp); a negative amount takes experience away. The player doesn't gain a level from it: when the experience reaches the next level they are told "You can now raise a level by using the 'level' command!" and raise it themselves.
Parameters
| Name | Type | Meaning |
|---|---|---|
| amount | integer | Experience to add; negative to take away. |
| pc | unitptr | The player. |
Notes
- Only mortal players: on an NPC, an object, a room or null nothing happens, and a god (level
IMMORTAL_LEVEL, 200, or more) keeps the experience they have. - Every call on a player is logged in vme.log: "name gained amount experience from unit symname."
- Experience taken away never drops below what level 1 needs.
Example
dilbegin quest_reward(pc : unitptr, xp : integer);
code
{
if (pc.type != UNIT_ST_PC)
return;
if (xp > 0)
{
experience(xp, pc);
act("You receive $2t experience points.", A_ALWAYS, pc, itoa(xp), null, TO_CHAR);
}
return;
}
dilend
Rewards a player at the end of a quest. Adapted from quests.zon.
See also
act()
Procedure. Shows a message to the characters around someone, worded for each of them.
act(text : string, show : integer, char : unitptr, medium : unitptr or string,
victim : unitptr or string, to : integer)
Sends text to the characters that to picks, around char. Codes such as $1n in the text are filled in for each reader: a name, or "someone" when they can't see who it is, "he" or "she", and so on. The usual way to tell what happens is one act for the one who does it (TO_CHAR), one for the victim (TO_VICT) and one for the others (TO_NOTVICT or TO_REST).
Parameters
| Name | Type | Meaning |
|---|---|---|
| text | string | The message, with $-codes (below). No <br/> at the end: act adds it.
|
| show | integer | A_SOMEONE, A_HIDEINV, A_ALWAYS or A_RAW (below).
|
| char | unitptr | The one who acts: $1, and the place the message goes out from.
|
| medium | unitptr or string | $2: a unit, a string for $2t, or null.
|
| victim | unitptr or string | $3: a unit, a string for $3t, or null.
|
| to | integer | Who gets it: a TO_ constant (below).
|
The constants are in vme.h.
| to | Who gets it |
|---|---|
| TO_CHAR | char only.
|
| TO_VICT | victim only.
|
| TO_ROOM | Everyone around char, but not char.
|
| TO_NOTVICT | Everyone around char, but not char and not victim.
|
| TO_ALL | Everyone around char, char too.
|
| TO_REST | As TO_ROOM, and not those inside char either.
|
"Around char" is the room char is in, including those inside transparent units there; when char is inside a transparent unit (a wagon, a boat), also the room around that unit.
| show | Meaning |
|---|---|
| A_SOMEONE | Not shown to those asleep. A unit a reader can't see is "someone" or "something". |
| A_HIDEINV | Not shown to those who can't see char, nor to those asleep. For things that are only seen, like a smile.
|
| A_ALWAYS | Shown also to those asleep. A unit a reader can't see is "someone" or "something". |
| A_RAW | Shown to everyone, and $n and $N give the real names even of units the reader can't see.
|
A code is $, a digit for the argument (1 char, 2 medium, 3 victim) and a letter:
| Code | Becomes |
|---|---|
| $1n | A player's name, or the title of an NPC or object ("the town guard"); "someone" or "something" to those who can't see it. |
| $1N | The unit's first name ("guard"); "someone" or "something" to those who can't see it. |
| $1e, $1m, $1s | he/she/it, him/her/it, his/her/its. |
| $1p | The character's position (standing, sleeping, ...); "lying" for anything else. |
| $1a | "a" or "an" to go before the unit's name (or before a string argument). |
| $2t | The string given as that argument. |
| $$ | A single $.
|
Notes
- Only characters with a connection see it. NPCs, and the programs on them, never see act() text: to tell a program something, use
send()orsendto(). - With
charnull, orvictimnull forTO_VICTandTO_NOTVICT, nothing is sent. A string ascharcompiles but sends nothing. - A
tooutsideTO_ROOM...TO_REST(0 to 5) sends nothing. Ashowbelow 10 or above 14 is logged and taken asA_ALWAYS. - A code whose argument is null shows "NULL", and an unknown code cuts the message there; both are logged.
- The first letter is made a capital (after any HTML tags at the start).
- Numbers can't be passed: give
itoa(n)as the medium or victim and write$2tor$3t. - Used in an expression,
s := act(...)sends nothing and gives the text as the one it is about would see it, with the<br/>, or""when there is nobody or they wouldn't see it; seesact().
Example
dilbegin block_flee();
var
pc : unitptr;
code
{
:start:
wait(SFB_CMD, command("flee") and (activator.type == UNIT_ST_PC));
pc := activator;
block;
act("You panic and try to flee, but something prevents you from escaping!",
A_SOMEONE, pc, null, self, TO_CHAR);
act("$1n panics and tries to flee, but can not!",
A_SOMEONE, pc, null, self, TO_REST);
goto start;
}
dilend
dilbegin hand_over(item : unitptr, pc : unitptr);
code
{
act("You hand $2n to $3n.", A_SOMEONE, self, item, pc, TO_CHAR);
act("$1n hands you $2n.", A_SOMEONE, self, item, pc, TO_VICT);
act("$1n hands $2n to $3n.", A_SOMEONE, self, item, pc, TO_NOTVICT);
return;
}
dilend
Fleeing fails where this program is, with one message for the player and one for the others (adapted from clans.zon), and the three messages of handing something over.
See also
exec()
Procedure. Makes a character carry out a command, as if they had typed it.
exec(cmd : string, ch : unitptr)
ch, a player or an NPC, carries out cmd at once through the ordinary command interpreter: the same checks (position, doors, ...), the same messages, and the same events for the programs around. Nothing tells whether it worked; check afterwards, for example self.outside after a move.
Parameters
| Name | Type | Meaning |
|---|---|---|
| cmd | string | The command and its arguments, e.g. "say Hello" or "get key".
|
| ch | unitptr | The character who does it. |
Notes
- A move made with exec() is followed by a
lookin the new room, and programs that see the character's commands (awareones on the character itself, too) see that look as a command. chmust be a character: on an object, a room or null nothing happens.- This is the way to move an NPC through an exit:
exec("north", self)makes an ordinary move, with position checks, leave and arrive messages and every program that listens for movement. Uselink()only where there is no exit. - The program that calls
execdoesn't get the command itself (it is busy running), but the other programs onchand around it do, asSFB_CMD, and asSFB_DONEwhen the command succeeds. - Commands are at most 512 characters; a longer one is cut there and logged.
- A god (level 200 or more) can't be made to use a command that only gods have: it is refused and logged.
- If the command destroys
chor takes it away, and the program hassecuredch, the secure fires. - On a player it looks to them as if they typed it; use it on players with care.
Example
dilbegin go_east();
var
here : unitptr;
code
{
here := self.outside;
exec("east", self);
if (self.outside == here)
exec("say I can't get through here.", self);
return;
}
dilend
Walks an NPC east and checks that it got there.
See also
wait()
Procedure. Stops the program until an event of the given kinds comes, for which a condition holds.
wait(events : integer, condition)
Every program spends most of its life here. wait() always stops the program; it
goes on only with an event of one of the kinds in events (the SFB_
values in vme.h, joined with |) for which condition is true. At each
such event the program wakes, the condition is worked out again, and if it is false the program
goes back to waiting. The built-ins activator, medium,
target, power, argument and command()
describe the event, so the condition can test them.
| Value | Event |
|---|---|
SFB_CMD |
A command typed by someone near the unit, before it runs (it can still be blocked) |
SFB_DONE |
A command that has been carried out |
SFB_PRE |
The step before some actions, e.g. a spell about to hit |
SFB_TICK |
The unit's heartbeat |
SFB_RANTIME |
With SFB_TICK: the tick comes at a random time around the heartbeat
|
SFB_MSG |
A message from another program (send, sendto, sendtoall, sendtoalldil)
|
SFB_COM |
A combat round |
SFB_DEAD |
A death nearby |
SFB_EDIT |
The end of an editor started with beginedit()
|
SFB_PROMPT |
The player's prompt being made |
pause; is wait(SFB_TICK | SFB_RANTIME, TRUE), a macro in wmacros.h.
Parameters
| Name | Type | Meaning |
|---|---|---|
| events | integer | The kinds of event to wake for. |
| condition | any | True to go on: a non-zero integer, a unit or string that isn't null, a list that isn't empty. |
Notes
- A program read from a file (a room's or object's program when the zone boots, a unit brought back with restore(), a
recallprogram on a player) doesn't run until the first event reaches it, and that event only takes it as far as itswait(): the event itself is lost. A room program waiting for a command misses the first one after a boot. Programs on units that%resetloads start at once and aren't affected. - It waits even if the condition is true already.
- Every event of the given kinds wakes the program, even one the condition then turns down. At every wake each
unitptrandextraptrvariable that isn't secured becomes null. Save what you need fromactivator,argumentand the rest right after thewait, andsecure()a unit you want to keep. - Other bits are dropped:
wait(SFB_SAVE, ...)never wakes. Useinterrupt()for such events. - The program also wakes for the events of its
interrupt()s, which may jump elsewhere. - A condition that fails (a field of a null unit) counts as false. A text field or list entry tested on its own (
wait(SFB_TICK, self.title)) counts the wrong way round, as true when the text is empty: compare with""instead. - A program that runs on without a
waitorpausefor about 52000 instructions is stopped ("had endless loop" in the zone log).
Example
dilbegin greeter();
var
pc : unitptr;
code
{
heartbeat := PULSE_SEC * 3;
:start:
wait(SFB_CMD, command("say") and (activator.type == UNIT_ST_PC) and
("hello" in argument));
pc := activator;
secure(pc, start);
pause; // let the player's words show first
exec("say Welcome, " + pc.name + "!", self);
unsecure(pc);
goto start;
}
dilend
An NPC that welcomes a player who says hello.
See also
savestr()
Function (integer). Writes a string to a file, to read back later with loadstr().
savestr(filename : string, s : string, mode : string)
Saves s in the file strings/filename under the zone's DIL file
directory: the last column of the zone's line in vme/etc/zonelist, or
dil_file_dir from server.cfg (../lib/file/) when the zone
has none. The strings directory is made when it is missing. Such files outlive
reboots; boards.zon keeps its messages in them.
Parameters
| Name | Type | Meaning |
|---|---|---|
| filename | string | The file's name inside the strings directory.
|
| s | string | The text to save, as it is (no newline is added). |
| mode | string | "w" to write from the start of the file, "a" to add to its end. Only the first letter counts, and it must be lower case.
|
Returns
Integer, constants from vme/include/vme.h:
FILE_SAVED(1): written.FILE_ILEGAL_OPP(-1): the mode is neitherwnora.
The header also has FILE_NOT_CREATED (0) and FILE_NOT_SAVED (-2), but
savestr() doesn't give them: a file that can't be opened still reports FILE_SAVED.
It fails when any of the three strings is empty, so an empty text can't be saved: remove the file with delstr() instead.
Notes
- Only zones with access level 10 or lower (the fourth column of
vme/etc/zonelist)
may use it. Elsewhere it writes "attempt to violate system access security (savestr)" to the zone's log and the program stops.
"w"does not empty the file first. It writes over the start of the old
text, and when the new text is shorter, the end of the old one stays behind. To replace a file whose text may get shorter, call delstr() first.
- Unlike loadstr() and delstr(), the file name is not checked: keep it to letters, digits,
_and., and never build it from what a player typed.
- Disk access is slow; keep the files small and don't save on every heartbeat.
Example
dilbegin note_winner(pc : unitptr);
var
err : integer;
code
{
err := savestr("lottery.win", pc.name + " " + asctime(realtime) + "<br/>", "a");
if (err != FILE_SAVED)
log("lottery: could not save the winner " + pc.name);
quit;
}
dilend
Adds a line naming a lottery winner to a file that keeps growing, the way boards.zon appends to a board's index.
See also
remove()
Procedure. Takes the entry at a given position out of a stringlist or an intlist.
remove(list : stringlist or intlist, i : integer)
The entries after it move down one place, so no gap is left. Positions count from 0. It works
on a list variable and on the list fields of an extra (ex.names,
ex.vals). To take a string out by its text rather than its position, use
substring().
Parameters
| Name | Type | Meaning |
|---|---|---|
| list | stringlist or intlist | The list to change: a variable or a list field, not a function's result. |
| i | integer | The position of the entry to remove. |
Notes
- A position below 0 or past the end does nothing.
- When
iis a failed value (a field of null), entry 0 is removed. - In an extra's
namesthe first entry is the extra's own name, the one
in finds it by: start removing data at position 1.
- While removing several entries in a loop, go from the end to the start, or each removal
shifts the positions still to come.
Example
dilbegin drop_entry(u : unitptr, cname : string);
var
ex : extraptr;
i : integer;
code
{
ex := "$comp" in u.extra;
if (ex == null)
return;
i := length(ex.names) - 1;
while (i >= 1)
{
if (ex.names.[i] == cname)
{
remove(ex.names, i);
remove(ex.vals, i);
}
i := i - 1;
}
return;
}
dilend
Takes a competition out of the names and values a player's extra keeps side by side, as competition.zon does.
See also
reset_level()
Procedure. Sets a mortal player's level back to 1.
reset_level(pc : unitptr)
Sets level to 1 and changes nothing else. Experience, abilities, skills and hit points stay as they are; a reroll changes those separately.
Only a program started in a zone with access level 0 or 1 (the fourth column of vme/etc/zonelist) can use it. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command. Elsewhere the zone log gets "attempt to reset level w/o access" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. |
Notes
- Nothing happens to NPCs, objects and rooms, or to immortals (level
IMMORTAL_LEVELand up). - A null unit variable is logged ("reset_level with no unit") and nothing happens.
Example
dilbegin back_to_one(pc : unitptr);
code
{
if ((pc.type != UNIT_ST_PC) or (pc.level >= IMMORTAL_LEVEL))
return;
reset_level(pc);
reset_vlevel(pc);
reset_race(pc);
sendtext("You are back at level 1.<br/>", pc);
}
dilend
Puts a mortal player back to level 1, and resets the virtual level and the race's values (reset_race()) too.
See also
reset_vlevel()
Procedure. Sets a mortal player's virtual level back to 1.
reset_vlevel(pc : unitptr)
Sets vlevel to 1 and changes nothing else. Experience, abilities, skills and hit points stay as they are; a reroll changes those separately.
Only a program started in a zone with access level 0 or 1 (the fourth column of vme/etc/zonelist) can use it. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command. Elsewhere the zone log gets "attempt to reset vlevel w/o access" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player. |
Notes
- Nothing happens to NPCs, objects and rooms, or to immortals (level
IMMORTAL_LEVELand up). - A null unit variable is logged ("reset_vlevel with no unit") and nothing happens.
Example
dilbegin back_to_one(pc : unitptr);
code
{
if ((pc.type != UNIT_ST_PC) or (pc.level >= IMMORTAL_LEVEL))
return;
reset_level(pc);
reset_vlevel(pc);
reset_race(pc);
sendtext("You are back at level 1.<br/>", pc);
}
dilend
Puts a mortal player back to level 1, and resets the virtual level and the race's values (reset_race()) too.
See also
reset race()
Procedure. Rolls a player's body again from the race's values: weight, height, lifespan and age.
reset_race(pc : unitptr)
The player keeps their race and sex. The server takes that race's entry in races.def (the male or female values, by the player's sex) and rolls the numbers again with its dice, the same way as when a character is made:
- weight and base weight: the race's weight plus its weight dice;
- height: the race's height plus its height dice;
- lifespan: the race's lifespan plus its lifespan dice;
- birth: the character's creation time minus the race's starting age plus its age dice, in mud years. The player's age is counted from that.
Use it after changing pc.race, or in a reroll together with reset level() and reset vlevel().
Parameters
| Name | Type | Meaning |
|---|---|---|
| pc | unitptr | The player to roll again. |
Notes
- Only a program in a zone with access level 0 or 1 (the fourth column of
vme/etc/zonelist) may call it. Elsewhere it writes "DIL '...' attempt to reset race w/o access." to the zone log and the program stops. - Players only. On an NPC, an object or a room it does nothing.
- A unitptr variable that is null writes "reset_race with no unit." to the zone log and does nothing. vmc refuses a literal
null. - It does not change the race, abilities, skills, training costs or level. (The old page said it also reset training costs: it doesn't.)
- The player's race must be one of the races (0 to 99). With a larger value in
pc.racethe server stops on an assertion.
Example
dilbegin reroll_body(pc : unitptr);
code
{
if (pc.type != UNIT_ST_PC)
return;
reset_race(pc);
sendtext("Your body changes. You are now " + itoa(pc.height) + " cm tall and weigh " +
itoa(pc.weight) + " pounds.<br/>", pc);
}
dilend
Rolls a player's body again and tells them their new height and weight.
See also
secure()
Procedure. Keeps a unit in a variable across waits, and names where to go when it leaves.
secure(u : unitptr, label)
DIL clears every unitptr variable at each wake (after every wait(), pause and heartbeat), because the unit may have gone in the meantime. A secured unit is the exception: its variables keep it for as long as it stays in the program's surroundings.
When the unit leaves them, or is destroyed, the program jumps to label, every variable holding the unit becomes null, and the secure ends. The surroundings are the room the program's unit is in (through whoever carries it), with everything in it and what the characters there carry, but not the inside of containers or of rooms within it, unless those have UNIT_FL_TRANS and are open. That includes the program's own unit walking away from u.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | A variable holding the unit. It must be one of the program's own variables or parameters: secure(activator, lost) gives "Arg 1 of 'secure' not a user-variable". Copy the built-in into a variable first.
|
| label | label | The label to jump to, written without its colons: secure(pc, lost); for :lost:.
|
Notes
- The secure is tested at each wake, after send(), sendto() and exec(), and after destroy() of the unit. A
destroy()of a secured unit therefore jumps to the label at once and skips the rest: call unsecure() first. - A secure belongs to the template call that made it and ends when that call returns. When a called template returns, the caller's secures are tested again, so a unit that left during the call sends the caller to its label then.
- Securing the same unit again only changes the label. A variable holding null secures nothing.
- extraptr variables can't be secured; they are null after every wake. Find the extra again.
- foreach() secures the units it walks over by itself; you don't need to.
Example
dilbegin storyteller();
var
pc : unitptr;
code
{
heartbeat := PULSE_SEC * 5;
:start:
wait(SFB_CMD, command("bow") and (activator.type == UNIT_ST_PC));
pc := activator;
secure(pc, lost);
exec("say Welcome, " + pc.name + ". Sit down and listen.", self);
pause;
exec("say Long ago, a dragon slept under this hill...", self);
pause;
exec("say ...and it sleeps there still.", self);
unsecure(pc);
goto start;
:lost:
exec("say Some people have no patience.", self);
goto start;
}
dilend
An NPC tells a story to the player who bowed. pc survives the pauses because it is secured; if the player walks out, the NPC grumbles instead.
See also
unitdir()
Function (stringlist). Lists the unit files that DIL has stored, by a pattern.
unitdir(pattern : string)
Returns the names of the files in the units directory that match pattern: the files store() writes and restore() and delunit() read. death.zon uses unitdir(".*") at boot to bring back the corpses that were stored before a crash or reboot.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pattern | string | A regular expression that must match the whole file name. "" means all files. |
Returns
Stringlist: the matching file names, in no particular order (the order the directory gives them). Empty when nothing matches or the directory doesn't exist. It fails if pattern fails, is a string variable that has never had a value, or is not a valid regular expression; assigning a failed list leaves the variable as it was.
Notes
- The pattern is a regular expression (Perl style), not a shell wildcard:
".*"is everything,"corpse[.].*"is every name starting with "corpse.", and a plain.matches any character. A shell-style"*"is not a valid expression. - The directory is
units/under the zone's DIL file directory: the sixth column of the zone's line invme/etc/zonelist(death has../lib/death), or elsedil_file_dirinserver.cfg. The zone is that of the program the unit runs; a function from another zone that it calls (f@otherzone) still looks in the calling program's directory. - Only file names are returned, without a path, ready for
restore().
Example
dilbegin aware reload_units();
var
files : stringlist;
u : unitptr;
i : integer;
n : integer;
code
{
files := unitdir("corpse[.].*");
n := length(files);
i := 0;
while (i < n)
{
u := restore(files.[i], null);
if (u == null)
log("reload_units: could not restore " + files.[i]);
i := i + 1;
}
quit;
}
dilend
Brings back every stored unit whose file name starts with "corpse.", into the unit that runs it (restore() with null puts it there); adapted from reload_corpse in death.zon.
See also
unsecure()
Procedure. Ends the secure on a unit.
unsecure(u : unitptr)
Ends what secure() started: the program no longer jumps to the label when u leaves, and from the next wake on the variables holding u are cleared like any other unit variable.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The secured unit. |
Notes
- Call it before destroy() on a secured unit: destroying it fires the secure, the program jumps to the label at once and the rest is skipped.
- It only ends the secures made in the current template call. A unit the caller secured stays secured.
- Nothing happens when the unit isn't secured or the variable is null.
Example
dilbegin token_taker();
var
item : unitptr;
code
{
heartbeat := PULSE_SEC * 3;
:start:
wait(SFB_DONE, command("give") and (target == self));
item := medium;
secure(item, gone);
pause;
act("$1n looks closely at $2n and nods.", A_ALWAYS, self, item, null, TO_ROOM);
unsecure(item);
destroy(item);
goto start;
:gone:
goto start;
}
dilend
An NPC takes what it is given, looks at it, and destroys it. Without the unsecure(), destroy() would jump to gone, which here happens to be harmless, but skips anything written after it.
See also
block
Procedure. Stops the event that woke the program from going any further.
block;
Most often used after wait(SFB_CMD, ...): the command is not carried out, and no program after this one, on this unit or on the units around, gets it. The program then answers the command its own way.
Notes
- It applies to the event that woke the program this time. It can come anywhere before the program waits again (
wait,pause), and it doesn't carry over to the next event. - What it stops depends on the event:
SFB_CMD: the command never runs.SFB_PRE: the spell or the damage that is about to happen doesn't happen.SFB_DONE,SFB_MSGand the others: the event has already happened; only the programs after this one don't hear of it.
- A unit's programs get each event in
fnpriorder, lowest number first. A program that blocks must have a lowerfnprithan the programs it should keep the command from. blockfollowed byquitstill blocks.
Example
dilbegin no_quit();
code
{
:start:
wait(SFB_CMD, command("quit") and (activator.level < IMMORTAL_LEVEL));
block;
act("For your safety you must withdraw from the arena to quit.",
A_ALWAYS, activator, null, null, TO_CHAR);
goto start;
}
dilend
Keeps mortal players from quitting in the arena. Adapted from arena.zon.
See also
priority
Procedure. Keeps the unit's later programs from getting any event until nopriority.
priority;
After priority, the programs that come after this one on the same unit get nothing: no commands, no messages, no ticks. It lasts until this program calls nopriority or ends. It is used so that an NPC busy with something important (a fight, a walk to a rescue, a conversation) isn't pulled away by its other routines, such as random walking.
Notes
- A unit's programs come in
fnpriorder, lowest number first.prioritystops the programs with a higherfnpri(and those with the same one that come later); the ones before it go on as usual. - Only the programs on the same unit are affected. Programs on other units still get every event.
- It lasts through
waitandpause. The usual loop is:start: nopriority; wait(...); priority; ... goto start;. - Forgetting
nopriorityleaves the unit's later programs dead for as long as this program runs. - Ending the program (
quit, or the unit being destroyed) ends the priority too. - Calling it while it is already set changes nothing.
Example
dilbegin fnpri(FN_PRI_RESCUE) john_helpme();
code
{
heartbeat := PULSE_SEC * 10;
on_activation(self.position <= POSITION_SLEEPING, skip);
:start:
nopriority;
wait(SFB_COM, self.position == POSITION_FIGHTING);
priority;
exec("emote yells, 'John! Help!'", self);
sendto(activator.name, findsymbolic("john@haon_dor"));
while (self.position == POSITION_FIGHTING)
pause;
goto start;
}
dilend
Mary calls her husband for help when she is attacked, and her other programs wait until the fight is over. From haon_dor.zon.
See also
nopriority
Procedure. Ends the priority set by this program.
nopriority;
After nopriority, the unit's other programs get events again. When no priority is set it does nothing, so a program can call it at the top of its loop every time.
Notes
- Call it before going back to waiting. A program that waits under
prioritykeeps the unit's later programs dead while it waits. - Ending the program ends the priority too; no
nopriorityis needed beforequit.
Example
dilbegin fnpri(FN_PRI_MISSION) john_assist();
external
integer walk_room@function(s : string, i : integer);
var
tf : integer;
s : string;
code
{
heartbeat := PULSE_SEC * 3;
on_activation(self.position <= POSITION_SLEEPING, skip);
:start:
nopriority;
wait(SFB_MSG, activator.nameidx == "mary");
priority;
s := argument;
tf := walk_room@function("cabin@haon_dor", 4);
exec("kill " + s, self);
pause;
exec("emote screams, 'Murderer, " + s + "!'", self);
goto start;
}
dilend
John runs home to help his wife, with his random walking held back by priority until he goes back to waiting. From haon_dor.zon.
See also
addequip()
Procedure. Puts an object a character carries on, at a given position.
addequip(u : unitptr, pos : integer)
u must be an object in a character's inventory and pos a free position: one of the WEAR_ constants in vme.h (WEAR_FINGER_R 2 to WEAR_ANKLE_R 24). The object is then worn there: its light counts for the wearer, and its transfer affects (see addaff()) go on the wearer until it is taken off.
It does this silently. There are no messages, and it isn't the wear command, so programs waiting for that command don't hear of it. To let the character wear something the ordinary way, use exec("wear " + ..., ch).
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The object, in the inventory of a player or NPC. |
| pos | integer | The WEAR_ position.
|
Notes
- Nothing happens, and nothing tells you, when
uisn't an object, isn't directly in a character, or the position is taken. Testu.equipafterwards, or check first with equipment(). - Nothing is checked about the object: whether it can be worn there (its
MANIPULATE_WEAR_flags), its size, or whetherposis a real position. A position that isn't one of theWEAR_values makes an object that counts as worn but shows nowhere. The position is kept in a byte: 256 is 0, and 0 does nothing. - Don't call it on an object that is already worn: the object moves to the new position and its light and transfer affects are applied a second time, and taking it off removes only one set. unequip() it first.
- Pass a variable. A null straight from a function (such as
equipment()for an empty position) stops the program with a type error in the zone log.
Example
dilbegin cuff(targ : unitptr, cuffs : unitptr);
code
{
act("$1n puts $2n around $3n's wrists.", A_SOMEONE, self, cuffs, targ, TO_NOTVICT);
link(cuffs, targ);
unequip(equipment(targ, WEAR_WRIST_R));
addequip(cuffs, WEAR_WRIST_R);
}
dilend
Puts handcuffs on a character's right wrist, taking off whatever was worn there, as cuff_target in midgaard.zon does.
See also
unequip()
Procedure. Takes off an object a character is wearing.
unequip(u : unitptr)
The object stays in the character's inventory but is no longer worn: its light stops counting for the wearer and its transfer affects come off the wearer. Like addequip() it is silent: no messages, and it isn't the remove command.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The worn object. |
Notes
- Nothing happens when
uis null, isn't an object, or isn't worn. Sounequip(equipment(ch, WEAR_WIELD))is safe when nothing is wielded. - To take the object away from the character as well, link() it somewhere after unequipping it.
Example
dilbegin disarm(victim : unitptr);
var
wpn : unitptr;
code
{
wpn := equipment(victim, WEAR_WIELD);
if (wpn == null)
return;
unequip(wpn);
link(wpn, victim.outside);
act("$1n knocks $2n out of $3n's hands.", A_ALWAYS, self, wpn, victim, TO_ROOM);
act("$1n knocks $2n out of your hands.", A_ALWAYS, self, wpn, victim, TO_VICT);
}
dilend
Takes the wielded weapon from a character and drops it on the floor.
See also
delete_player()
Procedure. Deletes a player character for good.
delete_player(pname : string)
If the player is connected, the character is taken out of the game and the connection closed; otherwise any copy of the character still in the game (a link-dead one) is taken out. Then the player's file and saved inventory are deleted. The name is matched without regard to case.
Only a program started in a zone with access level 0 (the fourth column of vme/etc/zonelist) can use it. What counts is the zone of the program's first template, the one that was dilcopy'd or run as a command. Elsewhere the zone log gets "attempt to violate system access security (delete_player)" and the program stops.
Parameters
| Name | Type | Meaning |
|---|---|---|
| pname | string | The character's name. |
Notes
- It doesn't say whether there was such a player. Check with isplayer() first if it matters.
- Nothing is saved first, and nothing else is cleaned up: records elsewhere that name the player (a clan, for one) stay. The
deletecommand in commands.zon makes the player leave the clan (cdefect) before deleting. - A program that deletes the player it runs on goes with the character: put nothing after it but
quit.
Example
dilbegin cmd_delete(arg : string);
code
{
if (self.type != UNIT_ST_PC)
quit;
if (arg != "self forever")
{
sendtext("To delete your character type: delete self forever<br/>", self);
quit;
}
sendtext("If you are sure, say 'delete me'. Anything else aborts.<br/>", self);
wait(SFB_CMD, self == activator);
if (command("say") and (argument == "delete me"))
{
block;
delete_player(self.name);
quit;
}
sendtext("Deletion aborted.<br/>", self);
quit;
}
dilend
A player command that deletes the player's own character after asking once more, as the delete command in commands.zon does.
See also
dilcopy()
Procedure. Starts a copy of a DIL template on a unit.
dilcopy(s : string, u : unitptr)
Puts a new program on u, made from the template named in s, with the
arguments written in the string: "name@zone(arg1,arg2,...)". It is the run-time
version of the dilcopy line in a zone file. The new program starts at the unit's
next tick, within about a second.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The template and its arguments: "name@zone" or "name@zone(a,b,...)".
|
| u | unitptr | The unit to put the program on. |
Notes
- Only
stringandintegerarguments can be given; a template with list or unit arguments can't be copied this way. - The arguments are the text between the brackets, cut at every comma, up to the first
). So a string argument can't hold a comma or a), and has no quotes around it. Spaces are kept in strings; write no space after the commas. Integers must be plain numbers. - An empty argument is lost, except the first:
"x@zone(a,0,5,)"passes three arguments, not four. Pass a word such asnoneinstead. - No space between the name and the
(. - A template that isn't found, or gets the wrong number or kind of arguments, isn't started; the zone log of
u's zone says "Template ... not found" or "had mismatching argument count". - A
uniquetemplate isn't started on a unit that already runs it. - The second argument can't be the word
null(vmc refuses it). A null unit variable does nothing. - The string must be shorter than 12288 characters (
MAX_STRING_LENGTH): a longer one stops the server.
Example
dilbegin give_reward(pc : unitptr);
var
item : unitptr;
code
{
item := load("canbelt@hallows23");
dilcopy("ply_restrict@function(" + pc.name + ",0,25,quest_act@gnome)", item);
link(item, pc);
act("You receive $2n.", A_ALWAYS, pc, item, null, TO_CHAR);
return;
}
dilend
Gives a quest reward that only this player may use, as in hallows23.zon.
See also
sendtext()
Procedure. Sends a text to one character's screen, exactly as it is.
sendtext(text : string, u : unitptr)
The plain way to talk to one player. Nothing is added or filled in: end each line with
<br/> yourself, and put names in with +. Text in the game is
HTML; the web client shows it as such, and a telnet player gets it turned into plain text with
their colours.
Parameters
| Name | Type | Meaning |
|---|---|---|
| text | string | The text, with <br/> where lines end.
|
| u | unitptr | The character to send it to. |
Notes
- It reaches whoever is connected to
u: a player, or the god switched into an
NPC. To an NPC with nobody in it, an object, a room or null it sends nothing, and an empty text sends nothing.
- Unlike act() it ignores whether
uis asleep or can
see anything; use act() for what happens in the room, so that each one sees names as they should.
- For long text that should be shown a page at a time, use
pagestring().
Example
dilbegin who_follows(pc : unitptr);
var
mast : unitptr;
code
{
mast := pc.master;
if (mast == null)
sendtext("You are not following anyone.<br/>", pc);
else
sendtext("You are following " + mast.name + ".<br/>", pc);
quit;
}
dilend
Tells a player whom they follow, as the follow command in commands.zon does.
See also
change_speed()
Procedure. Delays a fighting character's next attacks.
change_speed(u : unitptr, delay : integer)
Holds back a character in combat: its next attacks come later. Every combat round
(PULSE_VIOLENCE, 3 seconds) gives a fighter 12 points of time, so
change_speed(u, PULSE_VIOLENCE), which is 12, costs it one round. Spells and skills
use it for stuns and for the time a quaffed potion or a spell takes in a fight.
This is not the speed field.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The character. |
| delay | integer | The delay, in quarter seconds (PULSE_SEC is 4).
|
Notes
- It only works on a character that is in a fight. On anyone else, or null, nothing happens.
- The delay is at least 4 (at normal speed), so a small, zero or negative
delaystill costs 4: it can't speed anyone up. - The delay is scaled by the character's speed: a character with speed 6, twice as fast as the usual 12, loses half as much.
Example
dilbegin stun_blow(tgt : unitptr);
code
{
if (tgt.position != POSITION_FIGHTING)
return;
act("You reel from the blow!", A_ALWAYS, tgt, null, null, TO_CHAR);
act("$1n reels from the blow!", A_SOMEONE, tgt, null, null, TO_REST);
change_speed(tgt, PULSE_VIOLENCE); // loses one combat round
return;
}
dilend
Stuns a fighting character for one round, as in spells.zon.
See also
transfermoney()
Function (integer). Moves money from one character to another, or creates or destroys it.
transfermoney(from : unitptr, to : unitptr, amount : integer)
The amount is a value, not a number of coins: one iron piece is worth IRON_MULT (10), a copper piece COPPER_MULT (80) and so on up to PLATINUM_MULT (all in vme/include/vme.h). The server picks the coins and gives change, so a character with a gold piece can pay 3 copper.
- Both units given: the money moves from
fromtoto, iffromcan afford it. fromnull: new money is made and given toto. vme.log gets a line "<name> was given ... by DIL <unit>".tonull: the money is taken fromfromand destroyed, iffromcan afford it.
Parameters
| Name | Type | Meaning |
|---|---|---|
| from | unitptr | The character who pays, or null to make new money. |
| to | unitptr | The character who gets the money, or null to destroy it. |
| amount | integer | The value to move. |
Returns
TRUE when the money was moved. FALSE when from can't afford it, or both units are null (nothing happens then). It fails when a unit is not a character (an object or a room).
Notes
- The amount is rounded to the nearest iron piece (10), and is at least one iron piece. An amount of 0 or less therefore moves one iron piece. Test
amount > 0first, as the pick pocket skill in skills.zon does. - Only the coins a character carries directly count; money in a bag doesn't.
- With
fromnull, check the amount: the money is real and players keep it.
Example
dilbegin integer charge(pc : unitptr, price : integer);
code
{
if (price <= 0)
return (TRUE);
if (not transfermoney(pc, self, price))
{
exec("say That costs " + moneystring(price, TRUE) + ", which you don't have.", self);
return (FALSE);
}
exec("say Thank you, " + pc.name + ".", self);
return (TRUE);
}
dilend
An NPC takes a price from a player, as the repair shops in midgaard.zon do.
See also
set_fighting()
Procedure. Starts a fight between two characters.
set_fighting(u : unitptr, t : unitptr)
Makes u fight t. t gets u as an opponent (its opponentcount and opponent() show it), but its own fighting stays null, and its position unchanged, until its first combat round picks whom to hit. If
u isn't fighting yet, t becomes the one it hits. If u is
fighting already, t joins its opponents, but u goes on hitting the one
it was hitting. No blow is struck now: the combat rounds that follow do that.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The attacker. |
| t | unitptr | The one attacked. |
Notes
- Both must be characters (players or NPCs). Otherwise, or when either is null, or
uist, nothing happens. u's position becomes fighting, even if it was asleep.t's position isn't changed.- It checks nothing else: not whether the two are in the same room, can see each other, or may fight at all (player killing,
CHAR_PEACEFUL). Check that first. - It gives no message; use act().
Example
dilbegin no_backstab();
var
pc : unitptr;
code
{
:start:
wait(SFB_CMD, command("backstab") and (activator.type == UNIT_ST_PC) and
(self.position >= POSITION_RESTING));
pc := activator;
secure(pc, start);
block;
act("$3n turns around just in time!", A_SOMEONE, pc, null, self, TO_CHAR);
act("$3n turns around and catches $1n!", A_SOMEONE, pc, null, self, TO_REST);
set_fighting(self, pc);
unsecure(pc);
goto start;
}
dilend
An NPC that can't be backstabbed: it blocks the command and attacks the player, as command_block in basis.zon does.
See also
setweight()
Obsolete. setweight() was removed from DIL in 2020; vmc no longer knows the name.
Two procedures replace it:
- set_weight_base(u, w) sets the unit's own (empty) weight, and changes its total weight and the weight of whatever holds it by the same amount;
- set_weight(u, w) sets the unit's total weight, and changes the weight of whatever holds it to match.
To add or take liquid from a drink container, change its weight with set_weight().
setbright()
Procedure. Sets how much light a unit gives.
setbright(u : unitptr, light : integer)
Sets the bright value of u, the light it sheds, and
changes the light around it by the same amount: the room or container it is in, and a
character who wears or holds it. A torch with 1 or more lights up a dark room; a negative value
darkens. The bright field can't be assigned; this is how it is changed.
Parameters
| Name | Type | Meaning |
|---|---|---|
| u | unitptr | The unit. |
| light | integer | The new light value. |
Notes
- Works on every kind of unit. With a null unit nothing happens.
- The value is a 16-bit number: outside -32768 to 32767 it wraps around.
- The light inside a unit is the light field; whether a room can be seen in, islight().
Example
dilbegin burn_down(minutes : integer);
code
{
heartbeat := PULSE_SEC * 60;
setbright(self, 2);
while (minutes > 0)
{
pause;
minutes := minutes - 1;
}
setbright(self, 0);
quit;
}
dilend
A torch that burns for a given number of minutes and then goes out.
See also
log()
Procedure. Writes a line to the server log.
log(s : string)
Writes s to vme.log (in vme/bin), after the time and the
name of the zone: zone/text. The zone is that of the unit the program runs on,
which for a program on a player is _players. The line is also added to that zone's
.err file in the zone directory (zondir in server.cfg),
and gods who follow the log in the game see it as (LOG: zone/text).
Use it for errors a builder or admin should see, and for tracing a program while writing it. Players never see it.
Parameters
| Name | Type | Meaning |
|---|---|---|
| s | string | The text. |
Notes
vme.logstarts empty at every boot.- The server stops itself when it has written 80 MB of log since boot ("Log-file insanely big! Going down."). Don't log on every tick, every command, or in a loop.
- A null string writes nothing.
Example
dilbegin count_inside(u : unitptr);
var
n : integer;
item : unitptr;
code
{
item := u.inside;
while (item != null)
{
n := n + 1;
item := item.next;
}
if (n > 50)
log(u.symname + " holds " + itoa(n) + " units");
return;
}
dilend
Counts the units in a container and logs it when there are suspiciously many.
See also
send()
Procedure. Sends a message to the DIL programs around the unit.
send(msg : string)
Every DIL program around the program's own unit that is waiting for SFB_MSG (in a wait() or an interrupt()) gets the message. The receivers run at once, before send() returns. In each of them argument is the message and activator is the sender's unit; medium and target are null.
"Around" is the unit the sender is in (usually a room, but it can be a character or a container), and in this order:
- the programs on that unit itself;
- what the sender contains (its inventory and equipment);
- every unit in it, and what is in the transparent ones there;
- what the characters there wear, but not what they carry.
A sender that is a room reaches the units directly in it.
Parameters
| Name | Type | Meaning |
|---|---|---|
| msg | string | The message. Receivers usually compare it with argument.
|
Notes
- The sending program never gets its own message. The other programs on the sender's unit get it only if they are aware.
- A program that isn't waiting for
SFB_MSGat that moment misses the message; it isn't kept for later. - A receiver that does block stops the message there: the units after it don't get it. A receiver holding priority keeps it from the later programs on its own unit.
- Afterwards the sender's secures are tested: if a receiver moved a secured unit away, the sender goes to that secure's label.
- An empty (null) string sends nothing.
- To reach the programs on one particular unit use sendto(); for every copy of a template in the game, sendtoalldil().
Example
dilbegin dinner_bell();
code
{
:start:
wait(SFB_CMD, command("pull") and (activator.type == UNIT_ST_PC));
block;
act("You pull the rope and the bell rings.", A_ALWAYS, activator, null, null, TO_CHAR);
act("$1n pulls the rope and the bell rings.", A_ALWAYS, activator, null, null, TO_ROOM);
send("dinner");
goto start;
}
dilend
dilbegin hungry_orc();
code
{
:start:
wait(SFB_MSG, argument == "dinner");
exec("say Food!", self);
goto start;
}
dilend
A bell (an object in the room) tells everyone there that dinner is served, and each orc with hungry_orc answers. The orc chief in haon_dor.zon calls his orcs the same way with send("stew").
See also
sendto()
Procedure. Sends a message to the DIL programs on one unit.
sendto(msg : string, u : unitptr)
Every DIL program on u that is waiting for SFB_MSG (in a wait() or an interrupt()) gets the message. The receivers run at once, before sendto() returns. In each of them argument is the message and activator is the sender's unit; medium and target are null.
The unit can be anywhere in the game. Only the programs on u itself get the message, not those on what it contains.
Parameters
| Name | Type | Meaning |
|---|---|---|
| msg | string | The message. Receivers usually compare it with argument.
|
| u | unitptr | The unit whose programs get it. |
Notes
sendto(msg, self)reaches the other programs on the sender's own unit, aware or not. The sending program itself never gets its own message.- A program that isn't waiting for
SFB_MSGat that moment misses the message; it isn't kept for later. - The programs on
uget it in fnpri order. One that does block or holds priority keeps it from the ones after it. - Nothing happens when
uor the message is null. - Afterwards the sender's secures are tested: if a receiver moved a secured unit away, the sender goes to that secure's label.
Example
dilbegin call_captain();
var
capt : unitptr;
code
{
heartbeat := PULSE_SEC * 30;
:start:
wait(SFB_COM, TRUE);
capt := findsymbolic("captain@ex");
if (capt != null)
sendto("alarm " + self.outside.name, capt);
pause;
goto start;
}
dilend
dilbegin captain();
code
{
:start:
wait(SFB_MSG, "alarm" in argument);
exec("shout To arms! " + activator.name + " needs help!", self);
goto start;
}
dilend
A guard in a fight calls the captain, wherever the captain is, at most every 30 seconds. In haon_dor.zon the orc chief tells Mary she has lost her pot with sendto("gotit", u1).
See also
sendtoall()
Procedure. Sends a message to every copy of a unit in the game.
sendtoall(m : string, s : string)
Sends the message m to every unit in the game made from the definition
s ("name@zone", e.g. every "bag@arena"). Each DIL
program on those units that waits for SFB_MSG wakes up with m in
argument, and the sending unit as activator and medium.
To reach the programs made from one template, wherever they run, use sendtoalldil(); to reach one unit, sendto().
Parameters
| Name | Type | Meaning |
|---|---|---|
| m | string | The message. |
| s | string | The units' symbolic name with its zone, "name@zone".
|
Notes
- Without the
@zone, or for a name that doesn't exist, nothing is sent. - The messages are delivered at once, before
sendtoall()returns: the receivers run first. - A program waiting for something else gets nothing (unless an
interrupt(SFB_MSG, ...)catches it). - If the sending unit is itself such a unit, its own programs get the message only when they are
aware. - A program that blocks or takes
prioritykeeps the message from the programs after it on the same unit.
Example
dilbegin arena_over();
code
{
sendtoall("emptyout", "bag@arena");
quit;
}
dilend
dilbegin bag_wait();
code
{
:start:
wait(SFB_MSG, argument == "emptyout");
if (self.outside.type == UNIT_ST_PC)
act("Your $2N disappears.", A_SOMEONE, self.outside, self, null, TO_CHAR);
destroy(self);
quit;
}
dilend
When the arena closes, every arena bag in the game vanishes, as in arena.zon.
See also
sendtoalldil()
Procedure. Sends a message to every running copy of a DIL template.
sendtoalldil(m : string, s : string)
Sends the message m to every program in the game made from the template
s ("name@zone"), on whatever unit it runs. Each such program that waits
for SFB_MSG wakes up with m in argument, the sending unit
as activator and medium, and its own unit as target.
channel@function uses it to carry the chat channels to every player.
Parameters
| Name | Type | Meaning |
|---|---|---|
| m | string | The message. |
| s | string | The template's name with its zone, "name@zone".
|
Notes
- Without the
@zone, or for a template that doesn't exist, nothing is sent. - The sending program itself never gets the message. Another copy on the same unit gets it only when it is
aware. - Only programs made from that template (copied onto a unit) are reached, and only while they are in the template itself: one that waits inside a function it called gets nothing, and so does a program of another template that calls
sas a function. - The messages are delivered at once, before
sendtoalldil()returns: the receivers run first. - A program waiting for something else gets nothing (unless an
interrupt(SFB_MSG, ...)catches it).
Example
dilbegin raise_alarm();
code
{
sendtoalldil("alarm " + self.outside.title, "gate_guard@castle");
quit;
}
dilend
dilbegin gate_guard();
var
s : string;
w : string;
code
{
:start:
wait(SFB_MSG, "alarm" in argument);
s := argument;
w := getword(s); // takes "alarm" off s
exec("shout To arms! Trouble at " + s + "!", self);
goto start;
}
dilend
Raises the alarm with every gate guard (template gate_guard in a zone named castle), wherever the guards are.
See also
cast_spell()
Function (integer), or Procedure with four arguments. Casts a spell without mana or the caster's own casting.
cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr, effect : string) : integer cast_spell(spell : integer, caster : unitptr, medium : unitptr, tgt : unitptr);
Makes the spell happen as if caster had cast it through medium on tgt: no mana is used, the caster's position, fighting and casting time don't matter. It's how magic items work: a potion, a ring that heals, a weapon that strikes with lightning. The success roll uses the medium: an object's power, or a character's own ability and skill in that spell.
With five arguments it is a function and returns the result; with four it is a procedure (cast_spell(i, self, self, u); as a statement), with no effect argument.
Parameters
| Name | Type | Meaning |
|---|---|---|
| spell | integer | The spell, a SPL_* constant from vme/include/values.h (such as SPL_CURE_WOUNDS_1, SPL_BLESS).
|
| caster | unitptr | The character who casts it; the spell's messages treat it as the caster. |
| medium | unitptr | What the magic comes from: the object (potion, ring, wand) or the caster itself. |
| tgt | unitptr | The target of the spell. In the procedure form it may be null. |
| effect | string | "" for the spell's ordinary messages, or a template "name@zone" that shows the effect instead. It must take three arguments (unitptr, unitptr, integer): the two units of the spell and the amount (-1 or less when the spell failed). It runs on the caster.
|
Returns
The function form returns the spell's result: for most spells the success roll, above 0 when the spell worked; -1 when the spell can't be cast like this or not on that target. 0 when spell isn't a castable spell number (a spell group, or a spell that isn't implemented). The call fails, and the variable assigned keeps its old value, when caster is null or not a character, or medium or tgt is null.
Notes
- The spell must allow being cast as a spell (
MEDIA_SPELLin itsmediumsinvme/etc/spells.def); otherwise the caster is told "This spell wasn't meant to be there! Please report." and nothing happens. - A target the spell can't take gets "The magic disappears when cast on ...".
- An offensive spell counts as an attack by
casterfor the law. - Spells don't all pass the two units to the effect template in the same order: some pass the medium first, most of those in spells.zon the target first. Check the spell before writing an effect.
- Programs on the units can block the cast as they block an ordinary
castcommand. - The spell can kill the target. Afterwards the program's secures are checked at once.
Example
dilbegin ring_glow(medi : unitptr, targ : unitptr, hm : integer);
code
{
act("Your $2N glows softly.", A_ALWAYS, self, medi, targ, TO_CHAR);
return;
}
dilend
dilbegin heal_ring();
var
n : integer;
code
{
:start:
wait(SFB_CMD, command("say") and (activator == self.outside)
and ("heal" in argument) and (self.equip != 0));
n := cast_spell(SPL_CURE_WOUNDS_1, self.outside, self, self.outside,
"ring_glow@ex");
pause;
goto start;
}
dilend
A ring that heals its wearer when the wearer says "heal", with its own message, as the claws in arena.zon do. The example zone is called ex.
See also
attack_spell()
Function (integer). Hits a target with an offensive spell and returns the damage.
attack_spell(spell : integer, caster : unitptr, medium : unitptr, target : unitptr,
bonus : integer, effect : string)
The building block of the attack spells in spells.zon. It rolls the spell against
the target the way the server rolls any offensive spell: the caster's and target's spell
skills, the target's armour and shield, an open roll, then the spell's damage chart. Then it
deals the damage as a spell hit. That is an attack: the target fights back, and the caster may
commit a crime.
A spell's own template (the func of the spell in spells.def) normally
calls it with the arguments it was given, as in the example.
Parameters
| Name | Type | Meaning |
|---|---|---|
| spell | integer | The spell, an SPL_ constant from vme/include/values.h. Only spells from SPL_GROUP_MAX (12) to 499 that have a C function or a DIL template count.
|
| caster | unitptr | Who casts it. Must be a character. |
| medium | unitptr | What it is cast through: the caster, a wand, a scroll... Must not be null. |
| target | unitptr | Who is hit. Must be a character (see Notes). |
| bonus | integer | Added to the attack roll: positive helps the caster, negative hinders. |
| effect | string | "" for the usual hit messages, or the name of a DIL template (name@zone) that shows the effect instead.
|
Returns
Integer: the damage dealt. 0 or less is a miss; 0 also when the target's shield blocked the spell. A spell number outside the range, or one without a function, gives 0 and does nothing.
It fails when caster is null or not a character, when medium or
target is null, or when an argument is itself a failed value.
Notes
- The target must be a character. Only null is checked: an object or a room as the
target stops the server at once.
- Pass a string as
effect, never the constantnull. vmc accepts
null, but at run time the result is then a type error and the program stops
("DIL SERIOUS ... Type error in ...").
- The effect template must take
(medium : unitptr, target : unitptr, hm : integer).
It is copied onto the caster and run at once, withactivatorthe caster andhmthe damage. While it is found, the standard hit and miss messages are not shown; the damage is dealt either way. A template with other arguments is logged and ignored.
- Immortal targets take no damage, nor do two characters who may not attack each other
(player killing rules).
- If a secured unit died or left during the hit, the program jumps to that secure's label
straight after the call.
Example
dilbegin holy_word_1(med : unitptr, targ : unitptr, arg : string,
hm : integer, effect : string);
code
{
if ((targ.alignment >= 0) or (hm <= 0))
{
act("Nothing happens.", A_ALWAYS, self, null, null, TO_CHAR);
quit;
}
if (targ.alignment >= -350)
hm := attack_spell(SPL_HOLY_WORD, self, med, targ, 0, effect);
else
hm := attack_spell(SPL_HOLY_WORD, self, med, targ, +10, effect);
quit;
}
dilend
The holy word spell from spells.zon: it hurts only evil targets, and the very evil ones more.
See also
insert()
Procedure. Puts a new entry into a stringlist or an intlist at a given position.
insert(list : stringlist or intlist, i : integer, value : string or integer)
The entries from position i on move up one place. Positions count from 0, so
insert(sl, 0, s) puts s first. It works on a list variable and on the
list fields of an extra (ex.names, ex.vals,
u.extra.["name"].names), which is how comm.zon keeps a player's tell history
newest first.
Parameters
| Name | Type | Meaning |
|---|---|---|
| list | stringlist or intlist | The list to change: a variable or a list field, not a function's result. |
| i | integer | The position the new entry gets. |
| value | string or integer | The new entry. An integer put into a stringlist becomes its digits; a string put into an intlist becomes its number, as with atoi().
|
Notes
- A stringlist and an intlist treat a position past the end differently. In a stringlist,
empty strings fill the gap:insert(sl, 5, "x")on an empty list gives six entries, the last"x". In an intlist, a position past the end, or below 0, adds nothing;iequal to the length adds at the end.
- Never give a stringlist a negative position. It stops the server. A huge position makes
it try to build a list that long.
- When
iis a failed value (a field of null), the entry goes in at position 0. - An unset string inserts nothing.
Example
dilbegin add_history(ch : unitptr, s : string);
var
ex : extraptr;
code
{
ex := "$tell_history" in ch.extra;
if (ex == null)
{
addextra(ch.extra, {"$tell_history"}, "history");
ex := "$tell_history" in ch.extra;
}
insert(ex.names, 1, s);
while (length(ex.names) > 21)
remove(ex.names, length(ex.names) - 1);
return;
}
dilend
Keeps the 20 latest tells behind the extra's name, newest first, as comm.zon does.
See also
interrupt()
Function (integer). Sets up a jump to a label when a certain event wakes the program, whatever it is waiting for.
interrupt(flags : integer, condition, label) : integer
Registers an interrupt for the running template. From then on, every time the program is woken by an event of a kind in flags, the condition is evaluated before anything else; when it is true, the program leaves whatever it was doing (a wait, a pause) and goes on at label. The program is woken by those events even when its wait asks for other ones. Typical use: a long-running NPC program that should react to a message or to its own death at any moment.
Parameters
| Name | Type | Meaning |
|---|---|---|
| flags | integer | : SFB_CMD, SFB_MSG, SFB_TICK, SFB_DEAD, SFB_COM, SFB_DONE... Write the constants themselves (see the notes).
|
| condition | integer expression | Tested at each such event, with activator, argument, command() and the rest describing that event.
|
| label | label | Where to go on when the condition is true, or skip to ignore the event: the program then stays where it was and the event goes no further in it.
|
Returns
The number of the interrupt, for clear(). It can be used as a statement on its own (interrupt(SFB_MSG, argument == "stop", stop_it);) or assigned (i := interrupt(...);), but not inside an expression.
Notes
- The interrupt stays set until
clear()or until the template returns: it fires every time, not once. Running the sameinterruptstatement again replaces it instead of adding a second one. - When several interrupts match an event, they are tried from the lowest number up, and the first whose condition is true wins.
- An interrupt whose
flagsincludeSFB_ACTIVATEis tested at every wake, and is removed the first time it jumps to a label.on_activation(cond, label)is a macro invme/include/wmacros.hforinterrupt(SFB_ACTIVATE, cond, label). - Interrupts belong to the template that set them: a template called from it doesn't see them, and they end when it returns. With
recall, the main template's interrupts are saved and restored with the program. - The flags must be a constant expression such as
SFB_MSG | SFB_CMD. A variable holding the flags is read as 0, and that interrupt never fires. - Unit variables are cleared at the wake as usual: at the label, find the units again or keep them with
secure.
Example
dilbegin guard_post();
var
i : integer;
code
{
heartbeat := PULSE_SEC * 30;
i := interrupt(SFB_MSG, argument == "stand down", relieved);
:loop:
wait(SFB_TICK, TRUE);
act("$1n looks around watchfully.", A_SOMEONE, self, null, null, TO_ROOM);
goto loop;
:relieved:
clear(i);
act("$1n relaxes and stops guarding.", A_SOMEONE, self, null, null, TO_ROOM);
quit;
}
dilend
An NPC that keeps watch every 30 seconds until another program sends it the message "stand down" (sendto("stand down", guard)).
See also
clear()
Procedure. Removes an interrupt set up with interrupt().
clear(i : integer);
Removes interrupt number i of the running template, the number that interrupt() returned. The program then no longer jumps to that interrupt's label.
Parameters
| Name | Type | Meaning |
|---|---|---|
| i | integer | The interrupt's number, as returned by interrupt().
|
Notes
- A number that isn't in use does nothing.
- The interrupts after the cleared one move down a place, so their numbers change: interrupt 2 becomes 1 after
clear(1). Clearing several, clear the highest number first, or set them up again. - It only reaches the interrupts of the template that runs
clear, not those of a template that called it. - Running the same
interrupt()statement again replaces the old one, so there is no need to clear it first.
Example
dilbegin guard_post();
var
i : integer;
code
{
heartbeat := PULSE_SEC * 30;
i := interrupt(SFB_MSG, argument == "stand down", relieved);
:loop:
wait(SFB_TICK, TRUE);
act("$1n looks around watchfully.", A_SOMEONE, self, null, null, TO_ROOM);
goto loop;
:relieved:
clear(i);
act("$1n relaxes and sits down.", A_SOMEONE, self, null, null, TO_ROOM);
pause;
act("$1n stands up and goes back to the post.", A_SOMEONE, self, null, null, TO_ROOM);
i := interrupt(SFB_MSG, argument == "stand down", relieved);
goto loop;
}
dilend
An NPC on guard that takes a break when told "stand down"; while it rests, the message does nothing.
See also
on_activation()
Function (integer).
on_activation(condition, label) : integer on_activation(condition, skip) : integer
Sets a check that runs every time the program is woken, by any event, before the event reaches the program's wait() or pause. When the condition is true, the program either ignores the event (skip) or jumps to label. The usual use is to make a monster deaf while it sleeps or fights: on_activation(self.position == POSITION_FIGHTING, skip);.
It is a macro in wmacros.h for interrupt(SFB_ACTIVATE, condition, label), so the zone needs #include <macros.h> (as every zone has).
Parameters
| Name | Type | Meaning |
|---|---|---|
| condition | integer | an expression, checked at every wake |
| label | label | where to jump when it is true; or skip to ignore the event
|
Returns
The number of the interrupt, for clear(). Most programs don't keep it.
Notes
- With
skip: while the condition is true, every event is dropped. The program stays where it was, the event isn't kept for later, and the program can'tblockit. The check stays set. - With a label: when the condition is true the program jumps to the label and the check is removed. Call
on_activation()again after the label to set it again. - Running the same
on_activation()line again replaces the check it set before; it doesn't add a second one. - The checks belong to the template that set them: they end when that template returns or quits.
- The checks and the
interrupt()s of a template are tried in the order of their numbers; the first one that is true wins. - The check runs after the program's unit and extra variables have been cleared for the new wake (see
secure()), so useself,activatorand secured variables in the condition. clear()with the returned number removes the check. Removing one moves the numbers of the checks set after it down by one.
Example
dilbegin answer();
code
{
on_activation((self.position <= POSITION_SLEEPING) or
(self.position == POSITION_FIGHTING), skip);
heartbeat := PULSE_SEC * 3;
:start:
wait(SFB_CMD, command("say") and ("hello" in argument));
exec("say Hello, " + activator.name + ".", self);
goto start;
}
dilend
dilbegin wakeup();
var
i : integer;
code
{
heartbeat := PULSE_SEC * 5;
:watch:
i := on_activation(self.position == POSITION_SLEEPING, asleep);
:start:
pause;
goto start;
:asleep:
exec("emote snores loudly.", self);
wait(SFB_TICK, self.position != POSITION_SLEEPING);
exec("emote yawns.", self);
goto watch;
}
dilend
answer greets players but not while asleep or fighting, as many monsters in udgaard.zon do; wakeup jumps to a label when its monster falls asleep and sets the check again after waking.
See also
Where to go next
The chapters cover the language; each keyword has its own page in the Full Listing. To go further:
Read working programs
The public zones in vme/zone/ of the DikuMUD3 repository are full of DIL that runs in the game. Search them for the function you need. function.zon holds common helpers (wander_zones, rescue, max and many more), quests.zon the quest functions every quest should use, and commands.zon, baseget.zon, basemove.zon and baselook.zon the player commands written in DIL. DIL Examples has a few short ones explained.
Try a program quickly
- Compile with
-mto rebuild only the zones that changed:cd vme/zone; ../bin/vmc -m -d ../etc/ -I../include/ *.zon.-schecks the syntax without writing anything. The server reads zones only when it starts, so restart it afterwards. vme -wruns the server time-warped: it doesn't sleep between ticks, so heartbeats,pauseand the mud clock pass as fast as the computer allows. On a running game, a god'swtimewarp <seconds>does the same for that many seconds of game time. A program with a 90-second heartbeat can then be tried in moments.- log() writes a line to
vme/bin/vme.log, which is the quickest way to see what a program does. The same log has the errors of running programs: "had endless loop", "Type error in ...", "Template ... not found", "Cannot resolve external reference". It starts empty at every boot, so keep a copy before restarting if you need it. - In the game, a god's
wstat <unit> functionslists the programs a unit runs, in their order, andwstat world dilhow much time and how many instructions each template has used.
The DIL test zone
vme/zone/test.zon holds tests of DIL itself, run automatically. With vme/etc/zonelist.test as the zone list, a "lab director" program copies each test template onto a room in turn, from T0nn (the number TEST_MAXIMUM) down to T001; each test does its work, logs its result with logtest(), and sends "done" back with sendtoalldil(). When all have run, the server stops, with exit code 0 if every test passed. vme/bin/intergration_test.sh runs them time-warped. A new test is one more template T0nn and a higher TEST_MAXIMUM. DIL_UNIT_TESTING.md in the repository's top folder explains how to run them.
The zone manual
DIL lives in zone files. The Zone Manual explains the rest of them: rooms, objects, NPCs, resets, and the macros in vme/include; its DIL section chapter is about where DIL goes in a zone.
When the manual is wrong
The pages of this manual were checked against the compiler and the server. Where a page and the code still disagree, the code is right: the keywords are in vme/src/vmc/diltok.h, the grammar in vme/src/vmc/dilpar.y, the functions in vme/src/dilexp.cpp, the procedures and statements in vme/src/dilinst.cpp, and the fields in vme/src/dilfld.cpp. Please report such mistakes, and bugs in DIL itself, on GitHub.