wolfhacklua API 1.1 Forum

events

Subscribe to what the overlay does: frames, drawing, the menu, setting changes, and (with game data) match changes.

since 1.0no permission needed

A script can have at most 64 handlers. Handlers run on the thread that draws, inside the time budget (3 ms; see performance). Every handler is removed when the script stops.

The order in one frame is: finished downloads and uploads, timers, tasks, frame handlers, the menu and your tabs, then the overlay (draw handlers and widgets).

Reference#

events.on#since 1.0

events.on(name: string, fn: function): integer

Subscribes fn to an event. A bad event name is an error.

ParameterTypeDescription
namestringAn event name from the list below.
fnfunctionCalled with the event's arguments.
ReturnsDescription
integerA handler id for events.off.
lua
local id = events.on("frame", function(dt)
  -- runs every frame
end)

events.once#since 1.0

events.once(name: string, fn: function): integer

Like on, for a handler that should run a single time.

ParameterTypeDescription
namestringAn event name.
fnfunctionCalled once, then removed.
ReturnsDescription
integerA handler id.

events.off#since 1.0

events.off(id: integer): boolean

Removes one handler.

ParameterTypeDescription
idintegerAn id returned by on or once.
ReturnsDescription
booleantrue when a handler was removed.

frame#since 1.0event

events.on("frame", function(dt) end)   -- dt: number

Every frame, before the menu is built. Good for logic that does not draw.

ParameterTypeDescription
dtnumberSeconds since the previous frame.

draw#since 1.0event

events.on("draw", function() end)

The overlay layer: draw here with the draw functions, in screen coordinates. draw.* is only valid inside this handler, a widget's draw and a ui.canvas callback.

unload#since 1.0event

events.on("unload", function() end)

The script is about to go away (switched off, reloaded, removed, or the overlay is closing). It has 25 ms. A script the host has already stopped for misbehaving does not get it. Save what you need; the store is saved afterwards anyway.

menu#since 1.0event

events.on("menu", function(open) end)   -- open: boolean

The menu opened or closed.

ParameterTypeDescription
openbooleantrue when the menu opened.

settings#since 1.0event

events.on("settings", function(key) end)   -- key: string

A value in the script's store changed, by a control with an id or by store.set.

ParameterTypeDescription
keystringThe store key that changed.

ingame#since 1.0event

events.on("ingame", function(in_game) end)   -- in_game: boolean

The player entered or left a match. Fires on the change only, not when the script loads: read data.snapshot().in_game on your first frame for the starting state.

ParameterTypeDescription
in_gamebooleanWhether a match is loaded.

map#since 1.0event

events.on("map", function(name) end)   -- name: string

A different map was loaded. Fires on the change only; data.snapshot().map has the current one.

ParameterTypeDescription
namestringThe map name, for example de_mirage.

bomb#since 1.0event

events.on("bomb", function(state) end)   -- state: string

The bomb was planted, or is no longer planted (exploded, defused or the round ended).

ParameterTypeDescription
statestring"planted" or "gone".

media_track#since 1.0event

events.on("media_track", function(track) end)   -- track: table

The system's media session changed track. See media.

ParameterTypeDescription
tracktable{title, artist, app, duration} of the new track.

Example#

Several events in one script:

lua
events.on("frame", function(dt) end)
events.on("map", function(name) log.info("map: " .. name) end)
events.on("unload", function() log.info("bye") end)
API 1.1 · source docs-src/api/events.json