SetCommand

Category: Objects / Commands
Since engine version: 4.6.5.0 CP (extended in 4.9.1.0 GWE)

Description

Gives a command to an object. The object will try to complete the command using the internal artificial intelligence (including pathfinding).

Syntax

bool SetCommand (object pObj, string szCommand, object pTarget, int iX, int iY, object pTarget2, any Data, int iRetries);

Parameters

pObj:
Object for which the command is given.
szCommand:
Command name (as string). See the table below
pTarget:
[opt] target object for the command
iX:
[opt] X target coordinate
iY:
[opt] Y target coordinate
pTarget2:
[opt] secondary target object
Data:
[opt] additional data for the command
iRetries:
[opt] Number of retries if the command fails, until the command fails completely.

Remark

The following commands are defined:
szCommand pTarget iX,iY pTarget2 iData Description
Acquire Null 0,0 Ignore container Object type (id) Type of object to be acquired. May be bought at the home base if necessary. Material contained in the specified container (Target2) is to be ignored in the search.
Activate Target object Activate the target object (exit from its container).
Activate Null 0,0 Target object Open the Get menu for the contents of the target object.
Activate Null Number,0 Target object Object type (id) Activate n objects of the specified type in the target object.
Attack Target object Attack the target object.
Build Target object Build the target object and supply it with energy when done.
Buy Null 0,0 Null Object type (id) Buy an object of the specified type at the closest friendly home base.
Buy Basis Number,0 Null Object type (id) Buy n objects of the specified type at the home base.
Buy Basis Open the Buy menu for the specified home base.
Call Object Par(1),Par(2) Par(3) Function (string) Call Function in the object script. Par(0) will be the calling object. If the command fails because underlaying commands have failed, the function FunctionFailed is called instead.
Chop Target object Fell the target object object (tree).
Construct Open the Construction menu.
Construct Null 0,0 Null Object type (id) Create a construction site at the closest possible position.
Construct Null Target position Null Object type (id) Create a construction site at the target position and start building.
Construct Target object Target position [opt] Null Object type (id) Help the target object with the construction (help building as soon as the site is created).
Dig Null Target position Dig towards the target position.
Drop Immediately drop the first object in the inventory.
Drop Null Target position Drop the first object in the inventory at the target position.
Drop Target object Target position Collect the target object and drop it at the target position.
Energy Target object Supply the target object with energy from the closest supplier.
Energy Target object 0,0 Supplier Supply the target object with energy from this supplier.
Enter Target object Enter the target object.
Exit Exit the current container.
Follow Target object Follow the target object (permanently).
Get Target object Collect the target object, dig it out if necessary.
Get Null Number,0 Target object Object type (id) Get the specified number of objects from the target object. From 4.9.8.3.
Grab Target object Offset Grab the target object at the specified offset to the object center.
Home Return to the closest friendly home base.
Jump Jump into the current direction.
Jump Null Target position Jump into the direction of the target position.
MoveTo Target object 0,0 Null No automatic adjustment? (bool) Move to the position of the target object. Set iData to true to avoid automatic adjustment of the target coordinates to landscape surface.
MoveTo Null Target position Null No automatic adjustment? (bool) Move to the target position. Set iData to true to avoid automatic adjustment of the target coordinates to landscape surface.
None Clear all current commands.
PushTo Target object Target position Push the target object to the target position.
PushTo Object 0,0 Target object Push the target object into the secondary target object.
Put Target object Put the first inventory object into the target object.
Put Target object Number,0 Put the specified number of inventory objects into the target object. From 4.9.8.3.
Put Target object 0,0 Object Collect the target object and put it into the secondary target object.
Put Target object 0,0 Null Object type (id) Put the inventory object of the specified type into the target object.
Put Target object Number,0 Null Object type (id) Put the specified number of inventory objects of the specified type into the target object. From 4.9.8.3.
Sell Null 0,0 Object2 Object type (id) Sell an object of the specified type at the closest home base. If Object2 is specified, this one will be sold first.
Sell Basis Number,0 Object2 Object type (id) Sell a number of objects of the specified type at the home base. If Object2 is specified, this one will be sold first.
Sell Basis Open Sell menu for the specified base object.
Throw Throw the first inventory item immediately.
Throw Null Target position Throw the first inventory item towards the target position.
Throw Target object Target position Collect the target object and throw it towards the target position.
UnGrab Let go of the object currently grabbed.
Wait Null 0,0 Null Frames Wait specified number of frames/ticks.

To open the get menu of an object, the data parameter must be true. Example: func ControlLeft(object byObj) { SetCommand(byObj, "Get", this, 0, 0, 0, true); }

Example

SetCommand(this, "Attack", FindObjectOwner(CLNK, 1, 0, 0, -1, -1), 0, 0, 0, 0, 10);
This script gives the clonk the order to attack the closest clonk of player 1. If the command fails (e.g. due to unsuccessful pathfinding), retry 10 times.
See also: AddCommand, AppendCommand, FinishCommand, GetCommand, PlayerObjectCommand
PeterW, November 2001