some entities don't have health
This commit is contained in:
parent
3cdeac3988
commit
b3515c737f
|
@ -11,12 +11,16 @@ local options = {
|
||||||
local function entityBox(ent)
|
local function entityBox(ent)
|
||||||
local cube = canvas3d.addBox(ent.x - 0.25, ent.y - 0.25, ent.z - 0.25)
|
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 })
|
local hpbar = canvas3d.addFrame({ ent.x - 0.25, ent.y + 0.25, ent.z - 0.25 })
|
||||||
|
|
||||||
cube.setAlpha(0x20)
|
cube.setAlpha(0x20)
|
||||||
cube.setDepthTested(false)
|
cube.setDepthTested(false)
|
||||||
hpbar.setDepthTested(false)
|
hpbar.setDepthTested(false)
|
||||||
|
|
||||||
local hp_rect_bg = hpbar.addRectangle(-1, -0.25, 2, 0.25, options.hpbar.bg)
|
local hp_rect_bg, hp_rect_fg
|
||||||
local hp_rect_fg = hpbar.addRectangle(-1, -0.25, 0, 0.25, options.hpbar.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)
|
local hp_txt = hpbar.addText({ -1, -0.2 }, ent.name, options.hpbar.txt)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -28,8 +32,14 @@ local function entityBox(ent)
|
||||||
update = function(self, entity)
|
update = function(self, entity)
|
||||||
self._cube.setPosition(entity.x - 0.25, entity.y - 0.25, entity.z - 0.25)
|
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._hpbar.setPosition(entity.x, entity.y + 0.5, entity.z)
|
||||||
|
if self._hp_rect_fg ~= nil then
|
||||||
self._hp_rect_fg.setSize(2 * entity.health / entity.maxHealth, 0.25)
|
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))
|
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,
|
end,
|
||||||
destroy = function(self)
|
destroy = function(self)
|
||||||
self._cube.remove()
|
self._cube.remove()
|
||||||
|
|
Loading…
Reference in New Issue