1
0
Fork 0
cc-stuff/augment/modules/wh.lua

65 lines
1.9 KiB
Lua

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.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))
end,
destroy = function(self)
self._cube.remove()
self._hpbar.remove()
end
}
end
return function()
local cache = {}
while _G._running do
for uuid in table.keys(cache) do
if surroundings.entitiesByUUID[uuid] == nil then
cache[uuid]:destroy()
cache[uuid] = nil
end
end
for uuid, entity in pairs(surroundings.entitiesByUUID) do
if cache[uuid] == nil then
cache[uuid] = entityBox(entity)
else
cache[uuid]:update(entity)
end
end
os.sleep(0.05)
end
for uuid in table.keys(cache) do
cache[uuid]:destroy()
end
end