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

HUD panel

An info panel in evasive's own style. It shows your choice of frame rate, time, map, players alive and your health, and you place it anywhere on the screen.

Needs: no permission for the frame rate and the time. The map, players and health rows also need Allow game scripting, and the script skips them without it.

Lua
-- @name HUD panel
-- @author evasive
-- @version 1.0
-- @description A watermark-style info panel (draw.panel look) with configurable rows and position.

local enabled = ui.checkbox("Enabled", true)
local rows    = ui.multi_combo("Rows", {"FPS", "Time", "Map", "Players", "Health"}, {true, true, true, false, true})
ui.separator("Position")
local pos_x   = ui.slider("X", 0, 100, 2, {suffix = "%"})
local pos_y   = ui.slider("Y", 0, 100, 30, {suffix = "%"})
local width   = ui.slider("Width", 140, 320, 180, {suffix = "px"})
local title   = ui.text_input("Title", "evasive.lua", 24)
local value_col = ui.color("Value colour", ui.accent())

local fps = 0
events.on("tick", function()
    fps = fps + (time.fps() - fps) * 0.05
end)

events.on("paint", function()
    if not enabled:get() then return end
    local sw, sh = draw.screen_size()
    local show = rows:get()
    local lines = {}
    local function add(label, value) lines[#lines + 1] = {label, value} end
    if show[1] then add("fps", string.format("%d", math.floor(fps + 0.5))) end
    if show[2] then add("time", time.date("%H:%M:%S")) end
    if game and game.connected() then
        if show[3] then add("map", game.map()) end
        if show[4] then add("players", tostring(#entities.players("alive"))) end
        local me = entities.local_player()
        if show[5] and me then add("health", me.alive and tostring(me.health) or "dead") end
    end
    local w = width:get()
    local h = 22 + #lines * 16 + 6
    local x = math.floor((sw - w) * pos_x:get() / 100)
    local y = math.floor((sh - h) * pos_y:get() / 100)
    local row_y = draw.panel(x, y, w, h, title:get())
    for i, l in ipairs(lines) do
        local ty = row_y + (i - 1) * 16 + 2
        draw.text(x + 8, ty, l[1], color(160, 160, 160), {shadow = true})
        draw.text(x + w - 8, ty, l[2], value_col:get(), {align = "right", shadow = true})
    end
end)

How it works

  • ui.multi_combo lets the user pick any set of rows. rows:get() gives a table of booleans in the same order as the names.
  • The frame rate is smoothed in tick: each tick moves the shown value 5% of the way toward time.fps(), so the number does not jump around.
  • The position sliders are percentages of the free space, so the panel never leaves the screen, whatever the resolution.
  • draw.panel draws the frame and the title and gives back the y of the first row. Each row has its label on the left and its value right aligned.
  • game and game.connected() skips the game rows when the permission is off or you are not in a match.

Try this

  • Add a "Ping" row with entities.local_player() and the matching player from entities.player(me.index).
  • Add CS2's own frame rate with game.fps(), which can differ from the overlay's.