From 631abc9ab90da85d5375e3334245acc4a1885ba2 Mon Sep 17 00:00:00 2001 From: hkc Date: Sat, 14 Oct 2023 14:03:15 +0300 Subject: [PATCH] proper health issue fix --- augment/modules/wh.lua | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/augment/modules/wh.lua b/augment/modules/wh.lua index 7be8023..5102ae5 100644 --- a/augment/modules/wh.lua +++ b/augment/modules/wh.lua @@ -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)