Versions Compared

Key

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

Overview

Excerpt

Returns an array of all enemy player IDs, including scavengers, using caching for extra performance.

Availability

Warzone 3.1 Beta 1 and above.

...

 

Code

Code Block
theme

...

RDark
languagejavascript
linenumberstrue
const ENEMY_ID_LIST_TTL = 5000; // cache TTL (time to live) for getEnemyPlayerIDs() function
 
// getEnemyPlayerIDs() will return an array of enemy player IDs
var getEnemyPlayerIDs = (function() {
  var getIDs = function() {
    var list = (scavengers) ? [scavengerPlayer] : [];
    var player = maxPlayers;
    while (-1<--player) if (!allianceExistsBetween(me,player)) list.push(player);
    return list;
  }
  var TTL = gameTime + ENEMY_ID_LIST_TTL;
  var cache = getIDs();
  return function() {
    if (alliancesType == ALLIANCES && TTL < gameTime) { // refresh cache
      cache = getIDs();
      TTL = gameTime + ENEMY_ID_LIST_TTL;
    }
    return cache;
  }
})();

Example

Code Block
theme

...

RDark
languagejavascript
linenumberstrue
// build a list of all enemy defences
var enemies = getEnemyPlayerIDs();
var defences = [];
enemies.forEach(function(enemy) {
  defences = defences.concat(enumStruct(enemy,DEFENCE));
});
Div
classbox

Availability

Requires:

  • Warzone 3.2 and above.

Image Added Backport to earlier versions with scavengerPlayer.js version 0.3 or above.

Div
classbox

See also

Related articles:

...

  •  – determines if there is an alliance between two players
  • gameTime – the current game time in milliseconds
  • maxPlayers – the maximum number of players for the current map
  • me

...