Headless AI: the setInit function - Global-Conflicts-ArmA/Olsen-Framework-Arma-3 GitHub Wiki

The setInit function

In order to transfer special data and variables about the objects and units transferred to the HC we need to use the setInit function in the editor init box for the object, unit, or group we want to modify.

[this, "task", "stationary", "stance", "MIDDLE"] call PZAI_fnc_setInit;

The first parameter of the setInit function will always be this which will reference the modified item directly. Any subsequent parameters are grouped up in pairs: the first of the two will always be a string of the setting name, and the following parameter will be the value of that setting name. For example:

[
 this, // item referenced, in this case a unit group init
 "task", // task setting
 "stationary", // Value of the task setting
 "stance", // stance setting
 "MIDDLE" // Value of the stance setting
] call PZAI_fnc_setInit;

Having it broken up via setting names and setting values allows mission makers to simply input the values they want without having to worry about parameter order. All that is needed is the right setting name and an appropriate value.

Setting Item Inits

Setting an init on an item will run the code after the item spawns in. Normally an init block will have the magic variable this that will refer to the item, but this is not accessible in the setInit init value. Instead, we use _this. Init blocks are set with a code value { /*CODE*/ }

[this, "init", { hint format ["spawned %1 object and ran the init!", _this] }] call PZAI_fnc_setInit;

Setting group tasks

Tasks are set by group init akin to other setInit function parameters. Please see tasks

Setting group IDs

Group IDs visible in the spectator menu are set via the groupID setting with a string value.

[this, "task", "stationary", "groupID", "Alpha 1-1"] call PZAI_fnc_setInit;

Setting item names / variables

Because the item is recreated on the headless client machine, it needs to be reassigned a variable name if you wish to use one. The setting for variable names is varName and the input value is a string of the varname desired. If two items are spawned with the same desired varName, the latter item will receive an underscore and a number suffix. eg ("Tank", "Tank_1")

[this, "varName", "hostage1"] call PZAI_fnc_setInit;

Setting Olsen gearscript values

The olsen gearscript can be called by the gear setting with the value being a string of the type, akin to the regular olsen gearscript parameters for type.

[this, "gear", "1989VDV_RF"] call PZAI_fnc_setInit;

Setting stances

The stance setting can be used if a mission maker wants to force the stance for an entire group, or to specify a stance in the unit init without setting it visually in the editor. In the absence of a unit stance value, it will use the 3den editor dialog stance value. Keep in mind "AUTO" value is different from "UP"/standing in the editor. Unit stances will take precedent over a group stance value, so you can have a group set to "stance", "MIDDLE" while a unit can have "stance", "UP" which will make the unit with the stance value standing while the rest of the units in the group will be kneeling.

[this, "stance", "MIDDLE"] call PZAI_fnc_setInit;

Setting retreat locations and thresholds

AI groups can be configured to retreat to a specified location when their casualties exceed a certian threshold. Use the retreatPos parameter for the location to which they should retreat, and the retreatThreshold parameter (number between 0 and 1, 0.5 being 50% for example) to determine how much of the group needs to be remaining in order to retreat. In the following example, the AI group will do a bounding retreat to a game logic with the variable name retreat_position_game_logic once under 60% of their force remains:

[this, "retreatPos", getPos retreat_position_game_logic, "retreatThreshold", 0.6] call PZAI_fnc_SetInit;