Lua · Examples · HUD

Kill feed

A HUD panel that lists your last kills with weapon and headshot icons.

Uses: hud.panel, events, color.alpha

kill_feed.lua
-- name: Kill Feed
-- author: Adolfjon
-- version: 1.0
-- description: Your last kills in a HUD panel, fading out.

ui.slider("rows", "Rows", 3, 10, 5)
ui.slider("life", "Seconds on screen", 3, 20, 8)

local feed = {}
local white = color(235, 238, 245)
local gold = color(255, 205, 90)
local dim = color(160, 166, 178)

events.on("kill", function(e)
    table.insert(feed, 1, {
        name = e.victim ~= "" and e.victim or "enemy",
        weapon = e.weapon,
        hs = e.headshot,
        at = globals.time(),
    })
    while #feed > 10 do table.remove(feed) end
end)

function on_frame()
    local rows = ui.get("rows")
    local life = ui.get("life")
    local now = globals.time()
    local x, y, shown = hud.panel("feed", "Kill feed", 230, rows * 20 + 8)
    if not shown then return end
    local line = 0
    for _, k in ipairs(feed) do
        local age = now - k.at
        if age < life and line < rows then
            local a = 255 * math.clamp((life - age) / 1.0, 0, 1)
            local yy = y + 6 + line * 20
            draw.text(x + 10, yy, k.name, color.alpha(white, a), 14)
            local tag = k.weapon .. (k.hs and "  HS" or "")
            local tw = draw.text_size(tag, 13)
            draw.text(x + 220 - tw, yy + 1, tag, color.alpha(k.hs and gold or dim, a), 13)
            line = line + 1
        end
    end
end

Install it

  1. Press Copy on the code above.
  2. In the menu, open Lua and press From Clipboard. The file is named from its -- name: line.
  3. 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.