Player object

(info) Other great resources: Official JS API docs, Scripting Forum

Player object

Specifies useful static information about a specific player in the game.

 

Properties

Property

Type

Description

Game version

Property

Type

Description

Game version

difficulty

Constant

The player's difficulty level, which can be set for AI players on the game set-up screen:

Human players currently default to MEDIUM difficulty.

3.1

colour

Integer

The numeric Colour ID of the colour that's used on the player's units and buildings. They are also shown as this colour on the mini map.

Refer to "Colour ID" in the Colour Palette to determine what the actual colour is.

3.1

position

Integer

The map position to which the player is assigned. You can find it's x,y co-ordinates by cross-referencing against the startPositions[] array.

Note: This is not the same as the player ID. You can determine the player ID associated with your script using the "me" global.

3.1

team

Integer

The team to which the player is assigned, represented as a number (0 = A, 1 = B, etc).

The team is always specified, regardless of alliancesType mode:

Note: Maps can specify defaults for teams, see <mapname>.ini for details.

3.1

type

Constant

PLAYER_DATA

3.1 Beta 11

isHuman

Boolean

Is the player a human being?

  • true – yes

  • false – no, or the player slot is empty

3.2

isAI

Boolean

Is the player an AI bot?

  • true – yes

  • false – no, or the player slot is empty

3.2

name

String

Player's name

3.2

Scavengers

 The Scavenger Faction does not have an associated player object.

If they did, it would look something like this:

  • difficulty == MEDIUM (if you've got Ultimate Scavenger Mod installed) or EASY if you've not.

  • colour == undefined (it's set automatically but there isn't any way to work out what it is currently)

  • position == undefined (you could look for scavenger factories to get a rough location)

  • team == undefined (scavengers currently can't be allied with players)

  • type == PLAYER_DATA

  • isHuman == false

  • isAI == true (controlled by scavfact.js)

  • name == "Ultimate Scavenger Mod" (if USM installed) or "Scavengers"

The scavenger player ID is defined by scavengerPlayer. You can determine if scavengers are enabled via the scavengers global – note that this doesn't guarantee that the map maker added Scavengers to their map; if they didn't then regardless of scavengers being enabled there won't be any scavengers.

Notes

The player objects are based on the players in the current game. Depending on the type of the game, the source of the information is different:

  • Campaign:  no idea how it gets defined

  • Challenges: Players predefined in an ini file – see Challenge Games for more info.

  • Skirmish and MP: Players defined on the game set-up screen.

  • Tutorial:  no idea how it gets defined

  • Fast Play:  no idea how it gets defined

The playerData[] array and the player objects it contains are static during a game – the information is created prior to eventGameInit() being triggered. In campaign games, it is assumed (but not verified) that the information will be updated during eventStartLevel() as there could be different factions in a level.