Other great resources: Official JS API docs, Scripting Forum

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

Overview

Determine if more generators are required to power our oil derricks.

Availability

Warzone 3.1 Beta 1 and above.

Code

function generatorRequired(player) {
  if (player == null) player == me;
  if (player<0 || player>maxPlayers) return 0;
  var num_res  = enumStruct(player,RESOURCE_EXTRACTOR).length;
  var num_gens = enumStruct(player,POWER_GEN).length;
  var gens_needed = num_res/4;
  return Math.max(0,gens_needed-num_gens);
}

Example

// build generator if needed
if (generatorsRequired()) {
  // tell a free truck to build a power generator
}
 
// build all required generators
var i;
if (i=generatorsRequired()) while (-1<--i) {
  // tell a free truck to build a power generator
}
 
// how many more generators does player 3 need?
console("Player 3 needs "+generatorsRequired(3)+" more generators to power their resource extractors.");

See also

  • No labels