Manual:DIL Manual/unique
Jump to navigation
Jump to search
Contents
unique
Keyword. Option of dilbegin: a unit has at most one copy of the program.
dilbegin unique name(...);
When a unique template is copied onto a unit that already runs a copy of it, nothing happens: no second copy is made, and the one already there goes on undisturbed. That holds for dilcopy in a zone file, the dilcopy() procedure, and the copies the server makes itself (such as the follow and death programs).
Notes
- The test looks for a running program made from the same template on that unit only. Copies on other units don't count.
- The arguments don't matter: a second
dilcopywith other arguments is ignored too, so the first copy keeps its arguments. - Copies loaded with a saved unit are not tested; the test is made when a new copy is added.
- Without
unique, everydilcopyadds another copy, and each one reacts to every event.
Example
dilbegin unique curse_hunger();
code
{
heartbeat := PULSE_SEC * 60;
:start:
pause;
if (self.type == UNIT_ST_PC)
sendtext("Your stomach growls.<br/>", self);
goto start;
}
dilend
dilbegin feast_curse();
code
{
:start:
wait(SFB_CMD, command("eat") and (activator.type == UNIT_ST_PC)
and (activator.outside == self.outside));
dilcopy("curse_hunger@ex", activator);
goto start;
}
dilend
feast_curse, on a cursed table, puts curse_hunger on each player who tries to eat in the room. A player who tries twice still gets one growl a minute, not two.