[Mod] Store player-related information [db]
Sometimes a mod have to store player relevant information during the restart of the server.
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:
Get some value:
player can be a playername or a player object.
key is a string wich value tried to read.
default is a string, number,table wich is returned if nothing found.
Set something:
player can be a player name or a player object.
key is a string.
value can be a string, number or table.
Example: a mod that changes the skin:
Depends: Minetest 0.4.3
License: WTFPL and CC 0 (at your option)
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:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local my_db = playerDB({fs={
form = "json",
place="world",
name="my_db",
},})
Get some value:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
local somevalue = my_db:get(player, key, default)
player can be a playername or a player object.
key is a string wich value tried to read.
default is a string, number,table wich is returned if nothing found.
Set something:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- Code: Select all
my_db:get(player,key,value)
player can be a player name or a player object.
key is a string.
value can be a string, number or table.
Example: a mod that changes the skin:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
- 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)
Depends: Minetest 0.4.3
License: WTFPL and CC 0 (at your option)