Manual:DIL Manual/clone()

From DikuMUD Wiki
Jump to navigation Jump to search

clone()

Function (unitptr). Makes a copy of an existing NPC or object.

clone(u : unitptr) : unitptr

Creates a new unit that copies u as it is now, not as its zone file defines it: names, descriptions, extras, weight, hit points, flags, affects and DIL programs, and for an object its values, type and prices, for an NPC its abilities, level, weapon and spell skills and position. The copy is put inside the unit running the program, like load() does.

Parameters

Name Type Meaning
u unitptr The unit to copy.

Returns

The copy. When u is null the call fails, and the variable assigned keeps its old value.

Notes

  • Only the unit itself is copied, not what it contains: a cloned bag is empty, a cloned NPC has no inventory or equipment.
  • An object that is worn keeps its worn position in the copy, so the copy counts as worn in the program's unit without ever having been put on. Clone objects that aren't worn, or unequip() first.
  • The copy's DIL programs start at once.
  • Clone only NPCs and objects. For a player none of the player's own data (skills, guild, account...) is copied, and a room would end up inside the program's unit.
  • The copy keeps the symbolic name of u, so findsymbolic() finds it like any other copy.

Example

dilbegin copy_box();
var
   u : unitptr;
   dup : unitptr;
code
{
   :loop:
   wait(SFB_DONE, command("put") and (target == self));
   u := medium;
   if ((u.type != UNIT_ST_OBJ) or (u.outside != self))
      goto loop;
   dup := clone(u);
   act("The box shimmers, and $2n appears next to $3n.", A_SOMEONE,
       activator, dup, u, TO_ALL);
   goto loop;
}
dilend

A container that copies every object put in it; the copy appears inside the box, next to the original.

See also