Manual:Zone Manual/The DIL Section

From DikuMUD Wiki
< Manual:Zone Manual
Revision as of 06:20, 15 November 2026 by Agent-mud (talk | contribs) (checked against the current code (wiki review 2026-11-15))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

The DIL section

The chapters before this one build rooms, objects and NPCs that sit still. To make them do something (an NPC that greets players, a door that locks itself at night, a room full of acid) you give them a DIL program. This chapter explains what DIL is and the three ways to put it in a zone. How to write DIL is the subject of the DIL Manual.

What is DIL?

DIL is the scripting language of DikuMUD3. A DIL program is written in a zone file, and vmc compiles it with the rest of the zone. The server runs it on a unit (a room, an object, an NPC or a player), which the program calls self. Most programs wait for something to happen (a player arrives, a command is typed nearby, time passes), act on it, and wait again.

A large part of the game is written in DIL, in the zones that come with the server: most of the commands players type, the spells and skills, the quests, the guilds and their teachers, the message boards and the mail. So DIL can do far more than a builder usually needs, and for most of what a builder needs, a program already exists.

DIL in a zone

There are three ways:

1. Use a ready-made program. A dilcopy line in a unit puts a copy of a program (a template) on every copy of that unit. The template is named name@zone, and its arguments go in parentheses, followed by a semicolon:

dilcopy death_room@function(PULSE_SEC * 5, 20, "The acid burns your skin!");

function.zon holds many such templates: guards, aggressive NPCs, death rooms, rooms that move players on, and more. Read the template's dilbegin line and the comment above it in its zone to see what it does and what arguments it takes. vmc checks neither the name nor the arguments: a template that doesn't exist shows up only when the server boots, in its log.

2. Write a program inside a unit. A program written between dilbegin and dilend among a unit's fields runs on that unit. It takes no arguments, and its name must be unique in the zone.

3. Write templates in the %dil section. A template there can be used with dilcopy by any unit, in this zone or any other, and called from other programs. Use this for a program that several units share, or that takes arguments.

The zone must include macros.h: dilend is a macro defined there, and vmc can't find the end of a program without it.

An example

This zone uses all three: a template of its own in %dil, used by the cellarer with dilcopy; a program written inside the cellarer; and death_room@function on the vault. It compiles as cellar.zon:

#include <macros.h>

%zone cellar
title "The Wine Cellar"
lifespan 20
reset RESET_ANYHOW
creators {"manual"}

%dil

/* A template of this zone: any unit, in any zone, can use it
   with dilcopy greeting@cellar("...");                        */
dilbegin greeting(text : string);
code
{
   :start:
   wait(SFB_DONE, command(CMD_AUTO_ENTER) and (activator.type == UNIT_ST_PC));
   exec("say " + text, self);
   goto start;
}
dilend

%rooms

stairs
title "Cellar stairs"
descr
"Worn stone steps lead down into the dark."
down to vault;
end

vault
title "The acid vault"
descr
"The air stings your eyes and the floor bubbles."
up to stairs;
// A ready-made template from function.zon: 20 damage every 5 seconds.
dilcopy death_room@function(PULSE_SEC * 5, 20, "The acid burns your skin!");
end

%mobiles

cellarer
names {"cellarer", "old man", "man"}
title "the cellarer"
descr "The old cellarer is counting bottles."
extra {}
"A bent old man with dusty hands."
M_HUMAN_WARRIOR_AXE(10, SEX_MALE)
dilcopy greeting@cellar("Mind the acid down there!");

// A program written inside the unit: it runs on this NPC only.
dilbegin cellar_count();
code
{
   heartbeat := PULSE_SEC * 60;
   :start:
   pause;
   exec("emote counts the bottles again.", self);
   goto start;
}
dilend
end

%reset

load cellarer into stairs

%end

vmc prints a line for each program it compiled:

VMC 2.0 Copyright (C) 2001 by Valhalla [Nov 14 2026]
VMC Compiled with [-DDMSERVER -DPOSIX -DVMC -DVMC_SRC -DLINUX -DMUD_DEBUG]
Compiling 'cellar.zon'
DIL (line    13)tmpl : greeting             (   89 bytes)
DIL (line    53)tmpl : cellar_count         (  109 bytes)
VMC Done.

The greeting program waits until a player has walked into the room, makes the cellarer say its text, and waits again. cellar_count wakes about once a minute and makes him count his bottles. In the game, wstat with func lists the programs a unit runs.

Where to read more

The DIL Manual teaches the language. Start with these chapters:

  • Making a Program: where programs are written, their parts, how they run and wait, and how they are compiled.
  • Data Types and DIL Constructs: variables, if, while, goto and the rest.
  • Messages: the events a program waits for, such as SFB_DONE and SFB_CMD.
  • Functions: templates that call each other, also across zones.
  • DIL Examples: complete programs from the zones that come with the server.
  • Full Listing: every keyword, function and field of DIL on one page.

The chapters on rooms, objects and NPCs show the ready-made templates that suit each of them.

Previous: Color code descriptions and examples
Next: Appendices