forked from mtcontrib/3d_armor
Improve error logging, reduce log level to warning
This commit is contained in:
parent
348dad3d4d
commit
27a3823eed
@ -288,31 +288,50 @@ armor.update_inventory = function(self, player)
|
||||
-- DEPRECIATED: Legacy inventory support
|
||||
end
|
||||
|
||||
armor.set_inventory_stack = function(self, player, i, stack)
|
||||
local msg = "[set_inventory_stack]"
|
||||
local name = player:get_player_name()
|
||||
if not name then
|
||||
minetest.log("warning", "3d_armor: Player name is nil "..msg)
|
||||
return
|
||||
end
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
||||
if not player_inv then
|
||||
minetest.log("warning", "3d_armor: Player inventory is nil "..msg)
|
||||
return
|
||||
elseif not armor_inv then
|
||||
minetest.log("warning", "3d_armor: Detached armor inventory is nil "..msg)
|
||||
return
|
||||
end
|
||||
player_inv:set_stack("armor", i, stack)
|
||||
armor_inv:set_stack("armor", i, stack)
|
||||
end
|
||||
|
||||
armor.get_valid_player = function(self, player, msg)
|
||||
msg = msg or ""
|
||||
if not player then
|
||||
minetest.log("error", "3d_armor: Player reference is nil "..msg)
|
||||
minetest.log("warning", "3d_armor: Player reference is nil "..msg)
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
if not name then
|
||||
minetest.log("error", "3d_armor: Player name is nil "..msg)
|
||||
minetest.log("warning", "3d_armor: Player name is nil "..msg)
|
||||
return
|
||||
end
|
||||
local pos = player:getpos()
|
||||
local player_inv = player:get_inventory()
|
||||
local armor_inv = minetest.get_inventory({type="detached", name=name.."_armor"})
|
||||
local inv = player:get_inventory()
|
||||
if not pos then
|
||||
minetest.log("error", "3d_armor: Player position is nil "..msg)
|
||||
minetest.log("warning", "3d_armor: Player position is nil "..msg)
|
||||
return
|
||||
elseif not player_inv then
|
||||
minetest.log("error", "3d_armor: Player inventory is nil "..msg)
|
||||
elseif not inv then
|
||||
minetest.log("warning", "3d_armor: Player inventory is nil "..msg)
|
||||
return
|
||||
elseif not armor_inv then
|
||||
minetest.log("error", "3d_armor: Detached armor inventory is nil "..msg)
|
||||
elseif not minetest.get_inventory({type="detached", name=name.."_armor"}) then
|
||||
minetest.log("warning", "3d_armor: Detached armor inventory is nil "..msg)
|
||||
return
|
||||
end
|
||||
return name, player_inv, armor_inv, pos
|
||||
return name, inv, pos
|
||||
end
|
||||
|
||||
armor.drop_armor = function(pos, stack)
|
||||
|
@ -204,17 +204,16 @@ end)
|
||||
|
||||
if armor.config.drop == true or armor.config.destroy == true then
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local name, player_inv, armor_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
|
||||
local name, player_inv, pos = armor:get_valid_player(player, "[on_dieplayer]")
|
||||
if not name then
|
||||
return
|
||||
end
|
||||
local drop = {}
|
||||
for i=1, player_inv:get_size("armor") do
|
||||
local stack = armor_inv:get_stack("armor", i)
|
||||
local stack = player_inv:get_stack("armor", i)
|
||||
if stack:get_count() > 0 then
|
||||
table.insert(drop, stack)
|
||||
armor_inv:set_stack("armor", i, nil)
|
||||
player_inv:set_stack("armor", i, nil)
|
||||
armor:set_inventory_stack(player, i, nil)
|
||||
armor:run_callbacks("on_unequip", player, stack)
|
||||
end
|
||||
end
|
||||
@ -252,7 +251,7 @@ if armor.config.drop == true or armor.config.destroy == true then
|
||||
end
|
||||
|
||||
minetest.register_on_player_hpchange(function(player, hp_change)
|
||||
local name, player_inv, armor_inv = armor:get_valid_player(player, "[on_hpchange]")
|
||||
local name, player_inv = armor:get_valid_player(player, "[on_hpchange]")
|
||||
if name and hp_change < 0 then
|
||||
local heal_max = 0
|
||||
local state = 0
|
||||
@ -265,8 +264,7 @@ minetest.register_on_player_hpchange(function(player, hp_change)
|
||||
local heal = def.groups["armor_heal"] or 0
|
||||
local item = stack:get_name()
|
||||
stack:add_wear(use)
|
||||
armor_inv:set_stack("armor", i, stack)
|
||||
player_inv:set_stack("armor", i, stack)
|
||||
armor:set_inventory_stack("armor", i, stack)
|
||||
state = state + stack:get_wear()
|
||||
items = items + 1
|
||||
if stack:get_count() == 0 then
|
||||
|
Loading…
Reference in New Issue
Block a user