1
0
mirror of https://github.com/sys4-fr/server-nalc.git synced 2024-12-24 01:30:38 +01:00

Prevent crashes

- Avoid crashing when some variables are oddly nil
This commit is contained in:
LeMagnesium 2015-08-01 23:55:44 +02:00
parent 23f1f6515a
commit f905d48724
2 changed files with 6 additions and 4 deletions

View File

@ -95,7 +95,7 @@ end
minetest.register_privilege("class_shifter", "Able to shift between classes")
minetest.register_chatcommand("shift_class", {
minetest.register_chatcommand("switch_class", {
args = "<class>",
privs = {class_shifter = true},
func = function(name, param)
@ -125,13 +125,13 @@ local function tick()
if pclasses.data.reserved_items[stack:get_name()] then
if not pclasses.api.util.can_have_item(name, stack:get_name()) then
inv:set_stack("main", i, "")
local grave_inv = minetest.get_inventory({type = "detached", name = name .. "_graveyard"})
if grave_inv:room_for_item("graveyard", stack) then
local grave_inv = pclasses.api.create_graveyard_inventory(ref)
if grave_inv and grave_inv:room_for_item("graveyard", stack) then
grave_inv:add_item("graveyard", stack)
inv:add_item("graveyard", stack)
-- ^ Because add_item doesn't trigger on_put, nonsense
else
minetest.add_item(pos, stack)
minetest.add_item(ref:getpos(), stack)
end
end
end

View File

@ -53,6 +53,8 @@ function pclasses.api.vacuum_graveyard(player)
local grave_inv = minetest.get_inventory({type = "detached", name = pname .. "_graveyard"})
local player_inv = minetest.get_inventory({type = "player", name = pname})
if not grave_inv then return end
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