Difference between revisions of "Manual:DIL Manual/destroy()"

From DikuMUD Wiki
Jump to navigation Jump to search
(XML import)
(checked against the compiler and the interpreter; example compiles)
 
Line 1: Line 1:
−
<span id="bpdest"></span>
+
= destroy() =
 +
'''Procedure.''' Removes a unit from the game.
  
−
  '''Function:'''  <i><!--CODE-->destroy ( u : unitptr );</i><!--ENDCODE-->
+
  destroy(u : unitptr)
  
−
<!--TERM-->  '''u'''
+
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.
−
<!--DEFINITION-->        :Unit to remove from game
 
  
−
The destroy function works in two ways depending on the Unit being acted on.
+
== Parameters ==
−
If the Unit being acted on is a PC the player is saved and ejected from the game.
+
{| class="wikitable"
−
If the Unit being acted on is a NPC, or an Object. the purge function destroys
+
! Name !! Type !! Meaning
−
the Unit.  Currently destroy will not destroy rooms.
+
|-
−
This is different from the old destroy function in that it removes the player
+
| u || unitptr || The unit to remove.
−
out of the game instead of leaving the player in the menu.
+
|}
−
'''Example'''
 
−
<i><!--CODE-->
 
−
---~---~---~---~---~---~---~---~---
 
  
−
dilbegin purge_all_pc();
+
== Notes ==
−
var
+
* On null nothing happens.
−
        u:unitptr/*Unit used to purge each player*/
+
* <code>destroy(self)</code> ends the program at once: the statements after it don't run.
−
        n:unitptr;/*used to keep track of next player*/
+
* 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>.
−
code
+
* To keep what is inside, move it out first: <code>while (u.inside) link(u.inside, u.outside);</code> (as in the example).
−
dilend
+
* A player is saved first, unless they are a guest who was never saved.
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
 
 
−
</i><!--ENDCODE-->
 
−
 
 
−
 
 
−
---~---~---~---~---~---~---~---~---
 
−
<span id="bpdest"></span>
 
−
 
 
−
'''Function:'''  <i><!--CODE-->destroy ( u : unitptr );</i><!--ENDCODE-->
 
  
−
<!--TERM--> '''u'''
+
== Example ==
−
<!--DEFINITION-->        :Unit to remove from game
+
<pre>
 +
dilbegin fido();
 +
var
 +
  i : unitptr;
 +
code
 +
{
 +
  on_activation(self.position <= POSITION_SLEEPING, skip);
 +
  heartbeat := PULSE_SEC * 15;
  
−
The destroy function works in two ways depending on the Unit being acted on.
+
  :loop:
−
If the Unit being acted on is a PC the player is saved and ejected from the game.
+
  pause;
−
If the Unit being acted on is a NPC, or an Object. the purge function destroys
+
  foreach (UNIT_ST_OBJ, i)
−
the Unit.  Currently destroy will not destroy rooms.
+
  {
−
This is different from the old destroy function in that it removes the player
+
      if ((i.objecttype == ITEM_CONTAINER) and isaff(i, ID_CORPSE))
−
out of the game instead of leaving the player in the menu.
+
      {
−
'''Example'''
+
        act("$1n savagely devours $2n.", A_SOMEONE, self, i, null, TO_ROOM);
−
<i><!--CODE-->
+
        while (i.inside)
−
---~---~---~---~---~---~---~---~---
+
            link(i.inside, i.outside);
−
 
+
        destroy(i);
−
dilbegin purge_all_pc();
+
        goto loop;
−
var
+
      }
−
        u:unitptr/*Unit used to purge each player*/
+
  }
−
        n:unitptr;/*used to keep track of next player*/
+
  goto loop;
−
code
+
}
 
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()]]
−
</i><!--ENDCODE-->
+
* [[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. Call unsecure(u) before destroy(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