Lua · Documentation

Events

A script reacts by defining global functions (callbacks) or by adding handlers with events.on. When both exist for the same event, both run.

Callbacks

CallbackWhen
on_frame()Every overlay frame. The only place drawing works.
on_tick()64 times a second, at most 4 times per frame. Good for logic that should not depend on FPS.
on_menu()Every frame while the script's tab is open. menu.* widgets work only here.
on_unload()Right before the script is turned off, reloaded or deleted.
on_notepad_save(id, text)The user pressed Save in a notepad this script opened.
on_kill(e)You killed someone.
on_death(e)You died.
on_round_start()A new round began.
on_round_end(e)The round ended.
callbacks.lua
function on_tick()
end

function on_frame()
end

function on_unload()
    db.set("last_seen", globals.time())
end

events.on

events.on(name, handler) adds a handler; you can add many to one event, from different parts of your script. events.off(name) removes them all.

events.lua
events.on("player_hurt", function(e)
    if e.enemy then print(e.name .. " -" .. e.damage) end
end)

events.on("bomb_planted", function(e)
    notify.push("Bomb on " .. e.site)
end)

Events

kill

You got a kill. Also calls on_kill(e).

FieldTypeMeaning
victimstringName of the player you killed, or empty when not seen.
weaponstringYour weapon: AK, AWP, M4A1S, DEAGLE, KNIFE, HE, …
headshotboolean
knifebooleanA knife kill.
round_killsintegerYour kills this round, this one included.

death

You died. Also calls on_death(e). The table is empty.

round_start

A round began. Also calls on_round_start() (no argument). The table is empty.

round_end

A round ended. Also calls on_round_end(e).

FieldTypeMeaning
wonbooleanYour team won.
winnerinteger2 = T won, 3 = CT won, other values for a draw.

player_hurt

Any player lost health since the last frame.

FieldTypeMeaning
slotinteger
namestring
damageintegerHealth lost.
healthintegerHealth left.
enemyboolean
is_localbooleanIt was you.

player_death

A player's health reached 0. Same fields as player_hurt.

FieldTypeMeaning
slotinteger
namestring
damageinteger
healthintegerAlways 0.
enemyboolean
is_localboolean

bomb_planted

The bomb was planted.

FieldTypeMeaning
sitestringA, B or empty.

bomb_defused

The bomb was defused. The table is empty.

bomb_exploded

The bomb exploded. The table is empty.

spectator_join

Someone started watching you.

FieldTypeMeaning
namestring

spectator_leave

Someone stopped watching you.

FieldTypeMeaning
namestring

shot_fired

Any player fired.

FieldTypeMeaning
slotinteger
namestring
enemyboolean
is_localboolean
shotsintegerShots in the current spray.
weaponstring

flashed

A player got flashed.

FieldTypeMeaning
slotinteger
namestring
enemyboolean
is_localboolean
durationnumberSeconds.

spotted

A player became spotted by you.

FieldTypeMeaning
slotinteger
namestring
enemyboolean

unspotted

A player is no longer spotted by you.

FieldTypeMeaning
slotinteger
namestring
enemyboolean

bomb_defusing

Someone started defusing.

FieldTypeMeaning
slotinteger
namestring
enemyboolean

purchase

A player spent money.

FieldTypeMeaning
slotinteger
namestring
enemyboolean
is_localboolean
spentinteger
moneyintegerMoney left.

sound

A game sound was heard (needs Sound ESP on).

FieldTypeMeaning
typestringfootstep, shot, jump, reload, scope, land.
slotinteger-1 when unknown.
enemyboolean
posvector

footstep

Only footsteps from sound. Same fields.

FieldTypeMeaning
slotinteger
enemyboolean
posvector

weapon_switch

You changed weapons.

FieldTypeMeaning
fromstring
tostring

jump

You left the ground.

FieldTypeMeaning
speednumberUpward speed.

land

You landed.

FieldTypeMeaning
speednumberFall speed.

scope

You scoped in.

FieldTypeMeaning
weaponstring

unscope

You scoped out.

FieldTypeMeaning
weaponstring

reload

You started reloading.

FieldTypeMeaning
weaponstring

reload_end

Your reload finished or was cancelled.

FieldTypeMeaning
weaponstring

zone_enter

You walked into one of this script's world.zones. Only that script gets it.

FieldTypeMeaning
idinteger
namestring

zone_leave

You walked out of one of this script's zones.

FieldTypeMeaning
idinteger
namestring

Timing

  • Events run once a frame, before on_tick and on_frame.
  • Kills, deaths and rounds are checked 10 times a second while you are in a match, so they can arrive up to 0.1 s late.
  • player_hurt and player_death come from health changes between frames: two hits in one frame show as one event with the sum.
  • The kill victim is the player whose death was seen within 1.5 s; otherwise it is empty.
  • on_tick runs 64 times a second on average, but at most 4 times in one frame. At low FPS some ticks are dropped.