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

Events, the script and globals

Callbacks, the script object, time, logging and the global helpers.

events

Add and remove callback handlers (see Callbacks).

2 entries

Callbacks

23 events

Name a function on_<event> or pass it to events.on.

EventWhenArguments
combatBefore native combat on a new game frame. Needs the act permission (an approved exact source) and fires only while the script may act: running, no script panic, the overlay menu closed and no overlay text field focused, a local player alive. It does not check Allow input, window focus, the CS2 cursor or chat: action requests made then are refused "input disabled", "focus", "cursor" or "chat". 0.5 ms per script within the shared frame budget.dt:number
paintEvery visible overlay frame: draw here.none
tickFixed 64 Hz, also while the overlay is hidden.dt:number
loadAfter a successful load or reload.none
unloadBefore the script's state closes.none
menuThe menu opened or closed.open:boolean
map_changeThe map changed ("" on disconnect). Needs game scripting.map:string
player_hurtA listed player's health dropped: e = {player = {index, name, team, is_enemy}, pos, damage, health}.e:table
player_deathA listed player died (not by the local player): e = {player, pos}.e:table
local_killA death attributed to the local player: e = {player, pos, local_kill = true}.e:table
round_startApproximate: several players listed alive again at once.none
bomb_plantedThe C4 was planted: e = {site, pos}.e:table
bomb_defusedThe planted C4 was defused.e:table
bomb_explodedThe planted C4 exploded.e:table
config_changeThe active evasive profile was switched or reloaded.name:string
local_hitThe local player hit someone (the server's hit counter, matched to a health drop like the hit log): e = {player = {index, name, team, is_enemy} | nil, damage, health = left, hitgroup = hitgroup.* (-1 unknown), headshot, killed}.e:table
player_soundA listed player made a sound others hear (footsteps, landing, ...; an edge of Player.last_sound): e = {player = {index, name, team, is_enemy, is_local}, pos, time}.e:table
weapon_fireA listed player fired (an edge of Player.last_fired): e = {player = {index, name, team, is_enemy, is_local}, weapon, pos = eye}.e:table
grenade_detonateA grenade went off (HE / flash / decoy exploded, smoke bloomed, a molotov's fire appeared): e = {kind, index, pos, thrower}.e:table
freeze_startFreezetime (or the team intro) began.none
round_liveFreezetime ended: the round is live.none
local_spawnThe local player became alive.none
local_deathThe local player died.none

events.on

function
events.on(name, callback) -> integer

Adds a handler; returns a token for events.off. Globals named on_<event> are registered too.

Arguments
NameTypeDescription
namestring
callbackfunction
Returns
  • integer
Example
Lua
events.on("paint", function() end)

events.off

function
events.off(name [, token]) -> boolean

Removes one handler (or all of the event without a token).

Arguments
NameTypeDescription
namestring
tokenoptionalinteger
Returns
  • boolean
Example
Lua
events.off("paint", token)

script

The running script itself.

4 entries

script.name

field

The script's @name (or file stem).

Returns
  • string

script.file

field

The script's file name.

Returns
  • string

script.unload

function
script.unload()

Unloads this script after the callback.

Example
Lua
script.unload()

script.reload

function
script.reload()

Reloads this script after the callback.

Example
Lua
script.reload()

Globals

Global functions and values.

8 entries

skeleton_pairs

constantAllow game scripting
.skeleton_pairs

Flat parent, child bone id pairs of the skeleton.

Returns
  • integer[]

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

Example
Lua
for i = 1, #skeleton_pairs, 2 do end

print

global
print(...)

Same as log.info.

Arguments
NameTypeDescription
...any
Example
Lua
print("hello")

color

global
color(r, g, b [, a]) -> color

Packs a colour as 0xRRGGBBAA. Wherever a colour is taken, {r,g,b,a} and "#rrggbbaa" work too.

Arguments
NameTypeDefaultDescription
rinteger
ginteger
binteger
aoptionalinteger255
Returns
  • color
Example
Lua
local purple = color(143, 108, 240)

vec2

global
vec2(x, y) -> vec2

2D vector with + - * /, :length(), :dist(o), :normalize(), :dot(o), :unpack().

Arguments
NameTypeDescription
xnumber
ynumber
Returns
  • vec2
Example
Lua
local p = vec2(10, 20) + vec2(1, 1)

vec3

global
vec3(x, y, z) -> vec3

3D vector with + - * /, :length(), :length_2d(), :dist(o), :normalize(), :dot(o), :cross(o), :unpack(). Game positions are vec3.

Arguments
NameTypeDescription
xnumber
ynumber
znumber
Returns
  • vec3
Example
Lua
local d = p.origin:dist(me.origin)

key_down

global
key_down(vk) -> boolean

Alias for input.is_down.

Arguments
NameTypeDescription
vkinteger
Returns
  • boolean
Example
Lua
if key_down(vk.insert) then end

get_mouse_pos

global
get_mouse_pos() -> vec2

Alias for input.mouse.

Returns
  • vec2
Example
Lua
local m = get_mouse_pos()

register_routine

global
register_routine(fn [, data]) -> integer

Alias: fn(data) on every tick.

Arguments
NameTypeDescription
fnfunction
dataoptionalany
Returns
  • integer
Example
Lua
register_routine(function(d) end, nil)

time

Clocks, the overlay frame rate, date formatting.

5 entries

time.now

function
time.now() -> number

Seconds from a steady clock (QPC).

Returns
  • number
Example
Lua
local t = time.now()

time.delta

function
time.delta() -> number

Seconds since the previous overlay frame.

Returns
  • number
Example
Lua
x = x + speed * time.delta()

time.fps

function
time.fps() -> number

Overlay frames per second.

Returns
  • number
Example
Lua
draw.text(10, 10, tostring(math.floor(time.fps())), color(255,255,255))

time.frame

function
time.frame() -> integer

Overlay frame counter (draw frames and logic ticks).

Returns
  • integer
Example
Lua
if time.frame() % 2 == 0 then end

time.date

function
time.date([format]) -> string

Local date/time formatted with strftime specifiers (aAbBcdHIjmMpSUwWxXyYZ).

Arguments
NameTypeDefaultDescription
formatoptionalstring%H:%M:%S
Returns
  • string
Example
Lua
local clock = time.date("%H:%M")

log

Output to the script console.

3 entries

log.info

function
log.info(...)

Writes to the script console.

Arguments
NameTypeDescription
...any
Example
Lua
log.info("loaded", 42)

log.warn

function
log.warn(...)

Writes a warning to the script console.

Arguments
NameTypeDescription
...any
Example
Lua
log.warn("careful")

log.error

function
log.error(...)

Writes an error to the script console.

Arguments
NameTypeDescription
...any
Example
Lua
log.error("failed")