Manual:DIL Manual/store()

From DikuMUD Wiki
< Manual:DIL Manual
Revision as of 12:34, 19 November 2026 by Agent-mud (talk | contribs) (store(): with nothing to save the file is removed (reception.cpp); FALSE never saves u itself)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

store()

Procedure. Saves a unit, or what is inside it, to a file.

store(u : unitptr, filename : string, container : integer)

Writes the objects and NPCs inside u, with everything inside them, to a file. When container is TRUE, u itself is saved too, with its contents. restore() loads the file back, so things can be kept through a reboot: a clan chest, a parcel for a player, an arena fighter's belongings.

Parameters

Name Type Meaning
u unitptr The unit to save.
filename string The file's name: letters, digits, _ and . only, at most 512 characters.
container integer TRUE: save u and its contents. FALSE: only the contents, never u itself: to keep one unit (a piece of furniture, a chest) through a reboot, use TRUE.

Notes

  • The file goes in the units folder of the zone's DIL file directory (the last column of the zone's line in vme/etc/zonelist), or of dil_file_dir in server.cfg when the zone has none. An existing file is replaced.
  • Only zones with access level 10 or less (the fourth column of zonelist) may use it. In other zones the program stops and the zone log says "attempt to violate system access security (storeall)". The zone that counts is that of the program's template (the one copied onto the unit), not that of a function it called.
  • A name with other characters (a /, a space) is refused with a line in the zone log; nothing is saved.
  • Only objects and NPCs are saved, never players, and not units with UNIT_FL_NOSAVE. Worn equipment is saved as worn.
  • A room can't be saved, its contents neither: with TRUE the zone log says "attempt to save a container that is either a room or pc", with FALSE nothing is written. A player's inventory can be saved with FALSE.
  • When there is nothing to save, the file is removed: an old file would bring back what is gone. So store(u, f, FALSE) with nothing in u deletes f, and a later restore(f, ...) finds nothing (basic_save_contents in reception.cpp). delunit() removes a file on purpose.
  • The units are only copied: they stay in the game.
  • It writes to disk: don't call it often.

Example

dilbegin send_parcel(bag : unitptr, toname : string);
code
{
   if (bag.type != UNIT_ST_OBJ)
      return;
   store(bag, tolower(toname) + ".parcel", TRUE);   // the bag and what is in it
   destroy(bag);
   return;
}
dilend

Puts a bag and what is in it in storage for another player, who fetches it with restore() (see delunit()).

See also