Working with events
Callbacks let a script respond when the runtime or game has something to report.
Register a callback
local function on_hurt(event)
local victim = client.userid_to_entindex(event.userid)
if victim == entity.get_local_player() then
client.log("Damage taken: ", event.dmg_health)
end
end
client.set_event_callback("player_hurt", on_hurt)Game event user IDs are not entity indexes. Convert them before passing them to entity functions.
Remove a callback
client.unset_event_callback("player_hurt", on_hurt)Keep the function reference if you plan to unregister it later. Passing a newly created function does not identify the original callback.
Drawing callbacks
Use paint for in-game visuals. Keep expensive initialization and repeated file parsing outside per-frame callbacks. Cache reusable data, then draw from it.
Event reference
The sidebar separates runtime events, Source engine events and CS:GO events. These imported event descriptions are an upstream reference, not a guarantee that every event is emitted by the 2018 game or this runtime.