Fix buggy headbars
This commit is contained in:
parent
421b268716
commit
fd5caec63f
@ -48,15 +48,29 @@ minetest.register_entity(
|
|||||||
|
|
||||||
physical = false,
|
physical = false,
|
||||||
pointable = false,
|
pointable = false,
|
||||||
|
static_save = false,
|
||||||
|
|
||||||
|
_wielder = nil,
|
||||||
|
|
||||||
|
on_activate = function(self, staticdata)
|
||||||
|
local name = staticdata
|
||||||
|
local wielder = minetest.get_player_by_name(name)
|
||||||
|
if wielder and wielder:is_player() then
|
||||||
|
self._wielder = wielder
|
||||||
|
end
|
||||||
|
end,
|
||||||
on_step = function(self, dtime)
|
on_step = function(self, dtime)
|
||||||
local ent = self.wielder
|
local ent = self._wielder
|
||||||
|
|
||||||
if ent == nil or (minetest.get_player_by_name(ent:get_player_name(0)) == nil) then
|
if ent == nil or (minetest.get_player_by_name(ent:get_player_name()) == nil) then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if self.object:get_attach() == nil then
|
||||||
|
self.object:set_attach(ent, "", {x = 0, y = 19, z = 0}, {x = 0, y = 0, z = 0})
|
||||||
|
end
|
||||||
|
|
||||||
local hp = ent:get_hp()
|
local hp = ent:get_hp()
|
||||||
|
|
||||||
self.object:set_properties({textures = {headbars.get_sprite("heart.png", "headbars_heart_bg.png", 20, hp)}})
|
self.object:set_properties({textures = {headbars.get_sprite("heart.png", "headbars_heart_bg.png", 20, hp)}})
|
||||||
@ -68,17 +82,20 @@ function headbars.attach_hpbar(to)
|
|||||||
if not enable_headbars then return end
|
if not enable_headbars then return end
|
||||||
|
|
||||||
local pos = to:get_pos()
|
local pos = to:get_pos()
|
||||||
local bar = minetest.add_entity(pos, "headbars:hpbar")
|
local name = to:get_player_name()
|
||||||
|
local bar = minetest.add_entity(pos, "headbars:hpbar", name)
|
||||||
|
|
||||||
if bar == nil then return end
|
if bar == nil then
|
||||||
|
minetest.log("error", "[headbars] HP bar failed to spawn!")
|
||||||
-- local attach_pos = {x = 0, y = 0, z = 0}
|
return
|
||||||
local attach_pos = {x = 0, y = 9, z = 0}
|
end
|
||||||
|
|
||||||
bar:set_attach(to, "", attach_pos, {x = 0, y = 0, z = 0})
|
|
||||||
bar = bar:get_luaentity()
|
|
||||||
bar.wielder = to
|
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(headbars.attach_hpbar)
|
minetest.register_on_joinplayer(function(player)
|
||||||
|
minetest.after(1, function(player)
|
||||||
|
if player and player:is_player() then
|
||||||
|
headbars.attach_hpbar(player)
|
||||||
|
end
|
||||||
|
end, player)
|
||||||
|
end)
|
||||||
default.log("mod:headbars", "loaded")
|
default.log("mod:headbars", "loaded")
|
||||||
|
Loading…
Reference in New Issue
Block a user