listener
Callbacks for game / paint / cmd events.
paint
paint(width: number, height: number)
- Called every frame with the screen width and height.
secret.listener.add("paint", "example", function(w, h)
-- ...
end)
createmove
createmove(cmd: cmd)
- Called each createmove with the current cmd.
- The cmd is only valid inside this callback.
secret.listener.add("createmove", "bhop_strip", function(cmd)
cmd:remove_button(secret.cmd.buttons.jump)
end)
game_event
game_event(event: game_event)
- Called when a game event is fired.
- The event object is only valid inside this callback.
event:valid(): boolean
- Returns if the event is still valid.
event:name(): string | nil
- Returns the event name.
event:get_bool(key: string): boolean
- Returns a boolean field.
event:get_int(key: string): number | nil
- Returns an int field.
event:get_float(key: string): number | nil
- Returns a float field.
event:get_string(key: string): string | nil
- Returns a string field.
event:get_uint64(key: string): string | nil
- Returns a uint64 field as a string.
event:get_player_index(key: string): number | nil
- Returns a player index field.
event:get_controller(key: string): entity | nil
- Returns the controller for a player field.
event:get_pawn(key: string): entity | nil
- Returns the pawn for a player field.
secret.listener.add("game_event", "deaths", function(ev)
if not ev:valid() or ev:name() ~= "player_death" then return end
local victim = ev:get_controller("userid")
if victim then
print(victim:name(), "died")
end
end)
level_init
level_init(map: string)
- Called when a map loads.
secret.listener.add("level_init", "reset", function(map)
print(map)
end)
level_shutdown
level_shutdown()
- Called when a map unloads.
frame_stage
frame_stage(stage: number)
- Called on client frame stage.
secret.listener.add("frame_stage", "example", function(stage)
print(stage)
end)
Delay / unload
Delay(seconds: number, callback: () => void)
- Schedules
callbackaftersecondsof realtime. - Available as
Delayandsecret.Delay. - Cleared automatically when the script stops.
Delay(1.5, function()
print("later")
end)
__shutdown()
- Optional global. Called right before the script state is closed.
function __shutdown()
print("script unloading")
end