Lua · Examples · HUD
Bomb timer
A bar that drains as the bomb counts down, turns red when there is no time to defuse.
Uses: bomb.state, colour lerp
bomb_timer.lua
-- name: Bomb Timer
-- author: Adolfjon
-- version: 1.0
-- description: C4 countdown bar with a can-defuse check.
local bg = color(12, 14, 18, 220)
local white = color(240, 242, 246)
local ok = color(90, 220, 130)
local bad = color(240, 80, 70)
function on_frame()
local b = bomb.state()
if not b.planted or b.defused or b.exploded then return end
local w = draw.screen()
local bw, bh = 320, 46
local x, y = (w - bw) / 2, 90
local left = math.max(0, b.time_left)
local frac = b.timer_length > 0 and left / b.timer_length or 0
local can = left > (b.defusing and b.defuse_left or 10)
local col = can and color.lerp(bad, ok, math.clamp(left / 15, 0, 1)) or bad
draw.rect_filled(x, y, bw, bh, bg, 10)
draw.rect_filled(x + 10, y + bh - 12, (bw - 20) * frac, 4, col, 2)
local title = "BOMB " .. (b.site ~= "" and b.site or "") .. string.format(" %.1f s", left)
draw.text(x + 12, y + 8, title, white, 16)
if b.defusing then
local d = string.format("defusing %.1f", b.defuse_left)
local tw = draw.text_size(d, 13)
draw.text(x + bw - 12 - tw, y + 10, d, can and ok or bad, 13)
end
endInstall it
- Press Copy on the code above.
- In the menu, open Lua and press From Clipboard. The file is named from its
-- name:line. - Turn the script on in the list. Its settings show on its own tab.
Change anything you like and press Save (Ctrl+S) in the editor; the script reloads at once. See Getting started for the other ways to add scripts.