Versions Compared

Key

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

Order a construction droid to build a new structure...

 

Syntax

Code Block
themeRDark
languagejavascript
linenumberstrue
orderDroidBuild(droid, order, structureID, x, y[, direction])

Parameters

ParameterTypeMandatoryNotesGame Version
droidDroid object(tick)The droid that will build the structure(s).3.1 Beta 1
orderConstant(tick)

Indicate the construction mode:

  • DORDER_BUILD – the droid should build a single new structure.
  • DORDER_LINEBUILD – the droid should build a row of structures from it's current location to the target location.

Note: Once construction has started, other droids can help with the building process by issuing DORDER_HELPBUILD via the orderDroidObj() function.

3.1 Beta 1
structureIDString(tick)

The ID of the structure you want built. You can find a list of structure ID's in structures.txt or structures.ini (depending on game version).

Note: You cannot use structure type constants, you have to specify the specific structure id.

3.1 Beta 1
xNumber(tick)

The x co-ordinate of the top-left corner of the construction site.

Note: Always find suitable co-ordinates by using pickStructLocation() first.

3.1 Beta 1
yNumber(tick)

The y co-ordinate of the top-left corner of the construction site.

Note: Always find suitable co-ordinates by using pickStructLocation() first.

3.1 Beta 1
directionNumber(error)

The direction, in degrees from North, in which the front of the building faces when built.

Default: 0 (North-facing)

It's recommended to use multiples of 90º for the direction, otherwise the structure could adversely affect pathfinding:

  • 0º = North
  • 90º = East
  • 180º = South
  • 270º = West
3.1.0

Return values

ValueTypeNotesGame Version
trueBooleanThe order was successful and the droid will build the structure.3.1 Beta 1
falseBooleanThere was a problem and the structure will not be built.3.1 Beta 1
<error>ErrorAn error occurred, for example invalid parameters.3.1 Beta 1

Notes

This function replaces the deprecated orderDroidStatsLoc() function.

A typical sequence for building a new structure is:

  • Check if the structure can be built (eg. has it been researched, have structure limits been reached, etc?)
  • Find a free construction droid to do the construction (use enumDroid() to get a list of available droids)
  • Find a suitable location for the structure (use pickStructLocation() – RTFM for important notes on how the function works)
  • Order an idle construction droid (truck or engineer) to start the construction at the selected location

Only construction droids (trucks and field engineers) of type DROID_CONSTRUCT can build structures.

Example

Code Block
themeRDark
languagejavascript
linenumberstrue
// define some constants if missing
if (typeof NORTH == "undefined") {
	const NORTH = 0;
	const EAST = 90;
	const SOUTH = 180;
	const WEST = 270;
}
 
function isIdle(droid) {
	var notIdle = [
		DORDER_BIULD,
		DORDER_HELPBUILD,
		DORDER_LINEBUILD,
		DORDER_DEMOLISH
	];
	return (notIdle.indexOf(droid.order) == -1);
}
 
function buildA(structure, near) {
	// can we build the structure?
	if (!isStructureAvailable(structure)) return false;
	// get list of construction droids
	var constructors = enumDroid(me, DROID_CONSTRUCT);
	// find free droid
	var freeDroid;
	constructors.some(function isFree(droid) {
		if (isIdle(droid)) {
			freeDroid = droid;
			return true;
		}
	});
	// if no free droids abort
	if (!freeDroid) return false;
	// find suitable location to build
	var pos = pickStructLocation(freeDroid, structure, near.x, near.y);
	// abort if no location found
	if (!pos) return false;
	// let's build!
	return orderDroidBuild(
		freeDroid,
		DORDER_BUILD,
		structure,
		pos.x,
		pos.y,
		NORTH
	);
}
 
// find where our HQ is
var nearMyHQ = enumStuct(me, HQ)[0]; // assuming we already have one
 
buildA("A0LightFactory", nearMyHQ); // build a factory near my HQ
Div
classbox
Availability
Status
colourGreen
titleStable

Requires:

  • Warzone 3.1 Beta 1 or above
  • The 'direction' parameter was added in Warzone 3.1.0
Div
classbox
Contents

Jump to:

Table of Contents
maxLevel5

Div
classbox

See also

Related articles:

Interesting game mods to be aware of:

  • Structures by Design – allows structures to be designed in a similar way to droids, which obviously has implications for orderDroidBuild()
  • Contingency Mod – adds a huge number of new structures to Warzone, which your script will need to be aware of if it's to build them.