Difference between revisions of "Manual:Zone Manual/The DIL Section"
(checked against the current code (wiki review 2026-11-15)) |
|||
| Line 1: | Line 1: | ||
== The DIL section == | == 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 [[Manual:DIL Manual|DIL Manual]]. | ||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
=== What is DIL? === | === 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 <code>self</code>. 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 <code>dilcopy</code> line in a unit puts a copy of a program (a '''template''') on every copy of that unit. The template is named <code>name@zone</code>, and its arguments go in parentheses, followed by a semicolon: | |
| + | <pre> | ||
| + | dilcopy death_room@function(PULSE_SEC * 5, 20, "The acid burns your skin!"); | ||
| + | </pre> | ||
| + | <code>function.zon</code> holds many such templates: guards, aggressive NPCs, death rooms, rooms that move players on, and more. Read the template's <code>dilbegin</code> 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 <code>dilbegin</code> and <code>dilend</code> 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 <code>%dil</code> section.''' A template there can be used with <code>dilcopy</code> 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 <code>macros.h</code>: <code>dilend</code> 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 <code>%dil</code>, used by the cellarer with <code>dilcopy</code>; a program written inside the cellarer; and <code>death_room@function</code> on the vault. It compiles as <code>cellar.zon</code>: | |
| − | + | <pre> | |
| − | + | #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 | ||
| + | </pre> | ||
| + | vmc prints a line for each program it compiled: | ||
| + | <pre> | ||
| + | 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. | ||
| + | </pre> | ||
| + | The <code>greeting</code> program waits until a player has walked into the room, makes the cellarer say its text, and waits again. <code>cellar_count</code> wakes about once a minute and makes him count his bottles. In the game, <code>[[Wizhelp/Wstat|wstat]]</code> with <code>func</code> lists the programs a unit runs. | ||
| + | |||
| + | === Where to read more === | ||
| + | The [[Manual:DIL Manual|DIL Manual]] teaches the language. Start with these chapters: | ||
| + | * [[Manual:DIL Manual/Making a Program|Making a Program]]: where programs are written, their parts, how they run and wait, and how they are compiled. | ||
| + | * [[Manual:DIL Manual/Data Types|Data Types]] and [[Manual:DIL Manual/DIL Constructs|DIL Constructs]]: variables, <code>if</code>, <code>while</code>, <code>goto</code> and the rest. | ||
| + | * [[Manual:DIL Manual/Messages|Messages]]: the events a program waits for, such as <code>SFB_DONE</code> and <code>SFB_CMD</code>. | ||
| + | * [[Manual:DIL Manual/Functions|Functions]]: templates that call each other, also across zones. | ||
| + | * [[Manual:DIL Examples|DIL Examples]]: complete programs from the zones that come with the server. | ||
| + | * [[Manual:DIL Manual (Full Listing)|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. | ||
<div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/Color_and_Formatting_Codes/Color_code_descriptions_and_examples|Previous: Color code descriptions and examples]]</div> | <div style='padding-top: 30px; padding-bottom: 20px; text-align: left;float:left;width:50%;'>[[Manual:Zone_Manual/Color_and_Formatting_Codes/Color_code_descriptions_and_examples|Previous: Color code descriptions and examples]]</div> | ||
<div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/Appendices|Next: Appendices]]</div> | <div style='padding-top: 30px; padding-bottom: 20px; text-align: right;float:right;width:50%;'>[[Manual:Zone_Manual/Appendices|Next: Appendices]]</div> | ||
Latest revision as of 06:20, 15 November 2026
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,gotoand the rest. - Messages: the events a program waits for, such as
SFB_DONEandSFB_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.