eventPlayerDefeated()

(info) This AI is still in early stages of development.

eventPlayerDefeated()

A global event triggered when a player is defeated.

 

Syntax

function eventPlayerDefeated(player) { // code to run when player dies }

Parameters

Parameter

Type

Mandatory

Notes

API Version

Parameter

Type

Mandatory

Notes

API Version

player

Players Object

The players object associated with the player that was defeated.

1.0

Return value

The return value is not currently processed.

Notes

The event is not triggered for players identified as spectators or vacant slots.

After the player is defeated, the event may lag behind a little - it's only triggered the next time a script tries to determine if the player is alive (and even then only when any caches invalidate). If you want to force a periodical check, set a timer as follows:

Force state check every 2 seconds
function checkPlayerStates() { void Players.alive; // will cause applicable events to be triggered } setTimer("checkPlayerStates", 2000); // check every 2 seconds

Example

Display message when player defeated
function eventPlayerDefeated(player) { console(""+player+" has been defeated"); // maybe now would be a good time to claim their oil? // or mop up any remaining buildings they have (eg. research labs) }