evasivedocs
CS2 scriptingLua 5.4.9 · 25 guides · 292 API entries
Examples

Kill counter

Your kills this round, this map and of all time in a HUD chip. The chip flashes white for a moment on every kill.

Needs: Allow game scripting for the kill events. Without it the chip stays at zero.

Lua
-- @name Kill counter
-- @author evasive
-- @version 1.0
-- @description Round / map / all-time kills in a HUD chip, with a short flash on each kill.

local enabled  = ui.checkbox("Enabled", true)
local show_all = ui.checkbox("Show all-time total", true)
local accent   = ui.color("Accent", ui.accent())
ui.button("Reset all-time total", function()
    storage.set("total", 0)
    log.info("all-time total reset")
end)

local round, map_kills = 0, 0
local flash_until = 0

events.on("local_kill", function(e)
    round = round + 1
    map_kills = map_kills + 1
    storage.set("total", storage.get("total", 0) + 1)
    flash_until = time.now() + 0.6
    log.info("kill: " .. (e.player.name or "?"))
end)

events.on("round_start", function() round = 0 end)
events.on("map_change", function() round, map_kills = 0, 0 end)

events.on("paint", function()
    if not enabled:get() then return end
    local sw, sh = draw.screen_size()
    local value = string.format("%d / %d", round, map_kills)
    if show_all:get() then value = value .. string.format(" / %d", storage.get("total", 0)) end
    local flash = math.clamp((flash_until - time.now()) / 0.6, 0, 1)
    local col = color.lerp(accent:get(), color(255, 255, 255), flash)
    draw.chip({x = 20, y = math.floor(sh * 0.62), label = "KILLS", value = value, accent = col, value_color = col,
               meter = flash > 0 and flash or nil})
end)

How it works

  • local_kill fires for every death the game credits to you. The round and map counts live in local variables, the all time count in storage, so it survives restarts.
  • round_start and map_change reset the counters. round_start is a guess made from several players coming back alive at once, which is close enough for a counter.
  • The flash is a number that falls from 1 to 0 over 0.6 seconds. color.lerp blends the accent colour toward white by that much, and the chip's meter shows it running out.
  • The reset button runs on the next frame and writes 0 to the store.

Try this

  • Count headshots too, with the local_hit event and its headshot and killed fields.
  • Play with the chip's look: draw.chip also takes label_color and an icon image.