Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

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[scavengerPlayer4] – players object for Scavenger factionplayer ID 4
  • Players[me] – players object associated with your script, equivalent to Players.me
  • Players[4scavengerPlayer] – players object for player ID 4
If the specified player does not exist, a ReferenceError will be thrown.
  • 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 doesndeveloper didn't have a scavenger faction 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 one game tick100ms.

1.0

allies

Array of Players Objects

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

Cached for one game tick1 second.

1.0
alliesAndMeArray of Players Objects

Same as .allies, but also includes me.

Cached for one game tick5 seconds.

 
aliveArray of Players Objects

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

Cached for one game tick100ms.

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 one game tick10 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.

Code Block
themeRDark
languagejavascript
titleAlways use .forEach() to iterate!
linenumberstrue
// 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
});
Div
classbox
Availability
Status
colourGreen
titleStable

Requires:

Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

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
Div
classbox

Players API

Topics:

Child pages (Children Display)
alltrue
depthall
pagePlayers API
excerpttrue