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

Players[]

Main interface to Players API and an array of all players in the game, including Scavengers.

 

Properties

(warning) Always use .forEach() method to iterate arrays retuned by the Players API (see Examples section).

Where applicable, caching is applied for a single game tick to minimise code execution. For more information on caching and "game ticks" see Cache API.

The .enemies, .allies, .living and .dead arrays use sequential indexes and not player ids. Use the .id property of the players object instead (see Examples section).

PropertyTypeNotesAPI Version
<playerID>Players Object

Numeric player ID references return the object associated with the player.

Examples:

  • Players[4] – players object for player ID 4
  • Players[me] – players object associated with your script, equivalent to Players.me
  • Players[scavengerPlayer] – players object for Scavenger player (not recommended)

Pay particular attention to scavengerPlayer which can have a value of -1 if scavengers are not present on the map! If you want the players object associated with scavengers, always use Players.scavenger (see below).

If the specified player does not exist, a ReferenceError will be thrown.

1.0
scavengerPlayers Object

The players object associated with scavenger faction, even if scavenger faction is not present.

You can check Players.scavenger.isAlive to see if they are roaming the map, which is more concise and reliable than looking at the JS API scavengers and scavengerPlayer globals.

For example, scavengers might be enabled on the map, but if the map developer didn't add Scavengers to their map there won't be any scavengers!

(warning) Scavengers don't have a start position so:

Player.scavenger.position == undefined

1.0
enemiesArray of Players Objects

An array of objects for all living enemies, including scavengers (if applicable), excluding spectators and vacant slots.

Cached for 100ms.

1.0

allies

Array of Players Objects

An array of objects for all living allies, excluding me, spectators and vacant slots.

Cached for 1 second.

1.0
alliesAndMeArray of Players Objects

Same as .allies, but also includes me.

Cached for 5 seconds.

 
aliveArray of Players Objects

An array of objects for all living players, including scavengers (if living), excluding spectators and vacant slots.

Cached for 100ms.

1.0
deadArray of Players Objects

An array of objects for all defeated players, including scavengers (if defeated), excluding spectators and vacant slots.

Cached for 10 seconds.

1.0
mePlayers Object

The players object associated with your script.

You can check Players.me.isAlive to see if you are still alive (tongue)

1.0
lengthNumber

(minus) Do not use or small furry animals will die painful deaths.

1.0

Examples

When iterating over arrays of player objects, including the main Players[] array, always use Javascript's .forEach() method as it deals with gaps in the array which can be caused by scavengerPlayer.

Always use .forEach() to iterate!
// list of all players
Players.forEach(function(player) {
  // player == players object associated with player
  // player.id == player id
});
 
// pre-filtered list of living enemies
Players.enemies.forEach(function(enemy) {
  // enemy == players object associated with the player
  // enemy.id == player id
});
Availability STABLE

Requires:

Contents

Jump to:

See also

Related articles:

  • me – the ID of the player associated with your script
  • playerData[] – the native JS API player data array (not altered by Players API)
  • Player object – the native JS API player object definition (not altered by Players API)
  • selectedPlayer – the player the local host human is currently playing as (they can change it via the Debug Menu)
  • scavengerPlayer – the ID of the Scavengers faction

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).

Â