Versions Compared
Key
- This line was added.
- This line was removed.
- Formatting was changed.
Excerpt |
---|
Order a construction droid to build a new structure... |
Warning |
---|
This article is in need of technical review – specifically it seems that in Warzone 3.1.x the function is not returning Please see comments at bottom of page for more info, and please add a comment about what it's actually returning. |
Syntax
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
orderDroidBuild(droid, order, structureID, x, y[, direction]) |
Parameters
Parameter | Type | Mandatory | Notes | Game Version |
---|---|---|---|---|
droid | Droid object | The droid that will build the structure(s). | 3.1 Beta 1 | |
order | Constant | Indicate the construction mode:
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 | |
structureID | String | 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 | |
x | Number | 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 | |
y | Number | 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 | |
direction | Number | 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:
| 3.1.0 |
Return values
Value | Type | Notes | Game Version |
---|---|---|---|
true | Boolean | The order was successful and the droid will build the structure. | 3.1 Beta 1 |
false | Boolean | There was a problem and the structure will not be built. | 3.1 Beta 1 |
<error> | Error | An 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 | ||||||
---|---|---|---|---|---|---|
| ||||||
// 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 | ||||||
---|---|---|---|---|---|---|
| ||||||
Availability
Requires:
|
Div | ||||
---|---|---|---|---|
| ||||
ContentsJump to:
|
Div | ||
---|---|---|
| ||
See alsoRelated articles:
Interesting game mods to be aware of:
|