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

syncRandom()

Generate a synchronised random integer...

 

Syntax

var returnValue = syncRandom(limit);

Parameters

ParameterTypeMandatoryDescriptionGame verison
limitString(tick)

The upper limit of the random number.

The number will be in the range: 0 ≤ <number> < limit.

3.2

Return value

ValueTypeDescriptionGame version
<number>Number

A random integer between 0 and limit-1.

3.2
<error>ErrorInvalid parameter3.2

Notes

Using this function you can generate a random number that will be the same on all network peers in the same game frame. This means you can perform pseudo-random actions and not cause a game desynch, so long as all peers run the same code in the same game frame.

If you use the function as the basis for performing some action (eg. adding a feature to the map) in a script that only runs on the game host machine, as would be the case for AIs and scavfact.js, a game desynch would likely occur.

If a desync occurs, the  warning will appear and people might get worried that cheating is taking place, however the game will continue to run.

As such, it's recommended to limit use of this function, and the type of actions you would use it for, to scripts such as rules.js or 'extra' scripts that are running on all network peers.

Example

Add randomly placed oil barrel every 20 seconds...
function placeOilDrum() {
	var x = syncRandom(mapWidth);
	var y = syncRandom(mapHeight);
	addFeature("OilDrum", x, y);
}
 
setTimer("placeOilDrum", 20000); // every 20 seconds
Availability 3.2+

Requires:

  • Warzone 3.2 and above
Contents

Jump to:

Â