Data

Storage

Storage keeps text by key, like a Map<string, string>, but on disk: what a plugin stores survives a map change and a server restart. It is the place for a player's saved points, his last visit, a preference.

const 
visits
= new
Storage
("myplugin_visits");
server
.
addEventListener
("putInServer", (
event
) => countVisit(
event
.
player
));
function countVisit(
player
: Client) {
const
saved
=
visits
.
get
(
player
.
steamId
); // string | null: null when the key is not there
const
count
=
saved
== null ? 1 :
parseInt
(
saved
) + 1;
visits
.
set
(
player
.
steamId
,
count
.
toString
());
console
.
log
(`${
player
.
name
}: visit ${
count
}`);
}
MethodDoes
get(key)the value under key, or null
set(key, value)puts value under key, replacing what was there
has(key)true when there is a value under key
delete(key)removes key; a key that is not there is ignored

The name is the storage's file: new Storage("myplugin_visits") keeps its data in addons/amxmodx/data/vault/myplugin_visits.vault. Give each storage a name of its own, starting with your plugin's name. The file is opened the first time the storage is used. It is an nVault file, so a Pawn plugin can open the same storage with nvault_open("myplugin_visits").

Keys and values are text. A number goes in with toString() and comes out with parseInt or parseFloat. A value is read back up to 255 bytes of UTF-8: 255 Latin letters, about 127 Cyrillic ones.

When it reaches the disk
Changes are kept in memory and written to the file when the map changes or the server shuts down cleanly. If the server crashes or is killed, what was set since the last map change is lost.