Events, the script and globals
Callbacks, the script object, time, logging and the global helpers.
Callbacks
23 eventsName a function on_<event> or pass it to events.on.
| Event | When | Arguments |
|---|---|---|
combat | Before 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 |
paint | Every visible overlay frame: draw here. | none |
tick | Fixed 64 Hz, also while the overlay is hidden. | dt:number |
load | After a successful load or reload. | none |
unload | Before the script's state closes. | none |
menu | The menu opened or closed. | open:boolean |
map_change | The map changed ("" on disconnect). Needs game scripting. | map:string |
player_hurt | A listed player's health dropped: e = {player = {index, name, team, is_enemy}, pos, damage, health}. | e:table |
player_death | A listed player died (not by the local player): e = {player, pos}. | e:table |
local_kill | A death attributed to the local player: e = {player, pos, local_kill = true}. | e:table |
round_start | Approximate: several players listed alive again at once. | none |
bomb_planted | The C4 was planted: e = {site, pos}. | e:table |
bomb_defused | The planted C4 was defused. | e:table |
bomb_exploded | The planted C4 exploded. | e:table |
config_change | The active evasive profile was switched or reloaded. | name:string |
local_hit | The 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_sound | A 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_fire | A listed player fired (an edge of Player.last_fired): e = {player = {index, name, team, is_enemy, is_local}, weapon, pos = eye}. | e:table |
grenade_detonate | A grenade went off (HE / flash / decoy exploded, smoke bloomed, a molotov's fire appeared): e = {kind, index, pos, thrower}. | e:table |
freeze_start | Freezetime (or the team intro) began. | none |
round_live | Freezetime ended: the round is live. | none |
local_spawn | The local player became alive. | none |
local_death | The local player died. | none |
events.on(name, callback) -> integerAdds a handler; returns a token for events.off. Globals named on_<event> are registered too.
| Name | Type | Description |
|---|---|---|
name | string | |
callback | function |
integer
events.on("paint", function() end)events.off(name [, token]) -> booleanRemoves one handler (or all of the event without a token).
| Name | Type | Description |
|---|---|---|
name | string | |
tokenoptional | integer |
boolean
events.off("paint", token)The script's @name (or file stem).
string
The script's file name.
string
script.unload()Unloads this script after the callback.
script.unload()script.reload()Reloads this script after the callback.
script.reload().skeleton_pairsFlat parent, child bone id pairs of the skeleton.
integer[]
Needs Allow game scripting in Scripts > Security (on by default).
for i = 1, #skeleton_pairs, 2 do endprint(...)Same as log.info.
| Name | Type | Description |
|---|---|---|
... | any |
print("hello")color(r, g, b [, a]) -> colorPacks a colour as 0xRRGGBBAA. Wherever a colour is taken, {r,g,b,a} and "#rrggbbaa" work too.
| Name | Type | Default | Description |
|---|---|---|---|
r | integer | ||
g | integer | ||
b | integer | ||
aoptional | integer | 255 |
color
local purple = color(143, 108, 240)vec2(x, y) -> vec22D vector with + - * /, :length(), :dist(o), :normalize(), :dot(o), :unpack().
| Name | Type | Description |
|---|---|---|
x | number | |
y | number |
vec2
local p = vec2(10, 20) + vec2(1, 1)vec3(x, y, z) -> vec33D vector with + - * /, :length(), :length_2d(), :dist(o), :normalize(), :dot(o), :cross(o), :unpack(). Game positions are vec3.
| Name | Type | Description |
|---|---|---|
x | number | |
y | number | |
z | number |
vec3
local d = p.origin:dist(me.origin)key_down(vk) -> booleanAlias for input.is_down.
| Name | Type | Description |
|---|---|---|
vk | integer |
boolean
if key_down(vk.insert) then endget_mouse_pos() -> vec2Alias for input.mouse.
vec2
local m = get_mouse_pos()register_routine(fn [, data]) -> integerAlias: fn(data) on every tick.
| Name | Type | Description |
|---|---|---|
fn | function | |
dataoptional | any |
integer
register_routine(function(d) end, nil)time.now() -> numberSeconds from a steady clock (QPC).
number
local t = time.now()time.delta() -> numberSeconds since the previous overlay frame.
number
x = x + speed * time.delta()time.fps() -> numberOverlay frames per second.
number
draw.text(10, 10, tostring(math.floor(time.fps())), color(255,255,255))time.frame() -> integerOverlay frame counter (draw frames and logic ticks).
integer
if time.frame() % 2 == 0 then endtime.date([format]) -> stringLocal date/time formatted with strftime specifiers (aAbBcdHIjmMpSUwWxXyYZ).
| Name | Type | Default | Description |
|---|---|---|---|
formatoptional | string | %H:%M:%S |
string
local clock = time.date("%H:%M")log.info(...)Writes to the script console.
| Name | Type | Description |
|---|---|---|
... | any |
log.info("loaded", 42)log.warn(...)Writes a warning to the script console.
| Name | Type | Description |
|---|---|---|
... | any |
log.warn("careful")log.error(...)Writes an error to the script console.
| Name | Type | Description |
|---|---|---|
... | any |
log.error("failed")