Fix "player still online" check of armor.unequip (#146)

This commit is contained in:
Niklp 2024-05-01 07:24:49 +02:00 committed by GitHub
parent 1fcbf64d53
commit 22955b413a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -719,13 +719,14 @@ armor.unequip = function(self, player, armor_element)
if self:get_element(stack:get_name()) == armor_element then if self:get_element(stack:get_name()) == armor_element then
armor_inv:set_stack("armor", i, "") armor_inv:set_stack("armor", i, "")
minetest.after(0, function() minetest.after(0, function()
-- resolve player object again in async function local pplayer = minetest.get_player_by_name(name)
player = minetest.get_player_by_name(name) if pplayer then -- player is still online
local inv = player:get_inventory() local inv = pplayer:get_inventory()
if inv:room_for_item("main", stack) then if inv:room_for_item("main", stack) then
inv:add_item("main", stack) inv:add_item("main", stack)
else else
minetest.add_item(player:get_pos(), stack) minetest.add_item(pplayer:get_pos(), stack)
end
end end
end) end)
self:run_callbacks("on_unequip", player, i, stack) self:run_callbacks("on_unequip", player, i, stack)