Other great resources: Official JS API docs, Scripting Forum
Events & Timers
- Aubergine
Overview
When Warzone is processing your script, everything else in the game stops. So your script can't just run in a never-ending loop - it has to do something, then stop, so that Warzone can get on with other stuff. So, without events, your script would do one thing, then stop and never start again. In fact, it wouldn't even start in the first place - everything has to be event driven!
Warzone provides a number of pre-defined events, and some functions which allow you to create custom events (see bottom of this page). When an event is triggered, your event listener/handler (a function) should perform some task based on that event. For example, if a droid gets attacked you might want to send it for repairs or retreat it to a safe distance.
The normal JS API only allows you to attach a single event handler to each event - which is fine for most scenarios. However, if you need to attach multiple events you'll need to use uTardis() that's part of Util.js.
Pre-defined events
Warzone's qtscript.cpp defines and triggers a large number of extremely useful events. If one of these events is triggered before you are ready to do something (eg. your Laser Satellite Command Post is ready to attack but you don't yet have a suitable target) you can set up a custom event (using queue() for example) to do something later in the game.
- eventBeaconRemoved() — This event is triggered each time a beacon is removed.
- eventDroidBuilt() — This event is triggered when you get a new droid as a result of buildDroid() or addDroid()...
- eventTransporterArrived() — Triggered when a mission transporter has arrived on the map with reinforcements....
- eventReinforcementsArrived() — Triggered when a mission transporter has arrived on the map with reinforcements....
- eventPickup() — Triggered when an oil barrel or artifiact is picked up by a droid...
- eventTransporterExit() — Triggered when a mission transporter leaves the map...
- eventGameLoaded() — This event is triggered once after a saved game is loaded.
- eventAttackedUnthrottled() — This event is called when your droids or structures are attacked.
- eventArea<Label>() — An event that's triggered when a droid enters a labelled Area object...
- eventStructureReady() — This event is triggered when a structure is ready to perform its special ability.
- eventResearched() — Triggered when a new technology has been researched by you or an ally...
- eventBeacon() — This event is triggered each time a new beacon is received.
- eventAttacked() — This event is called when your droids or structures are attacked.
- eventGroupLoss() — Triggered when a game object leaves a group...
- eventGameSaved()
- eventStartLevel() — This event is triggered once at the start of a new game after the map is ready and all game data loaded. It is also triggered once after a new level is loaded.
- eventStructureBuilt()
- eventMissionTimeout() — This event triggers when the mission timer runs out...
- eventPlayerLeft() — Triggers if a player leaves the game...
- eventDroidIdle() — This event is triggered when a droid is twiddling it's turrets because it's got nothing to do.
- eventTransporterDone() — Stick a fork in it, it's done...
- eventTransporterLaunch() — Triggered when a mission transporter has been instructed to launch....
- eventLaunchTransporter() — Triggered when a mission transporter has been instructed to launch....
- eventObjectRecycled() — Triggered when a droid is recycled or when a structure is demolished by a truck...
- eventCheatMode() — This event is called when the human player enters cheat mode...
- eventTransporterLanded() — Triggered when a transporter lands...
- eventGameSaving()
- eventChat() — This event is triggered each time a chat message is received.
- eventVideoDone()
- eventObjectSeen() — This event is triggered when one of your sensors detects something new on the map.
- eventObjectTransfer() — This event is triggered when a droid or structure is transferred to or from another player...
- eventDesignCreated() — Triggers when a player saves a new template in the droid designer...
- eventGameInit() — This event is triggered once at the start of a new game before the map is ready.
- eventDestroyed() — Triggered when a game object is destroyed...
- bind() — Register a function to be called when a game object gets destroyed.
- eventSelectionChange() — Triggered when the user selects or deselects objects...
Custom events
You can create custom events using Timers:
- setTimer() – create a repeating schedule to trigger a function call
- queue() – create a one-time schedule to trigger a function call
- removeTimer() – cancel a timed or queued function call
Deprecated events
In Warzone 3.1, there was another custom event mechanism:
- bind() – set up an event that will be triggered when a specific object is destroyed (any object, an owner)
In Warzone 3.2 and above, use eventDestroyed() instead – it was updated to trigger when any object, of any type or player, is destroyed.
Availability
New events have been added at various stages of Warzone's evolution.
For a summary of availability and changes, see: Events by version.
See also
Related documentation:
- Environment Sequences – learn about the sequence of events, and what you can do at different stages of that sequence