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

Drawing and colours

Shapes, text and images on the overlay, colours, and the old render aliases.

draw

Immediate-mode 2D drawing on the overlay, in screen pixels. Only inside paint handlers.

26 entries

draw.line

function
draw.line(x1, y1, x2, y2, col [, thickness])

Line between two screen points.

Arguments
NameTypeDefaultDescription
x1number
y1number
x2number
y2number
colcolor
thicknessoptionalnumber1
Example
Lua
draw.line(10, 10, 200, 10, color(255, 255, 255), 2)

draw.rect

function
draw.rect(x, y, w, h, col [, thickness [, rounding]])

Rectangle outline.

Arguments
NameTypeDefaultDescription
xnumber
ynumber
wnumber
hnumber
colcolor
thicknessoptionalnumber1
roundingoptionalnumber0
Example
Lua
draw.rect(100, 100, 50, 80, color(255, 0, 0))

draw.rect_filled

function
draw.rect_filled(x, y, w, h, col [, rounding])

Filled rectangle.

Arguments
NameTypeDefaultDescription
xnumber
ynumber
wnumber
hnumber
colcolor
roundingoptionalnumber0
Example
Lua
draw.rect_filled(20, 20, 120, 24, color(17, 17, 17, 240), 4)

draw.gradient

function
draw.gradient(x, y, w, h, tl, tr, br, bl)

Four-corner gradient rectangle (no rounding).

Arguments
NameTypeDescription
xnumber
ynumber
wnumber
hnumber
tlcolor
trcolor
brcolor
blcolor
Example
Lua
draw.gradient(0, 0, 200, 40, color(255,0,0), color(0,255,0), color(0,0,255), color(255,255,255))

draw.gradient_h

function
draw.gradient_h(x, y, w, h, left, right)

Horizontal gradient rectangle.

Arguments
NameTypeDescription
xnumber
ynumber
wnumber
hnumber
leftcolor
rightcolor
Example
Lua
draw.gradient_h(20, 20, 200, 2, ui.accent(), color(0, 0, 0, 0))

draw.gradient_v

function
draw.gradient_v(x, y, w, h, top, bottom)

Vertical gradient rectangle.

Arguments
NameTypeDescription
xnumber
ynumber
wnumber
hnumber
topcolor
bottomcolor
Example
Lua
draw.gradient_v(20, 20, 200, 60, color(30, 30, 30), color(10, 10, 10))

draw.circle

function
draw.circle(x, y, r, col [, thickness [, segments]])

Circle outline (segments 0 = automatic).

Arguments
NameTypeDefaultDescription
xnumber
ynumber
rnumber
colcolor
thicknessoptionalnumber1
segmentsoptionalinteger0
Example
Lua
draw.circle(960, 540, 100, color(255, 255, 255, 120))

draw.circle_filled

function
draw.circle_filled(x, y, r, col [, segments])

Filled circle.

Arguments
NameTypeDefaultDescription
xnumber
ynumber
rnumber
colcolor
segmentsoptionalinteger0
Example
Lua
draw.circle_filled(960, 540, 3, color(143, 108, 240))

draw.arc

function
draw.arc(x, y, r, start_deg, sweep_deg, col [, thickness])

Arc; 0 degrees = +x, clockwise on screen, sweep may be negative.

Arguments
NameTypeDefaultDescription
xnumber
ynumber
rnumber
start_degnumber
sweep_degnumber
colcolor
thicknessoptionalnumber1
Example
Lua
draw.arc(960, 540, 30, -90, 270, color(255, 255, 255), 2)

draw.triangle

function
draw.triangle(x1, y1, x2, y2, x3, y3, col [, filled])

Triangle, outlined or filled.

Arguments
NameTypeDefaultDescription
x1number
y1number
x2number
y2number
x3number
y3number
colcolor
filledoptionalbooleanfalse
Example
Lua
draw.triangle(0, 0, 20, 0, 10, 15, color(255, 255, 0), true)

draw.polygon

function
draw.polygon(points, col [, filled [, thickness]])

Closed polygon; points = flat {x1, y1, x2, y2, ...} or a list of vec2 (at most 512 points). Filled polygons must be convex.

Arguments
NameTypeDefaultDescription
pointstable
colcolor
filledoptionalbooleanfalse
thicknessoptionalnumber1
Example
Lua
draw.polygon({10, 10, 60, 10, 35, 50}, color(0, 200, 255), true)

draw.polyline

function
draw.polyline(points, col [, closed [, thickness]])

Open (or closed) line strip.

Arguments
NameTypeDefaultDescription
pointstable
colcolor
closedoptionalbooleanfalse
thicknessoptionalnumber1
Example
Lua
draw.polyline({0, 0, 50, 20, 100, 0}, color(255, 255, 255))

draw.text

function
draw.text(x, y, text, col [, opts])

Text (at most 1024 bytes). opts = {font=, size=, align="left"|"center"|"right", outline=true, shadow=true}.

Arguments
NameTypeDescription
xnumber
ynumber
textstring
colcolor
optsoptionaltable
Example
Lua
draw.text(20, 20, "hello", color(255, 255, 255), {font = "bold", outline = true})

draw.text_size

function
draw.text_size(text [, font [, size]]) -> number, number

Width and height of text in pixels.

Arguments
NameTypeDescription
textstring
fontoptionalfont
sizeoptionalnumber
Returns
  • number, number
Example
Lua
local w, h = draw.text_size("hello", "bold")

draw.font

function
draw.font(name) -> font

A built-in face: text, bold, small, esp, label, pixel, icons (Boxicons).

Arguments
NameTypeDescription
namestring
Returns
  • font
Example
Lua
local f = draw.font("pixel")

draw.load_font

function
draw.load_font(file, size) -> font | nil, string

Loads a TTF/OTF from scripts/fonts/ (at most 8 per runtime).

Arguments
NameTypeDescription
filestring
sizenumber
Returns
  • font | nil, string
Example
Lua
local f = draw.load_font("Inter.ttf", 14)

draw.load_image

function
draw.load_image(file) -> image | nil, string

Loads a PNG/JPEG from the scripts folder (path relative to it; at most 64 per runtime).

Arguments
NameTypeDescription
filestring
Returns
  • image | nil, string
Example
Lua
local logo = draw.load_image("images/logo.png")

draw.image

function
draw.image(img, x, y, w, h [, tint [, rotation_deg]])

Draws a loaded image, optionally tinted and rotated about its centre.

Arguments
NameTypeDefaultDescription
imgimage
xnumber
ynumber
wnumber
hnumber
tintoptionalcolor
rotation_degoptionalnumber0
Example
Lua
draw.image(logo, 20, 20, 64, 64)

draw.clip_push

function
draw.clip_push(x, y, w, h)

Clips the following draws to a rectangle (balanced automatically at the end of paint).

Arguments
NameTypeDescription
xnumber
ynumber
wnumber
hnumber
Example
Lua
draw.clip_push(0, 0, 100, 20)

draw.clip_pop

function
draw.clip_pop()

Ends the last clip_push.

Example
Lua
draw.clip_pop()

draw.chip

function
draw.chip(spec) -> number, number

The house HUD chip: spec = {x=, y=, label=, value=, accent=, meter=0..1, icon=image, label_color=, value_color=}. Returns its width and height.

Arguments
NameTypeDescription
spectable
Returns
  • number, number
Example
Lua
draw.chip({x = 20, y = 300, label = "KILLS", value = tostring(n)})

draw.panel

function
draw.panel(x, y, w, h [, title]) -> number

The house panel look (frame, accent line, title row). Returns the y of the first content row.

Arguments
NameTypeDescription
xnumber
ynumber
wnumber
hnumber
titleoptionalstring
Returns
  • number
Example
Lua
local y = draw.panel(20, 20, 180, 60, "Stats")

draw.world_line

functionAllow game scripting
draw.world_line(a, b, col [, thickness])

Line between two world points, projected with the drawn camera.

Arguments
NameTypeDefaultDescription
avec3
bvec3
colcolor
thicknessoptionalnumber1

Needs Allow game scripting in Scripts > Security (on by default).

Example
Lua
draw.world_line(p.origin, p.eye_pos, color(255, 0, 0))

draw.world_circle

functionAllow game scripting
draw.world_circle(center, radius, col [, thickness])

Circle on the ground plane around a world point.

Arguments
NameTypeDefaultDescription
centervec3
radiusnumber
colcolor
thicknessoptionalnumber1

Needs Allow game scripting in Scripts > Security (on by default).

Example
Lua
draw.world_circle(p.origin, 20, color(255, 255, 255))

draw.world_text

functionAllow game scripting
draw.world_text(pos, text, col [, opts])

Text at a world point (centred by default).

Arguments
NameTypeDescription
posvec3
textstring
colcolor
optsoptionaltable

Needs Allow game scripting in Scripts > Security (on by default).

Example
Lua
draw.world_text(p.eye_pos, p.name, color(255, 255, 255))

draw.screen_size

function
draw.screen_size() -> number, number

Overlay size in pixels.

Returns
  • number, number
Example
Lua
local w, h = draw.screen_size()

color

Colour helpers; color(r, g, b [, a]) itself is a global.

5 entries

color.hex

function
color.hex(hex) -> color

Parses "#rrggbb[aa]".

Arguments
NameTypeDescription
hexstring
Returns
  • color
Example
Lua
local c = color.hex("#8f6cf0")

color.hsv

function
color.hsv(h, s, v [, a]) -> color

From hue/saturation/value in 0..1.

Arguments
NameTypeDefaultDescription
hnumber
snumber
vnumber
aoptionalinteger255
Returns
  • color
Example
Lua
local rainbow = color.hsv(time.now() % 1, 1, 1)

color.lerp

function
color.lerp(a, b, t) -> color

Blends two colours.

Arguments
NameTypeDescription
acolor
bcolor
tnumber
Returns
  • color
Example
Lua
local c = color.lerp(color(255,0,0), color(0,255,0), 0.5)

color.alpha

function
color.alpha(c, a) -> color

The colour with another alpha.

Arguments
NameTypeDescription
ccolor
ainteger
Returns
  • color
Example
Lua
local faded = color.alpha(c, 100)

color.unpack

function
color.unpack(c) -> integer, integer, integer, integer

r, g, b, a of a colour.

Arguments
NameTypeDescription
ccolor
Returns
  • integer, integer, integer, integer
Example
Lua
local r, g, b, a = color.unpack(c)

render (compat)

Compatibility aliases over draw.*. Prefer draw.* in new scripts.

19 entries

render.draw_line

function
render.draw_line(p0, p1, col [, thickness])

Alias for draw.line.

Arguments
NameTypeDescription
p0vec2
p1vec2
colcolor
thicknessoptionalnumber

render.draw_rect

function
render.draw_rect(pos, size, col [, thickness [, rounding]])

draw.rect.

Arguments
NameTypeDescription
posvec2
sizevec2
colcolor
thicknessoptionalnumber
roundingoptionalnumber

render.draw_rect_filled

function
render.draw_rect_filled(pos, size, col [, rounding])

draw.rect_filled.

Arguments
NameTypeDescription
posvec2
sizevec2
colcolor
roundingoptionalnumber

render.draw_circle

function
render.draw_circle(center, r, col [, thickness [, filled]])

draw.circle / circle_filled.

Arguments
NameTypeDescription
centervec2
rnumber
colcolor
thicknessoptionalnumber
filledoptionalboolean

render.draw_polygon

function
render.draw_polygon(points, n, col [, thickness [, filled]])

draw.polygon.

Arguments
NameTypeDescription
pointsvec2[]
ninteger
colcolor
thicknessoptionalnumber
filledoptionalboolean

render.draw_triangle

function
render.draw_triangle(a, b, c, col [, thickness [, filled]])

draw.triangle.

Arguments
NameTypeDescription
avec2
bvec2
cvec2
colcolor
thicknessoptionalnumber
filledoptionalboolean

render.draw_arc

function
render.draw_arc(center, r, start_deg, sweep_deg, col [, thickness])

draw.arc.

Arguments
NameTypeDescription
centervec2
rnumber
start_degnumber
sweep_degnumber
colcolor
thicknessoptionalnumber

render.draw_four_corner_gradient

function
render.draw_four_corner_gradient(pos, size, tl, tr, br, bl)

draw.gradient.

Arguments
NameTypeDescription
posvec2
sizevec2
tlcolor
trcolor
brcolor
blcolor

render.draw_text

function
render.draw_text(text, pos, col [, font [, outline [, shadow_color [, shadow_px [, size]]]]])

draw.text.

Arguments
NameTypeDescription
textstring
posvec2
colcolor
fontoptionalfont
outlineoptionalboolean
shadow_coloroptionalcolor
shadow_pxoptionalnumber
sizeoptionalnumber

render.get_text_size

function
render.get_text_size(font, text) -> vec2

draw.text_size.

Arguments
NameTypeDescription
fontfont
textstring
Returns
  • vec2

render.create_font

function
render.create_font(file, size) -> font

draw.load_font.

Arguments
NameTypeDescription
filestring
sizenumber
Returns
  • font

render.create_bitmap

function
render.create_bitmap(file) -> image

draw.load_image.

Arguments
NameTypeDescription
filestring
Returns
  • image

render.draw_bitmap

function
render.draw_bitmap(bmp, pos, size [, tint])

draw.image.

Arguments
NameTypeDescription
bmpimage
posvec2
sizevec2
tintoptionalcolor

render.clip_push

function
render.clip_push(pos, size)

draw.clip_push.

Arguments
NameTypeDescription
posvec2
sizevec2

render.clip_pop

function
render.clip_pop()

draw.clip_pop.

render.get_view_width

function
render.get_view_width() -> number

Overlay width.

Returns
  • number

render.get_view_height

function
render.get_view_height() -> number

Overlay height.

Returns
  • number

render.get_fps

function
render.get_fps() -> number

time.fps().

Returns
  • number

render.get_frame_index

function
render.get_frame_index() -> integer

time.frame().

Returns
  • integer