1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-25 02:00:37 +01:00

Added 'vacuum' feature to manage the items' graveyard

- Added a refresh function to retrieve confiscated items from the items' graveyard
This commit is contained in:
LeMagnesium 2015-08-01 20:28:12 +02:00
parent 55bd0ea800
commit 23f1f6515a
2 changed files with 47 additions and 7 deletions

View File

@ -56,6 +56,7 @@ function pclasses.api.set_player_class(pname, cname)
end end
pclasses.data.players[pname] = cname pclasses.data.players[pname] = cname
pclasses.api.get_class_by_name(cname).on_assigned(pname) pclasses.api.get_class_by_name(cname).on_assigned(pname)
pclasses.api.vacuum_graveyard(minetest.get_player_by_name(pname))
end end
return true return true
end end
@ -76,6 +77,32 @@ pclasses.api.util.does_wear_full_armor = function(pname, material, noshield)
return full_armor and (inv:contains_item("armor", "shields:shield_" .. material) or noshield) return full_armor and (inv:contains_item("armor", "shields:shield_" .. material) or noshield)
end end
function pclasses.api.util.can_have_item(pname, itemname)
if not pclasses.data.reserved_items[itemname] then
return true
end
for index, class in pairs(pclasses.data.reserved_items[itemname]) do
if pclasses.api.get_player_class(pname) == class then
return true
end
end
return false
end
-- TEMPORARY CLASS SHIFT SYSTEM
-- Used to test on local servers
--
minetest.register_privilege("class_shifter", "Able to shift between classes")
minetest.register_chatcommand("shift_class", {
args = "<class>",
privs = {class_shifter = true},
func = function(name, param)
pclasses.api.set_player_class(name, param)
end
})
------------------- -------------------
-- Reserved items -- Reserved items
-- --
@ -96,13 +123,7 @@ local function tick()
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.data.reserved_items[stack:get_name()] then if pclasses.data.reserved_items[stack:get_name()] then
local drop_stack = true if not pclasses.api.util.can_have_item(name, stack:get_name()) then
for index, class in pairs(pclasses.data.reserved_items[stack:get_name()]) do
if pclasses.api.get_player_class(name) == class then
drop_stack = false
end
end
if drop_stack then
inv:set_stack("main", i, "") inv:set_stack("main", i, "")
local grave_inv = minetest.get_inventory({type = "detached", name = name .. "_graveyard"}) local grave_inv = minetest.get_inventory({type = "detached", name = name .. "_graveyard"})
if grave_inv:room_for_item("graveyard", stack) then if grave_inv:room_for_item("graveyard", stack) then

View File

@ -48,3 +48,22 @@ unified_inventory.register_page("graveyard", {
end end
}) })
function pclasses.api.vacuum_graveyard(player)
local pname = player:get_player_name()
local grave_inv = minetest.get_inventory({type = "detached", name = pname .. "_graveyard"})
local player_inv = minetest.get_inventory({type = "player", name = pname})
for i = 1,7*8 do
local stack = grave_inv:get_stack("graveyard", i)
if pclasses.api.util.can_have_item(pname, stack:get_name()) then
grave_inv:set_stack("graveyard", i, nil)
player_inv:set_stack("graveyard", i, nil)
if player_inv:room_for_item("main", stack) then
player_inv:add_item("main", stack)
else
minetest.add_item(pos, stack)
end
end
end
end