This AI is still in early stages of development.
Players Objects
The objects returned by the Players API are enhanced versions of Player objects...
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 HARD, ambiguous human players will have a difficulty of MEDIUM. | 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...
Comparison operators -- use with care
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:
Switch statement pattern
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:
Focus on what is true...
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.