Difference between revisions of "Manual:DIL Manual/store()"
Jump to navigation
Jump to search
(XML import) |
(checked against the compiler and the interpreter; example compiles) |
||
| 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. | ||
| + | |} | ||
| − | + | == 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, no file is written, and an older file stays. Remove it with [[Manual:DIL Manual/delunit()|delunit()]]. | |
| + | * 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()]] | |
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
| − | |||
Revision as of 23:21, 14 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.
|
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, no file is written, and an older file stays. Remove it with delunit().
- 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()).