mirror of
https://github.com/sys4-fr/server-nalc.git
synced 2025-01-12 11:00:25 +01:00
Fixed pclasses' reservation system
- Moved callbacks call when setting class - Fixed reservation system
This commit is contained in:
parent
96edf51190
commit
6b7b073cd9
@ -35,14 +35,14 @@ end
|
|||||||
|
|
||||||
-- Get single player
|
-- Get single player
|
||||||
function pclasses.api.get_player_class(pname)
|
function pclasses.api.get_player_class(pname)
|
||||||
return pclasses.datas.players[pname]
|
return pclasses.data.players[pname]
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Get all players for a class
|
-- Get all players for a class
|
||||||
function pclasses.api.get_class_players(cname)
|
function pclasses.api.get_class_players(cname)
|
||||||
local pnames = {}
|
local pnames = {}
|
||||||
if pclasses.api.get_class_by_name(cname) then
|
if pclasses.api.get_class_by_name(cname) then
|
||||||
for p,c in ipairs(pclasses.datas.players) do
|
for p,c in ipairs(pclasses.data.players) do
|
||||||
if c == cname then
|
if c == cname then
|
||||||
table.insert(pnames, table.getn(pnames)+1)
|
table.insert(pnames, table.getn(pnames)+1)
|
||||||
end
|
end
|
||||||
@ -53,7 +53,13 @@ end
|
|||||||
-- Set single player
|
-- Set single player
|
||||||
function pclasses.api.set_player_class(pname, cname)
|
function pclasses.api.set_player_class(pname, cname)
|
||||||
if pclasses.api.get_class_by_name(cname) then
|
if pclasses.api.get_class_by_name(cname) then
|
||||||
pclasses.datas.players[pname] = cname
|
if pclasses.api.get_player_class(pname) ~= cname then
|
||||||
|
if pclasses.api.get_player_class(pname) and pclasses.classes[pclasses.api.get_player_class(pname)].on_unassigned then
|
||||||
|
pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname)
|
||||||
|
end
|
||||||
|
pclasses.data.players[pname] = cname
|
||||||
|
pclasses.api.get_class_by_name(cname).on_assigned(pname)
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
@ -84,39 +90,16 @@ function pclasses.api.assign_class(player)
|
|||||||
local pname = player:get_player_name()
|
local pname = player:get_player_name()
|
||||||
|
|
||||||
if pclasses.classes["admin"].determination(player) then
|
if pclasses.classes["admin"].determination(player) then
|
||||||
if pclasses.api.get_player_class(pname) ~= "admin" then
|
|
||||||
if pclasses.classes[pclasses.api.get_player_class(pname)].on_unassigned then
|
|
||||||
pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname)
|
|
||||||
end
|
|
||||||
pclasses.api.set_player_class(pname, "admin")
|
pclasses.api.set_player_class(pname, "admin")
|
||||||
pclasses.api.get_class_by_name("admin").on_assigned(pname)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif pclasses.classes["hunter"].determination(player) then
|
elseif pclasses.classes["hunter"].determination(player) then
|
||||||
if pclasses.api.get_player_class(pname) ~= "hunter" then
|
|
||||||
if pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned then
|
|
||||||
pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname)
|
|
||||||
end
|
|
||||||
pclasses.api.set_player_class(pname, "hunter")
|
pclasses.api.set_player_class(pname, "hunter")
|
||||||
pclasses.api.get_class_by_name("hunter").on_assigned(pname)
|
|
||||||
end
|
|
||||||
|
|
||||||
elseif pclasses.api.get_class_by_name("warrior").determination(player) then
|
elseif pclasses.api.get_class_by_name("warrior").determination(player) then
|
||||||
if pclasses.api.get_player_class(pname) ~= "warrior" then
|
|
||||||
if pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned then
|
|
||||||
pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname)
|
|
||||||
end
|
|
||||||
pclasses.api.set_player_class(pname, "warrior")
|
pclasses.api.set_player_class(pname, "warrior")
|
||||||
pclasses.api.get_class_by_name("warrior").on_assigned(pname)
|
|
||||||
end
|
|
||||||
elseif pclasses.conf.default_class then
|
elseif pclasses.conf.default_class then
|
||||||
if pclasses.api.get_player_class(pname) ~= pclasses.conf.default_class then
|
|
||||||
if pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned then
|
|
||||||
pclasses.api.get_class_by_name(pclasses.api.get_player_class(pname)).on_unassigned(pname)
|
|
||||||
end
|
|
||||||
pclasses.api.set_player_class(pname, pclasses.conf.default_class)
|
pclasses.api.set_player_class(pname, pclasses.conf.default_class)
|
||||||
pclasses.api.get_class_by_name(pclasses.conf.default_class).on_assigned(pname)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -132,8 +115,8 @@ end)
|
|||||||
-- Reserved items
|
-- Reserved items
|
||||||
--
|
--
|
||||||
function pclasses.api.reserve_item(cname, itemstring)
|
function pclasses.api.reserve_item(cname, itemstring)
|
||||||
pclasses.datas.reserved_items[itemstring] = pclasses.datas.reserved_items or {}
|
pclasses.data.reserved_items[itemstring] = pclasses.data.reserved_items[itemstring] or {}
|
||||||
table.insert(pclasses.datas.reserved_items[itemstring], 1, cname)
|
table.insert(pclasses.data.reserved_items[itemstring], 1, cname)
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_globalstep(function(dtime)
|
minetest.register_globalstep(function(dtime)
|
||||||
@ -142,9 +125,9 @@ minetest.register_globalstep(function(dtime)
|
|||||||
local inv = minetest.get_inventory({type="player", name = name})
|
local inv = minetest.get_inventory({type="player", name = name})
|
||||||
for i = 1, inv:get_size("main") do
|
for i = 1, inv:get_size("main") do
|
||||||
local stack = inv:get_stack("main", i)
|
local stack = inv:get_stack("main", i)
|
||||||
if pclasses.datas.reserved_items[stack:get_name()] then
|
if pclasses.data.reserved_items[stack:get_name()] then
|
||||||
local drop_stack = true
|
local drop_stack = true
|
||||||
for _, class in pairs(pclasses.datas.reserved_items) do
|
for index, class in pairs(pclasses.data.reserved_items[stack:get_name()]) do
|
||||||
if pclasses.api.get_player_class(name) == class then
|
if pclasses.api.get_player_class(name) == class then
|
||||||
drop_stack = false
|
drop_stack = false
|
||||||
end
|
end
|
||||||
|
@ -22,10 +22,10 @@ pclasses.conf.datafile = minetest.get_worldpath() .. "/pclasses"
|
|||||||
pclasses.classes = {}
|
pclasses.classes = {}
|
||||||
|
|
||||||
-- Data
|
-- Data
|
||||||
pclasses.datas = {}
|
pclasses.data = {}
|
||||||
pclasses.datas.players = {}
|
pclasses.data.players = {}
|
||||||
pclasses.datas.reserved_items = {}
|
pclasses.data.reserved_items = {}
|
||||||
pclasses.datas.hud_ids = {} -- HUD maybe?
|
pclasses.data.hud_ids = {} -- HUD maybe?
|
||||||
|
|
||||||
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
|
dofile(minetest.get_modpath("pclasses") .. "/api.lua")
|
||||||
|
|
||||||
@ -39,10 +39,7 @@ if pclasses.conf.default_class then
|
|||||||
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
|
dofile(minetest.get_modpath("pclasses") .. "/" .. pclasses.conf.default_class .. ".lua")
|
||||||
if pclasses.api.get_class_by_name(pclasses.conf.default_class) then
|
if pclasses.api.get_class_by_name(pclasses.conf.default_class) then
|
||||||
minetest.register_on_joinplayer(function(player)
|
minetest.register_on_joinplayer(function(player)
|
||||||
if not pclasses.api.get_player_class(player:get_player_name()) then
|
pclasses.api.assign_class(player)
|
||||||
pclasses.api.set_player_class(player:get_player_name(),
|
|
||||||
pclasses.conf.default_class)
|
|
||||||
end
|
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user