This AI is still in early stages of development.
Players Objects
- Aubergine
Properties
Property | Settable | Type | Notes | API Version |
---|---|---|---|---|
id | Number | The id of the player. Note: For the scavenger player, their id will be >= maxPlayers (see scavengerPlayer for more info) | 0.1 | |
type | Constant | Note: The constant is backported by the Players API for Warzone 3.1 Beta 10 and earlier, so it will always be available regardless of Warzone version. | 0.1 | |
name | String | What is the player's name?
| 0.1 | |
isAI | Boolean Undefined | Is the player an AI?
| 0.1 | |
isScavenger | Boolean | Is the player the Scavenger Faction faction?
| 0.1 | |
isHuman | Boolean Undefined | Is the player human?
| 0.1 | |
isHost | Boolean | Is the player the game host?
| 0.1 | |
isVacant | Boolean | Is the player slot vacant?
A player is considered vacant if they are not alive when the Players API initialises (either at the start of a new game, or when loading a saved game). | 0.1 | |
difficulty | Constant | What Difficulty Level is the player? Note: Confirmed human players will have a difficulty of | 0.1 | |
colour | Object | An object describing the colour associated with the player – it has two properties:
The Scavenger faction has a custom colour defined:
See Colour Palette for possible values of each property. You can use _(player.colour.name) to localise the colour name. | 0.1 | |
team | Object | An object describing the team the player is in – it has two properties:
The Scavenger faction has a custom team defined:
The team is always specified, regardless of alliancesType mode:
Note: Maps can specify defaults for teams, see <mapname>.ini for details. | 0.1 | |
isAlly | 3.1 3.2+ | Boolean | Is the player an ally of the script player (me)?
On Warzone 3.2 and above, you can set this value, for example: | 1.0 |
isEnemy | 3.1 3.2+ | Boolean | Is the player an enemy of the script player (me)?
On Warzone 3.2 and above, you can set this value, for example: | 1.0 |
isAlive | Boolean | Is the player "Alive" according to game rules?
| 0.1 | |
position | Number Undefined | What map position did the player start in?
| 0.1 | |
isSelected | Boolean | Has the localhost human player selected this player?
For more information, see selectedPlayer. | 0.1 |
Where do the properties get defined?
Most of the properties are defined when a new game is started:
- Multiplayer and skirmish games: The game set-up screen
- Challenge Games: The .ini file associated with the challenge, and optionally some further customisation via the game set-up screen
- Campaign: <not sure!>
- Tutorial: <not sure!>
- Fast Play: <not sure!>
Other properties, such as .isAlly, .isAlive and .isSelected, can change during the game. The values of such properties will update automatically to reflect the current game state.
Working with .isAI
and .isHuman
properties
All properties listed above are always defined, even if their value has been defined as undefined
. An undefined
value will only occur in Warzone 3.1 on the isAI
and isHuman
properties if the Players API isn't able to disambiguate whether a player is human or AI.
In JavaScript, undefined
typecasts to Boolean false
so bear this in mind when working with properties that might be defined as being undefined
. You'll need to use the strict equality operators (===
and !==
) to avoid confusion between false
and undefined...
Players.forEach(function(player, id) { // Using !, == or != is unreliable // For example, we can't be certain a non-human player is an AI... if (!player.isHuman || player.isHuman == false || player.isHuman != true) { // They might still be human! // undefined == false } // So use strict equality checks instead... if (player.isHuman === false) { // They are definitely not human // undefined !== false } });
Switch statements automatically use strict equality, so you can do something like this:
Players.forEach(function(player, id) { switch (player.isHuman) { case false: { // they are definitely not human break; } case true: { // they are definitely human break; } case undefined: { // Could be human or AI // Players API wasn't able to disambiguate break; } } });
But its probably better to do something like this:
Players.forEach(function(player, id) { if (player.isHuman) { // They are definitely human } else if (player.isAI) { // They are definitely AI } else { // Could be human or AI // Players API was unable to disambiguate } });
Working with .colour
and .team
properties
In addition to the .id
and .name
properties of the .colour and .team objects, they also have two methods:
.valueOf()
– returns the value of the .id property.toString()
– returns the value of the .name property
As such, you can use shortcuts like this:
Players.forEach(function(player, id) { console("Colour for player #"+id+" is: "+player.colour); });
In the example above, Javascript will typecast player.colour to a string using its toString() method, thus returning the colour name.
Contents
Jump to:
See also
Native JS API features:
- playerData[] – an array of traditional player objects
- Player object – traditional player object definition
- me – the player id of the player your script is associated with
- selectedPlayer – the player the localhost human is currently looking at (can be changed via Debug Menu)
- difficulty – difficulty level associated with your script
- startPositions[] – array of player starting positions (excluding scavengers)
Players API
Topics:
- isPlayerAlive() — A global function that performs a basic, un-cached check to determine if a player is alive.
- eventTeamRevived() — A global event triggered when a team is revived (one or more of it's players resurrected).
- eventPlayerDefeated() — A global event triggered when a player is defeated.
- eventPlayerRevived() — A global event triggered when a player is revived (brought back to life).
- Modding Players API — The Players API supports modding...
- isSpectator() — A global function that performs a basic, un-cached check to determine if a player is a spectator based on presence of a Satellite Uplink at the start of the game.
- Players[] — Main interface to Players API and an array of all players in the game, including Scavengers.
- Players.alliesAndMe[] — Returns an array of players objects for living allied players, including me.
- Players.alive[] — Returns an array of players objects for living players.
- Players.allies[] — Returns an array of players objects for living allied players.
- Players.refresh() — Rebuilds all Players Objects, use with care!
- Players.dead[] — Returns an array of players objects for dead players.
- Players.scavenger — Returns the players object associated with the Scavenger faction, even if Scavengers are disabled.
- Players.me — Returns the player object associated with your script.
- Players.enemies[] — Returns an array of players objects for living enemy players.
- Players.mod() — Extend the Players API and Players Objects with your own features...
- Players Objects — The objects returned by the Players API are enhanced versions of Player objects...
- eventTeamDefeated() — A global event triggered when a team is defeated (all it's players defeated).