(info) Other great resources: Official JS API docs, Scripting Forum

Contents

Quick Reference

Links to all the main JS API features (see also: Index or Contents)...

How To's

Compatibility Matrix

A record of all changes to the Javascript API features since it's initial release...

  • Events 3.1Matrix of events availability in Warzone 3.1...
  • Change logA summary of the main changes in the JS API from Warzone 3.1 Beta 1 to present day...
  • Functions 3.1Matrix of functions availability in Warzone 3.1...
  • Globals 3.1Matrix of globals availability in Warzone 3.1...
  • Constants 3.1Matrix of constant availability in Warzone 3.1...

Atmosphere

  • setSunPosition()Set the position of the Sun, which affects shadows on the map...
  • setSunIntensity()Change the lighting effects applied to game objects...
  • setWeather()Sets the weather effect applied to the whole map.
    • WEATHER_SNOWAdds a snow effect to the entire map, disabling any previous weather setting in the process.
    • WEATHER_CLEARClears any active weather effect.
    • WEATHER_RAINAdds a rain effect to the entire map, disabling any previous weather setting in the process.
  • setSky()Set the sky image, rotation speed and scale...

Components & Templates

Droids in Warzone are predominantly built from component parts, with component configurations stored as templates...

Constants

The JS API defines a number of constants which are used in Functions and Objects.

Droids

A wide range of features for working with droids (tanks, etc)...

Events & Timers

Events are the driving force behind your scripts...

Features

  • enumFeature()Returns an array of feature objects (like trees and boulders), optionally filtered to a specific looking player...
  • addFeature()Add a feature object (tree, log cabin, etc.) to the map...

Game Configuration

There's two parts to game settings - the game set-up, and player initialisation...

  • hackNetOff()Used to disable network updates during Player Initialisation...
  • hackNetOn()
  • applyLimitSet()Merges limits set by your script with limits set on the Structure Limits Screen...
  • getBurnDamage()Get the base damage applied per second to a player's burning objects...
  • setBurnDamage()Define the base damage applied per second to burning objects...
  • getBurnTime()Define how long units burn for when they catch fire...
  • setBurnTime()Define how long units burn for when they catch fire...
  • getDroidLimit()Get the current production limit for a specific droid type or the total number of droids a player can produce...
  • setDroidLimit()Define the maximum number of droids a player can create.
  • getExperienceModifier()Set the rate at which droids gain experience...
  • setExperienceModifier()Set the rate at which droids gain experience...
  • getStructureLimit()Determine the structure limits for a given type of structure...
  • setStructureLimits()Set limits on how many structures of a specific type a player can build.
  • Player InitialisationInitialise player structures, components, technologies and bases before the game starts...

Groups

Organise game objects in to groups for easier iteration...

Labels

Functions for labelling objects...

  • getLabel()Get the label, if any, associated with a game object...
  • addLabel()Associate a game or map object with a label...
  • removeLabel()Remove a label from the game...
  • resetArea()Reset a labelled area trigger...
  • enumLabels()Returns a list of all currently defined labels...

Map

  • distBetweenTwoPoints()Returns the straight-line distance between two points on the map...
  • enumGateways()
  • enumRange()List all objects within a specified range of a position on the map...
  • safeDest()Determine if, based on the script player's current knowledge of the map, whether a specific map location is safe or not.
  • derrickPositions[]An array of oil resources on the map, filtered to those that don't have derricks built on them at the start of the game.
  • enumBlips()Get positions of non-transient radar blips as seen by your radar detectors...
  • hackMarkTiles()Highlight map tiles with a pulsing red glow...
  • setNoGoArea()
  • tilesetTypeA global which states the major tileset used by the current map...
  • propulsionCanReach()Find out if a specific propulsion can travel between two points on the map...
  • startPositions[]An array of player starting positions on the map.
  • getThreatsNear(x,y[,range])Returns an array of dangerous enemy objects near a specific location on the map.
  • mapHeightDefines the map height, in tiles, as an integer.
  • mapNameA string containing the name of the map being played.
  • setScrollParams()
  • mapWidthDefines the map width, in tiles, as an integer.
  • enumArea()

Missions / Campaign

Players & Alliances

Player data and scripts, alliances/teams, and player interactions...

  • Players
    • scavengerPlayerDefines the player ID for the scavenger faction on the map.
    • playerData[]An array of Player objects describing each human/AI player slot on the current map regardless of whether those slots have been assigned players for the current game.
    • difficultyA constant representing the difficulty level selected for your script.
      • EASYAct like a punching bag...
      • MEDIUMAct like a regular skirmish player...
      • HARDAct like a seasoned MP player...
      • INSANEBe evil, cheat if you have to...
    • selectedPlayerIndicates which player is currently being played/viewed by the human on the current machine.
    • scavengersIndicates whether scavengers are enabled in this game.
    • maxPlayersDefines the maximum number of human/AI player slots on the current map, regardless of whether those slots are filled in the current game.
    • meStores the player ID your script is associated with...
    • isMultiplayerDetermine if the game is an online multiplayer game...
  • Alliance
  • Interactions
    • donateObject()Transfer an object to another player...
    • chat()Send an in-game message to a specific player, your alliance or everyone.
    • donatePower()Transfer some power to another player...
    • removeBeacon()Send a beacon to a specific player or allies...
    • addBeacon()Send a beacon to a specific player or allies...

Objects

The JS API has several object types that you'll encounter regularly when developing scripts...

  • .typeDefines the type of a game object – the .type of Objects.
  • getObject()Three ways to retrieve a specific object...
    • label()Retrieve the object associated with a label...
    • hackGetObj()Retrieve a game object based on it's type, player and ID...
      • objFromId()Retrieve a game object based on it's ID...
        • droidFromId()Get an object based on it's object ID and player ID...
  • removeObject()Remove a game object from the map...
    • removeStruct()Immediately remove a structure object from the map...
  • Data objectsThese objects relate to players and game config ("stats")...
    • Weapon ObjectAn object describing a weapon turret...
    • Group ObjectA group of Game objects...
    • Template ObjectAn object describing a droid template...
    • Research objectDescribes various attributes related to a specific researchable technology.
    • Player objectSpecifies useful static information about a specific player in the game.
  • Game objectsThe common properties for all objects that appear on the map such as droids, features and structures.
    • Structure objectDescribes a structure (something a truck can build) on the map.
    • Droid objectDroids are mobile game objects (items on the map), and have a huge number of properties and related API features...
      • .droidTypeDefines the type of a droid – the .droidType of a Droid object.
        • DROID_ANYUsed to bypass droid type filtering in functions that list or count droids.
        • DROID_TRANSPORTERA cyborg transporter (or possibly a super transporter in Warzone 3.1 Beta 4 and earlier), capable of airlifting droids to some other location on the map.
        • DROID_REPAIRA droid that has a repair turret, capable of repairing other droids.
        • DROID_PERSONA droid that uses "legs" propulsion, for example a civilian or a scavenger machinegunner.
        • DROID_SUPERTRANSPORTERA heavy transport unit, capable of airlifting any type of droid (including VTOLs) to some other location on the map...
        • DROID_CONSTRUCTA construction truck or a cyborg engineer.
        • DROID_SENSOR
        • DROID_ECMA droid that has an Electronic Counter Measures (radar jammer) turret.
        • DROID_COMMANDA commander unit, to which other units can be assigned.
        • DROID_CYBORGA cyborg warrior capable of attacking the enemy.
        • DROID_WEAPONA droid capable of attacking other droids.
      • .orderDefines the order which a droid is currently performing (the .order property of a Droid object) or must perform (orderDroid*() functions).
        • DORDER_HELPBUILDInstruct a construction droid to help with an existing structure building site.
        • DORDER_RECOVEROrder a droid to recover a collectible item such as an oil barrel or artefact (crate).
        • DORDER_DISEMBARK
        • DORDER_GUARDInstruct a droid to guard a structure.
        • DORDER_TEMP_HOLDUse DORDER_HOLD instead of DORDER_TEMP_HOLD.
        • DORDER_RTRInstruct a land droid to go to a repair facility for repairs.
        • DORDER_EMBARK
        • DORDER_UNUSEDAs it's name suggests, this constant is not used.
        • DORDER_CIRCLEInstruct a VTOL to circle around a specific location.
        • DORDER_HOLDInstruct the droid to hold its current position until instructed otherwise.
        • DORDER_SCOUTInstruct a droid to "scout" to a new location.
        • DORDER_OBSERVEInstruct a sensor droid to observe (target) a Droid object, Structure object, or even a Feature object.
        • DORDER_RTR_SPECIFIEDInstruct a land droid to go to a specific repair facility for repairs.
        • DORDER_DESTRUCTInstruct a droid to self-destruct!
        • DORDER_RETREATInstruct a droid to retreat to a pre-defined retreat point. Does not retreat to HQ! Read docs before using!
        • DORDER_NONEIndicates that a droid is currently idle.
        • DORDER_BUILDInstruct a construction droid to build a Structure object at a specific location.
        • DORDER_ATTACKInstruct a droid to attack something.
        • DORDER_LINEBUILDIndicates that a construction droid is building a line of structures (eg. a long wall).
        • DORDER_REARMInstruct a VTOL to return to a rearming pad for repairs and rearming.
        • DORDER_RECYCLERecycle a droid...
        • DORDER_FIRESUPPORTAssign a attacker droid to a sensor droid so that it can attack whatever the sensor droid targets.
        • DORDER_RTBInstruct a droid to return to your base.
        • DORDER_MOVEInstruct a droid to move to a new location.
        • DORDER_COMMANDERSUPPORTAssign an attacker droid to a commander droid so that it will attack whatever the commander droid targets.
        • DORDER_STOPInstruct a droid to stop what it's doing.
        • DORDER_DEMOLISHInstruct a construction droid to demolish one of your structures.
        • DORDER_PATROLInstruct a droid to patrol between it's current location and a specified location, attacking any enemies it detects along the way.
        • DORDER_DROIDREPAIRInstruct a repair droid to repair a damaged Droid object.
        • DORDER_REPAIRInstruct a construction droid to repair a damaged Structure object.
      • .actionDefines the current action a Droid object is taking to fulfil its current .order.
    • Feature objectFeature objects describe inanimate game objects such as oil barrels and resources, artefacts, log cabins and skyscrapers, trees, etc.
  • Location objects
    • Position objectDefines a position on the map via its x,y co-ordinates.
    • Area objectSpecifies the top-left and bottom-right co-ordinates of an area of the map.

Power

  • setPowerModifier()
  • queuedPower()Find out if your power reserves have gone negative, indicating that you have one or more tasks stalled due to lack of power...
  • extraPowerTime()Increase the player's power reserve as if they'd played the game for an additional number of seconds...
  • powerTypeDefines the rate at which oil derricks produce power, prior to applying any power upgrades.
  • playerPower()Find out how much available power a specific player has...
  • setPower()Set the power reserves for a player...

Research & Technology

Script Environment

This section contains general information about the Javascript environment used by Warzone.

  • scriptPathThe path to the main script loaded in to a particular scripting environment...
  • Native JS FeaturesA summary of the native Javascript features of the Warzone JS environment.
  • scriptNameThe filename of the main script loaded in to a particular scripting environment...
  • dump()Dumps text to a log file...
  • hackAssert()Assert a value and throw a game assert and JS error if it's falsey...
  • Scopes & ClosuresThis article explains some important javascript concepts...
  • syncRandom()Generate a synchronised random integer...
  • debug()Outputs text to the terminal or log file depending on operating system.
  • Timers
    • queue()Invoke a function at some point in the future...
    • setTimer()Allows you to trigger a function at some point in the future.
    • removeTimer()Allows you to cancel all queued and timed calls associated with a specific function...
  • WZscript (.vlo and .slo) to Javascript (.js)This guide is designed to help developers who are converting their old WZScripts to the new Javascript API...
  • Error HandlingMost JS API functions and Javascript operations will "thow" an error if you use them incorrectly...
  • Common MistakesA summary of common issues you *will* run in to whilst developing against the JS API...
  • include()Include library scripts in to your main script...
  • Javascript DebuggerThe JS debugger allows you to inspect scripts and labels...
  • Environment SequencesDetails of the main environment sequences that occur in Warzone...
  • Code sandboxingA brief tutorial showing how to sandbox a chunk of code, primarily to avoid it's variables leaking on to the global scope.
  • versionA string representing the game version being played.
  • Player ScriptsEach player in the game has a specific script associated with them...
  • IntroductionWarzone2100 contains a scripting language for implementing AIs, campaigns and some of the game rules...
  • Save / Load Cycle
    • Saved game filesHow do I work out what data is getting stored in save game files? Will it show me why my script is broken?

Structures

User Interface

  • _() localiseUsed for string localisation (translation in to other languages)...
  • console()Outputs text to the player console associated with the script.
  • enumSelected()Get a list of all objects selected by the the game host...
  • Mini Map and Design ModeEnable or disable the mini map and design mode depending on the presence of a HQ.
    • setDesign()Enable or disable the design tool...
    • setMiniMap()Display or hide the localhost human player's radar mini-map...
  • playSound()Plays a sound, optionally displaying a beacon on the map and mini map.
  • audioAlert(filename,pos,despam)Throttled alternative for playSound().
  • setTutorialMode()Toggles "tutorial mode" in a single-player game...
  • addReticuleButton()Enable a reticule button...
  • removeReticuleButton()Disable a reticule button...
  • Reticule buttonsThese constants are used by addReticuleButton() and removeReticuleButton().
    • BUILDUsed to show or hide the "Build" (hammer) reticule button.
    • CANCELUsed to show or hide the "Cancel" (central) reticule button.
    • COMMANDUsed to show or hide the "Command" (star) reticule button.
    • DESIGNUsed to show or hide the "Design" (blue components) reticule button.
    • INTELMAPUsed to show or hide the "Intelligence" (earth map) reticule button.
    • MANUFACTUREUsed to show or hide the "Maufacture" (factory) reticule button.
    • OPTIONSThis constant is deprecated, use COMMAND instead.
    • RESEARCHUsed to show or hide the "Research" (green circuit board) reticule button.
  • Camera

To-Do List

Just a dumping ground for things I spot in the forums that need adding to this guide...

Useful Links

There's lots of useful information elsewhere on the intertubes...