(info) Most of the information here is for Warzone 3.1 and above.

rules.js

An instance of rules.js is run for each human player. It initialises all players and checks victory conditions.

 

Description

The rules.js script is responsible for Game Rules & SitRep (see that link for full details and modding guidelines).

Every human player in the game has rules.js associated with them.

The rules.js code must be exactly the same for all human players otherwise "2 + 2 = 5" desyncs will occur.

The rules.js is responsible for:

Players

As mentioned in Player Initialisation, the initialisation sequence is applied to all players (except Scavengers), not just the human player associated with the script.

When it comes to Victory Conditions, again all players are being checked but only to determine if the human player associated with the script has won or lost.

With the Mini Map and Design Mode checking, only the human player associated with the script is checked and updated.

In terms of Situation Reporting (SitRep), that will usually be performed in relation to the player the human is currently controlling – usually their own player, but if they are in debug mode they might have switched to a different player.

Here's a list of JS API globals and which players they relate to:

Global variableRelates to...Use for...
meThis will always be the human player in the context of rules.js

Mini Map and Design Mode

Victory Conditions

selectedPlayer

This will be the player the human is currently controlling.

Situation Reporting (SitRep)
scavengerPlayerThis is always the Scavenger faction (if enabled in the game)

Not applicable

Although you might use it to customise SitReps

maxPlayersIteration of all players in the game (excluding Scavengers)

Player Initialisation

Victory Conditions

See Enhanced SitRep Mod for an example of a heavily customised rules.js.

You can view the normal rules.js online

Contents

Assimilate:

File location

The "rules.js" that comes with Warzone can be found here:

mp.wz or multiplay

skirmish

rules.js

If you want a custom "rules.js" in your mod, it should be stored here:

<your mod>.wz or <your mod>

multiplay don't forget this!

skirmish

rules.js