Difference between revisions of "Manual:DIL Manual/store()"
Jump to navigation
Jump to search
(XML import) |
(store(): with nothing to save the file is removed (reception.cpp); FALSE never saves u itself) |
||
| (One intermediate revision by the same user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | = 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 <code>u</code>, with everything inside them, to a file. | |
| − | + | When <code>container</code> is TRUE, <code>u</code> itself is saved too, with its contents. | |
| − | + | [[Manual:DIL Manual/restore()|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 == | ||
| + | {| class="wikitable" | ||
| + | ! Name !! Type !! Meaning | ||
| + | |- | ||
| + | | u || unitptr || The unit to save. | ||
| + | |- | ||
| + | | filename || string || The file's name: letters, digits, <code>_</code> and <code>.</code> only, at most 512 characters. | ||
| + | |- | ||
| + | | container || integer || TRUE: save <code>u</code> and its contents. FALSE: only the contents, never <code>u</code> itself: to keep one unit (a piece of furniture, a chest) through a reboot, use TRUE. | ||
| + | |} | ||
| − | + | == Notes == | |
| − | + | * The file goes in the <code>units</code> folder of the zone's DIL file directory (the last column of the zone's line in <code>vme/etc/zonelist</code>), or of <code>dil_file_dir</code> in <code>server.cfg</code> when the zone has none. An existing file is replaced. | |
| − | + | * Only zones with access level 10 or less (the fourth column of <code>zonelist</code>) 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 <code>/</code>, 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 <code>UNIT_FL_NOSAVE</code>. 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 <code>store(u, f, FALSE)</code> with nothing in <code>u</code> deletes <code>f</code>, and a later <code>restore(f, ...)</code> finds nothing (<code>basic_save_contents</code> in reception.cpp). [[Manual:DIL Manual/delunit()|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 == | |
| − | + | <pre> | |
| − | + | 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 | dilend | ||
| + | </pre> | ||
| + | Puts a bag and what is in it in storage for another player, who fetches it with <code>restore()</code> (see [[Manual:DIL Manual/delunit()|delunit()]]). | ||
| − | + | == See also == | |
| − | + | * [[Manual:DIL Manual/restore()|restore()]] | |
| − | + | * [[Manual:DIL Manual/delunit()|delunit()]] | |
| − | + | * [[Manual:DIL Manual/savestr()|savestr()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Latest revision as of 12:34, 19 November 2026
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
unitsfolder of the zone's DIL file directory (the last column of the zone's line invme/etc/zonelist), or ofdil_file_dirinserver.cfgwhen 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 inudeletesf, and a laterrestore(f, ...)finds nothing (basic_save_contentsin 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()).