database
The database namespace provides a persistent key-value storage engine shared across all Lua scripts. Data is serialized to aimsense/scripts/data/database.json.
Supported Value Types
Section titled βSupported Value TypesβValues stored in the database can be strings, numbers, booleans, nested tables, arrays, or nil. Tables follow the same serialization rules as json.
Functions
Section titled βFunctionsβ| Function | Parameters | Returns | Description |
|---|---|---|---|
database.read |
key: string |
any | nil |
Reads the stored value associated with key. Returns nil if key does not exist. |
database.write |
key: string, value: any |
nil |
Updates or sets a key in memory. Setting value to nil deletes the key. |
database.flush |
(none) | boolean |
Flushes pending in-memory database writes to disk. |
Example
Section titled βExampleβ-- Read previous player kill countlocal kills = database.read("total_kills") or 0
client.add_callback("game_events", function(event) if event:get_name() == "player_death" then local attacker = entity.get(event.attacker, true) local local_player = entity.get_local_player()
if attacker and local_player and attacker:ent_index() == local_player:ent_index() then kills = kills + 1 database.write("total_kills", kills) database.flush() print("Lifetime kills updated: " .. kills) end endend)