1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-15 06:50:31 +01:00
server-nalc/mods/pclasses/init.lua
LeMagnesium 743507564f Updated pclasses
- Moved the holographic item's name as a field in switch_params (pclasses.api.register_class)
 - Added wizard class' skeleton for later
 - Fixed a few bugs in nodes, inventory and api
 - Splitted tick function to bury items in two
 - Items from 3d_armor's armor inventory are also affected by inventory vacuuming (from tick function).
   The player's static armor inventory is first cleared, then copied to the detached one, then armor updates everything else (rendering, model, etc)
 - Fixed itemname of admin shield to reserve it properly
 - Return graveyard inventory if it already exists. Do not create it every two seconds
2015-08-20 17:18:57 +02:00

88 lines
2.2 KiB
Lua
Executable File

-------------------
-- Player Classes
--
-- NOTE: This is a very simple interface for classes, more features will be
-- added depending on the various mechanisms we will need
-- Global namespace
pclasses = {}
-- API
pclasses.api = {}
pclasses.api.util = {}
-- Configuration
pclasses.conf = {}
pclasses.conf.default_class = "adventurer"
pclasses.conf.save_interval = 3 * 60
pclasses.conf.datafile = minetest.get_worldpath() .. "/pclasses"
pclasses.conf.gravefile = minetest.get_worldpath() .. "/graveyards"
-- Classes
pclasses.classes = {}
-- Data
pclasses.data = {}
pclasses.data.players = {}
pclasses.data.reserved_items = {}
pclasses.data.hud_ids = {} -- HUD maybe?
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
dofile(minetest.get_modpath("pclasses") .. "/inventory.lua")
dofile(minetest.get_modpath("pclasses") .. "/nodes.lua")
function pclasses.data.load()
local file = io.open(pclasses.conf.datafile, "r")
if file then
local loaded = minetest.deserialize(file:read("*all"))
file:close()
if loaded then
pclasses.data.players = loaded.players or pclasses.data.players
minetest.log("action", "[PClasses] Loaded data")
end
end
end
function pclasses.data.save()
local file, err = io.open(pclasses.conf.datafile, "w")
if file then
file:write(minetest.serialize({
players = pclasses.data.players,
}))
file:close()
minetest.log("action", "[PClasses] Saved data")
else
minetest.log("error", "[PClasses] Data save failed: open failed: " .. err)
end
end
local function data_save_loop()
pclasses.data.save()
minetest.after(pclasses.conf.save_interval, data_save_loop)
end
pclasses.data.load()
------------------
-- Default class
--
if pclasses.conf.default_class then
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
end
minetest.register_on_joinplayer(function(player)
local pname = player:get_player_name()
if pclasses.api.get_class_by_name(pclasses.conf.default_class) and pclasses.api.get_player_class(pname) == nil then
pclasses.api.set_player_class(pname, pclasses.conf.default_class)
end
pclasses.api.create_graveyard_inventory(player)
end)
minetest.register_on_shutdown(function()
pclasses.data.save()
end)
data_save_loop()