Each mod has it own ways to do it and it have much of code only for that function.
This (something like OOP) mod adds an easy way to do it.
Project Homepage: https://project.king-arthur.eu/projects/db/
Source + Download: https://bitbucket.org/adrido/db/src
API Doku: https://project.king-arthur.eu/projects/db/wiki
1. Add db to depends.txt.
2. Create a new instance of a database:
Code: Select all
local my_db = playerDB({fs={
form = "json",
place="world",
name="my_db",
},})
Get some value:
Code: Select all
local somevalue = my_db:get(player, key, default)
key is a string wich value tried to read.
default is a string, number,table wich is returned if nothing found.
Set something:
Code: Select all
my_db:get(player,key,value)
key is a string.
value can be a string, number or table.
Example: a mod that changes the skin:
Code: Select all
local skin_storage = playerDB({fs={
form = "json",
place="world",
name="skins",
},})
...
-- If a player joins the server:
local current_skin = skin_storage:get(player,"skin_id",1) --1 is the default skin
...
-- If a player sends a formspec to set the skin:
local selected = fields.skin
skin_storage:set(player,"skin_id",selected)
License: WTFPL and CC 0 (at your option)