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

Custom box ESP

Your own player boxes: full or corner boxes, a health bar, names, weapons and distance. It uses the same boxes and the same camera as evasive's built in ESP, so the two line up.

Needs: Allow game scripting.

Lua
-- @name Custom box ESP
-- @author evasive
-- @version 1.0
-- @description Corner or full boxes, a health bar and names, drawn with the same camera as the built-in ESP.

local enabled  = ui.checkbox("Enabled", true)
local style    = ui.combo("Box style", {"Full", "Corners"}, 2)
local parts    = ui.multi_combo("Show", {"Health bar", "Name", "Weapon", "Distance"}, {true, true, false, false})
local teammates = ui.checkbox("Teammates", false)
local box_col  = ui.color("Box colour", color(143, 108, 240))
local thick    = ui.slider("Thickness", 1, 3, 1)

local function corners(x1, y1, x2, y2, col, t)
    local w, h = x2 - x1, y2 - y1
    local l = math.min(w, h) * 0.25
    draw.line(x1, y1, x1 + l, y1, col, t)  draw.line(x1, y1, x1, y1 + l, col, t)
    draw.line(x2, y1, x2 - l, y1, col, t)  draw.line(x2, y1, x2, y1 + l, col, t)
    draw.line(x1, y2, x1 + l, y2, col, t)  draw.line(x1, y2, x1, y2 - l, col, t)
    draw.line(x2, y2, x2 - l, y2, col, t)  draw.line(x2, y2, x2, y2 - l, col, t)
end

events.on("paint", function()
    if not enabled:get() or not game.connected() then return end
    local show = parts:get()
    local col, t = box_col:get(), thick:get()
    for _, p in ipairs(entities.players(teammates:get() and "alive" or "enemies")) do
        if p.alive and not p.is_local then
            local x1, y1, x2, y2 = p:box()
            if x1 then
                if style:get() == 1 then
                    draw.rect(x1 - 1, y1 - 1, x2 - x1 + 2, y2 - y1 + 2, color(0, 0, 0, 160), t + 2)
                    draw.rect(x1, y1, x2 - x1, y2 - y1, col, t)
                else
                    corners(x1, y1, x2, y2, col, t)
                end
                if show[1] then
                    local frac = math.clamp(p.health / 100, 0, 1)
                    local bh = (y2 - y1) * frac
                    draw.rect_filled(x1 - 6, y1 - 1, 4, y2 - y1 + 2, color(0, 0, 0, 170))
                    draw.rect_filled(x1 - 5, y2 - bh, 2, bh, color.lerp(color(220, 60, 60), color(120, 220, 90), frac))
                end
                local cx = (x1 + x2) / 2
                if show[2] then
                    draw.text(cx, y1 - 14, p.name, color(235, 235, 235), {align = "center", font = "esp", outline = true})
                end
                local below = y2 + 2
                if show[3] then
                    draw.text(cx, below, p.weapon.name, color(200, 200, 200), {align = "center", font = "pixel", outline = true})
                    below = below + 10
                end
                if show[4] then
                    draw.text(cx, below, string.format("%dm", math.floor(p.distance / 52.5)), color(180, 180, 180),
                              {align = "center", font = "pixel", outline = true})
                end
            end
        end
    end
end)

How it works

  • With Teammates on, the list is everyone alive. Otherwise it is only enemies. Your own player is skipped either way.
  • p:box() gives the screen box as two corners, or nil when the player is off screen.
  • The full box draws a dark outline 2 pixels wider first, then the coloured box on top, so it stays readable on bright maps.
  • corners draws eight short lines, a quarter of the box's shorter side each.
  • Text below the box stacks: below moves down 10 pixels after the weapon so the distance does not overlap it.
  • The distance divides game units by 52.5 to show an approximate number of metres.

Note

This script calls game.connected() without checking game first, so it stops with an error if Allow game scripting is off. Add not game or in front of the check if you share it.

Try this

  • Colour the box by visibility with p:is_visible(). Remember it counts toward the map ray budget, so cache it in tick if you have many players.
  • Add a skeleton, see the Skeleton example.