Events and timers
Everything outside an event runs on every tick of the game, after that tick's deaths and spawns. A paused game has no ticks. An event has one handler, at the top level of the file; on object damaged may have more:
| Event | current_… in it | Values in it |
|---|---|---|
| The script's body | None until a loop sets one | Runs every tick. |
on init: do … end | None | Once, as each round starts. |
on widget click: do … end | The player who clicked | clicked_widget: the widget's number. See script menus. |
on button press: do … end | The player who pressed | pressed_button: button.melee and so on. See buttons. |
on player join: do … end | The player joining | A player joins the game, before their first body. Those already there as the round's script begins get it too. |
on player spawn: do … end | The player who spawned | Their new body is there. selected_deploy_object: the object they chose to deploy at, or no_object. |
on player quit: do … end (or player leave) | The player leaving | Once as a player leaves the game, while their variables are still there to read and write; again if they come back and leave again. |
on player team change: do … end | The player who moved | previous_team: the team they left. current_team: theirs now. |
on vehicle enter: do … end, on vehicle exit: do … end | The player; current_object: the vehicle | Their body takes or leaves a seat. vehicle_seat: the seat's number in the vehicle. A seat left for another raises both. |
on objective pickup: do … end | The carrier; current_object: the flag, bomb or ball | A player takes one up. |
on objective drop: do … end | The player who carried it; the item | They let it go or died. killer_player: their killer, else no_player. |
on objective reset: do … end | No player; the item | The game type puts one back: Capture the Flag's flag, Assault's bomb, Oddball's ball. current_team: its team, no_team for the ball. |
on objective scored: do … end | The player who scored | A capture in Capture the Flag, a detonation in Assault. current_team: theirs. Points a script gives don’t count as one. |
on territory captured: do … end | None; current_object: the territory's marker | A Territories game's territory changes hands: previous_team, current_team. |
on vip change: do … end | The new VIP | A team’s VIP changes in the VIP game type: current_team, previous_player (no_player for the first). |
on juggernaut change: do … end | The new Juggernaut | previous_player. |
on bomb armed: do … end | The player who armed it | Assault's bomb is armed: current_team, their team. |
on deployment selected: do … end | The player who chose | They chose where to deploy on the deployment map: selected_deploy_object, no_object for nowhere in particular. current_player.get_selected_deploy_point() reads it later. |
on object damaged: do … end | current_object: the object hit (no_object once gone). current_player: who's responsible (no_player for the world or the AI). | damage_category: damage.bullet and so on. damage_source_object: the attacker's body or vehicle the damage came from, or no_object. damage_incoming and damage_inflicted: the damage as it came and as the mode's rules left it, in tenths of a point; a hit an object's rules refuse whole reads 0 for both. See damage. |
on object death: do … end | The player whose body died | killed_object: the body, while it lies there. killer_player: no_player after a suicide, a betrayal or a death to the world or the AI. killer_object: the killer's body. |
Outside their events, clicked_widget, pressed_button and damage_category are −1. on object damaged runs once for every hit on every object while a round is played: each round of automatic fire, and each object a blast reaches. Keep its handler short.
Beside the plain handler, a source may have handlers for the hits on objects of one label, or of one damage category, alone: on object damaged with label "target": do … end and on object damaged with type damage.plasma: do … end. Each runs in the order written.
objective pickup and objective drop come from the items themselves, the map's flag, bomb and ball and any a script makes, so they play under every game type. objective reset, objective scored, vip change, juggernaut change and bomb armed are the game type's own, and come only in the game types that have them (mode in the header).
on object death: do
if killer_player != no_player then
killer_player.score += 1
current_player.score -= 1
end
end
Reach's pregame runs before init as a round starts, and local each tick once for each player: see Reach's calls.
Timers
- Timers count seconds, fractions included.
set_rate(-100%)counts down one second per second of play,100%counts up,0%stops. Other rates: 10, 25, 50, 75, 125, 150, 175, 200, 300, 400, 500 and 1000%, either sign, written as a plain value. - A timer counting down stops at 0.
reset()puts back its declared value but keeps its rate, so callset_rateagain for a timer that repeats.is_zero()is a test, not an event: check it every tick. - A timer counting up stops at its declared value if that value is above 0. Assignment and arithmetic can change a timer's value; it can't go below zero. Reading a timer into a number drops the fraction.
- For something that repeats on a fixed beat,
game.get_tick()gives the ticks since the round began, andgame.get_ticks_per_second()the game's ticks a second, 30 or 60.if mod(game.get_tick(), game.get_ticks_per_second() * 5) == 0 thenholds once every five seconds, with no timer to reset.
