Examples
Grenade timers
A countdown over every smoke and fire, with a ring that empties as time runs out. HE grenades and flashes in the air show their fuse.
Needs: Allow game scripting.
Lua
-- @name Grenade timers
-- @description Time left on smokes, fires and grenade fuses.
local smoke_col = ui.color("Smoke", color(180, 200, 255))
local fire_col = ui.color("Fire", color(255, 140, 60))
local fuse_col = ui.color("Fuse", color(255, 255, 255))
local SMOKE_SECONDS = 20
local function timer(pos, left, total, col)
local x, y = game.world_to_screen(pos)
if not x then return end
draw.circle_filled(x, y, 16, color(0, 0, 0, 140))
if total and total > 0 then
local frac = math.clamp(left / total, 0, 1)
draw.arc(x, y, 14, -90, 360 * frac, col, 3)
end
draw.text(x, y - 7, string.format("%.1f", left), col, {align = "center", font = "bold", outline = true})
end
events.on("paint", function()
if not game or not game.connected() then return end
for _, g in ipairs(entities.projectiles()) do
if g.remaining > 0 then
if g.kind == "smoke" and g.active then
timer(g.center, g.remaining, SMOKE_SECONDS, smoke_col:get())
elseif g.kind == "inferno" then
timer(g.center, g.remaining, g.lifetime, fire_col:get())
elseif (g.kind == "he" or g.kind == "flash") and not g.detonated then
timer(g.origin, g.remaining, nil, fuse_col:get())
end
end
end
end)How it works
entities.projectiles()lists grenades in flight and burning.kindis"he","flash","smoke","molotov","inferno"or"decoy". A molotov becomes aninfernowhen it lands and catches fire.- For a smoke that has bloomed and for a fire,
remainingis the seconds until it is gone, andcenteris the middle of the cloud or the flames. A fire also haslifetime, its full burn time. - For an HE grenade or a flash,
remainingis the fuse. draw.arcstarts at the top (-90 degrees) and sweeps clockwise by the fraction of time left.
Try this
- Draw each flame of a fire with
g.fire_points, a list ofvec3, anddraw.world_circle. - Show where a grenade in the air will land with
world.predict_grenade, see Map traces and the world.