2023-10-14 13:26:32 +03:00
|
|
|
|
|
|
|
local options = {
|
|
|
|
reverse_projection = false,
|
|
|
|
hpbar = {
|
|
|
|
bg = 0x13131355,
|
|
|
|
fg = 0xef787878,
|
|
|
|
txt = 0xffffffff
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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_txt = hpbar.addText({ -1, -0.2 }, ent.name, options.hpbar.txt)
|
|
|
|
|
|
|
|
return {
|
|
|
|
_cube = cube,
|
|
|
|
_hpbar = hpbar,
|
|
|
|
_hp_rect_bg = hp_rect_bg,
|
|
|
|
_hp_rect_fg = hp_rect_fg,
|
|
|
|
_hp_txt = hp_txt,
|
|
|
|
update = function(self, entity)
|
|
|
|
self._cube.setPosition(entity.x - 0.25, entity.y - 0.25, entity.z - 0.25)
|
|
|
|
self._hpbar.setPosition(entity, 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))
|
|
|
|
end,
|
|
|
|
destroy = function(self)
|
|
|
|
self._cube.remove()
|
|
|
|
self._hpbar.remove()
|
|
|
|
end
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2023-10-12 18:14:13 +03:00
|
|
|
return function()
|
2023-10-12 21:25:20 +03:00
|
|
|
local cache = {}
|
2023-10-12 18:14:13 +03:00
|
|
|
while _G._running do
|
2023-10-14 13:26:32 +03:00
|
|
|
for uuid in table.keys(cache) do
|
|
|
|
if surroundings.entitiesByUUID[uuid] == nil then
|
|
|
|
cache[uuid]:destroy()
|
|
|
|
cache[uuid] = nil
|
2023-10-12 18:14:13 +03:00
|
|
|
end
|
|
|
|
end
|
2023-10-12 21:25:20 +03:00
|
|
|
|
2023-10-14 13:26:32 +03:00
|
|
|
for uuid, entity in pairs(surroundings.entitiesByUUID) do
|
|
|
|
if cache[uuid] == nil then
|
|
|
|
cache[uuid] = entityBox(entity)
|
|
|
|
else
|
|
|
|
cache[uuid]:update(entity)
|
2023-10-12 18:14:13 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
os.sleep(0.05)
|
|
|
|
end
|
2023-10-14 13:26:32 +03:00
|
|
|
|
|
|
|
for uuid in table.keys(cache) do
|
|
|
|
cache[uuid]:destroy()
|
|
|
|
end
|
2023-10-12 18:14:13 +03:00
|
|
|
end
|