proper health issue fix

This commit is contained in:
Casey 2023-10-14 14:03:15 +03:00
parent a37ba81545
commit 631abc9ab9
Signed by: hkc
GPG Key ID: F0F6CFE11CDB0960
1 changed files with 5 additions and 9 deletions

View File

@ -16,11 +16,8 @@ local function entityBox(ent)
cube.setDepthTested(false)
hpbar.setDepthTested(false)
local hp_rect_bg, hp_rect_fg
if ent.health ~= nil then
hp_rect_bg = hpbar.addRectangle(0, 0, 100, 15, options.hpbar.bg)
hp_rect_fg = hpbar.addRectangle(0, 0, 0, 15, options.hpbar.fg)
end
local hp_rect_bg = hpbar.addRectangle(0, 0, 100, 15, options.hpbar.bg)
local hp_rect_fg = hpbar.addRectangle(0, 0, 0, 15, options.hpbar.fg)
local hp_txt = hpbar.addText({ 0, 2 }, ent.name, options.hpbar.txt)
return {
@ -32,13 +29,12 @@ local function entityBox(ent)
update = function(self, entity)
self._cube.setPosition(entity.x - 0.25, entity.y - 0.25, entity.z - 0.25)
self._hpbar.setPosition(entity.x, entity.y + 0.5, entity.z)
if self._hp_rect_fg ~= nil then
self._hp_rect_fg.setSize(100 * entity.health / entity.maxHealth, 15)
end
if entity.health ~= nil then
if entity.health ~= nil and entity.maxHealth ~= nil then
self._hp_txt.setText(string.format("%s (%.1f/%.1f)", entity.name, entity.health, entity.maxHealth))
self._hp_rect_fg.setSize(100 * entity.health / entity.maxHealth, 15)
else
self._hp_txt.setText(string.format("%s", entity.name))
self._hp_rect_fg.setSize(0)
end
end,
destroy = function(self)