1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-11-15 23:10:31 +01:00
server-nalc/mods/pclasses/init.lua
LeMagnesium d491015a78 Updated pclasses with admin class
- Moved reserved_items into their class file
 - Added admin class for #139
2015-07-28 16:17:26 +02:00

94 lines
2.0 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"
-- Classes
pclasses.classes = {}
-- Data
pclasses.datas = {}
pclasses.datas.players = {}
pclasses.datas.reserved_items = {}
pclasses.datas.hud_ids = {} -- HUD maybe?
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
---------------------------
-- Backup and load system
--
-- Startup
local pfile = io.open(pclasses.conf.datafile, "r")
if pfile then
local line = pfile:read()
if line then
pclasses.datas.players = minetest.deserialize(line)
end
pfile:close()
end
-- Frequent backup
local function save_datas()
local pfile = io.open(pclasses.conf.datafile, "w")
pfile:write(minetest.serialize(pclasses.datas.players))
pfile:close()
minetest.log("action", "[PClasses] Datas saved")
end
local save_timer = 0
minetest.register_globalstep(function(dtime)
save_timer = save_timer + dtime
if save_timer >= pclasses.conf.save_interval then
save_datas()
save_timer = 0
end
end)
minetest.register_on_shutdown(save_datas)
------------------
-- Default class
--
if pclasses.conf.default_class then
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
if pclasses.api.get_class_by_name(pclasses.conf.default_class) then
minetest.register_on_joinplayer(function(player)
if not pclasses.api.get_player_class(player:get_player_name()) then
pclasses.api.set_player_class(player:get_player_name(),
pclasses.conf.default_class)
end
end)
end
end
------------
-- Classes
--
dofile(minetest.get_modpath("pclasses") .. "/warrior.lua")
dofile(minetest.get_modpath("pclasses") .. "/hunter.lua")
dofile(minetest.get_modpath("pclasses") .. "/admin.lua")