Difference between revisions of "Manual:DIL Manual/destroy()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| Line 1: | Line 1: | ||
| − | + | = 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 == | |
| − | + | {| class="wikitable" | |
| − | + | ! Name !! Type !! Meaning | |
| − | + | |- | |
| − | + | | u || unitptr || The unit to remove. | |
| − | + | |} | |
| − | |||
| − | |||
| − | |||
| − | + | == Notes == | |
| − | + | * On null nothing happens. | |
| − | + | * <code>destroy(self)</code> ends the program at once: the statements after it don't run. | |
| − | + | * Destroying a unit this program has <code>secure</code>d jumps to the secure's label at once, skipping the rest. Call <code>unsecure(u)</code> before <code>destroy(u)</code>. | |
| − | + | * To keep what is inside, move it out first: <code>while (u.inside) link(u.inside, u.outside);</code> (as in the example). | |
| − | + | * A player is saved first, unless they are a guest who was never saved. | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | < | ||
| − | |||
| − | |||
| − | + | == Example == | |
| − | + | <pre> | |
| + | 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 | dilend | ||
| + | </pre> | ||
| + | A dog that eats corpses and leaves what was in them on the floor. Adapted from midgaard.zon. | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/load()|load()]] | |
| − | + | * [[Manual:DIL Manual/link()|link()]] | |
| − | + | * [[Manual:DIL Manual/secure()|secure()]] | |
| − | + | * [[Manual:DIL Manual/unsecure()|unsecure()]] | |
| − | + | * [[Manual:DIL Manual/foreach()|foreach()]] | |
Latest revision as of 23:23, 14 November 2026
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.