Fix player ref being stored between callbacks

This commit is contained in:
rubenwardy 2017-10-12 15:57:00 +01:00
parent ff8bdf1167
commit a24c563372

View File

@ -11,9 +11,8 @@ local hp_bar = {
} }
function hp_bar:on_step(dtime) function hp_bar:on_step(dtime)
local wielder = self.wielder local wielder = self.wielder and minetest.get_player_by_name(self.wielder)
if wielder == nil or if wielder == nil then
minetest.get_player_by_name(wielder:get_player_name()) == nil then
self.object:remove() self.object:remove()
return return
end end
@ -35,7 +34,7 @@ local function add_HP_gauge(player)
if ent ~= nil then if ent ~= nil then
ent:set_attach(player, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0}) ent:set_attach(player, "", {x = 0, y = 10, z = 0}, {x = 0, y = 0, z = 0})
ent = ent:get_luaentity() ent = ent:get_luaentity()
ent.wielder = player ent.wielder = player:get_player_name()
end end
end end
@ -44,3 +43,4 @@ if minetest.setting_getbool("health_bars") ~= false and
minetest.setting_getbool("enable_damage") then minetest.setting_getbool("enable_damage") then
minetest.register_on_joinplayer(add_HP_gauge) minetest.register_on_joinplayer(add_HP_gauge)
end end