From b3515c737f0ac36bf04d608d9fa1daa38a65ffc8 Mon Sep 17 00:00:00 2001 From: hkc Date: Sat, 14 Oct 2023 13:58:23 +0300 Subject: [PATCH] some entities don't have health --- augment/modules/wh.lua | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/augment/modules/wh.lua b/augment/modules/wh.lua index 20b7235..93c94da 100644 --- a/augment/modules/wh.lua +++ b/augment/modules/wh.lua @@ -11,12 +11,16 @@ local options = { local function entityBox(ent) local cube = canvas3d.addBox(ent.x - 0.25, ent.y - 0.25, ent.z - 0.25) local hpbar = canvas3d.addFrame({ ent.x - 0.25, ent.y + 0.25, ent.z - 0.25 }) + cube.setAlpha(0x20) cube.setDepthTested(false) hpbar.setDepthTested(false) - local hp_rect_bg = hpbar.addRectangle(-1, -0.25, 2, 0.25, options.hpbar.bg) - local hp_rect_fg = hpbar.addRectangle(-1, -0.25, 0, 0.25, options.hpbar.fg) + local hp_rect_bg, hp_rect_fg + if ent.health ~= nil then + hp_rect_bg = hpbar.addRectangle(-1, -0.25, 2, 0.25, options.hpbar.bg) + hp_rect_fg = hpbar.addRectangle(-1, -0.25, 0, 0.25, options.hpbar.fg) + end local hp_txt = hpbar.addText({ -1, -0.2 }, ent.name, options.hpbar.txt) return { @@ -28,8 +32,14 @@ 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) - self._hp_rect_fg.setSize(2 * entity.health / entity.maxHealth, 0.25) - self._hp_txt.setText(string.format("%s (%.1f/%.1f)", entity.name, entity.health, entity.maxHealth)) + if self._hp_rect_fg ~= nil then + self._hp_rect_fg.setSize(2 * entity.health / entity.maxHealth, 0.25) + end + if entity.health ~= nil then + self._hp_txt.setText(string.format("%s (%.1f/%.1f)", entity.name, entity.health, entity.maxHealth)) + else + self._hp_txt.setText(string.format("%s", entity.name)) + end end, destroy = function(self) self._cube.remove()