ws_fnc_createGarrison, similarly to the older ws_fnc_taskDefend, aims to provide a convenient and perfomance-friendly solution to one of the more annoying tasks in editing: fortifying towns and buildings. It creates the units directly inside the building and sets them up to engage independently. That way you can fill up an entire block of buildings (or even town if you feel ambitious) at once and don't have to do it on a building-per-building basis.
Usage
To use the function, simply call it with the desired parameters, making sure that it only runs on the server (or headless client if you are using one). I have a preferred and streamlined way of implementing it in my missions which I'll detail below, under Implementation.
Parameters
[center,radius,side,units,threshold,classes] call ws_fnc_createGarrison
Red are mandatory, blue are optional.
1. center - Indicates the center around which units are placed. Can be an object or a marker.
2. radius - Indicates the radius around the center in which units to place. Needs to cover at least one building!
3. side - Which side the units will belong to (east, west, independent, civilian).
4. units - number of units that will be placed. Default value is (# of buildings in radius / 4). Tip: Keep this number between 6 and 20.
5. threshold - percentage of building positions that can max be occupied in any building. Default value can be set at top of fn_createGarrison.sqf, below classes.
6. classes - an array from which the unit classes will be picked. If left out they default classes defined in fn_createGarrison.sqf are used (lines 26 - 32).
Implementation Example
In-Editor
1. In the editor, place a Gamelogic > Location in the center of the group of buildings you want occupied, which one you pick does not matter. Name it garrisonLogic.
2. Double-click on the newly placed Logic and put the following into it's init field:
Code: Select all
this setVariable ["ws_garrisonSettings",[]]
Screenshot TBA
3. Modify the inner array to your liking, for example if we wanted to create a CSAT garrison of 1-5 units within 50m it would be:
Code: Select all
this setVariable ["ws_garrisonSettings",[this,50,east,(round random 5)]]
Tips:
* Use the placement radius for the logic to determine which radius createGarrison will cover. Screenshot tba
4. Select the gamelogic you just created and copy it once for every town/group of buildings you need occupied. They should all be numbered garrisonLogic_1,garrisonLogic_2,....,garrisonLogic_n etc. Make sure to only copy the original garrisonLogic, otherwise the numbering will be off. Then modify the setVariable values to your liking.
Script-side
1. In your mission root-folder (where the init.sqf is), create a new file named ws_garrisonControl.sqf. Open it and put at it's top:
Code: Select all
if !(isServer) exitWith {};
2. Below that, add the line:
Code: Select all
_garrisons = [garrisonLogic] call ws_fnc_collectObjectsNum;
Code: Select all
_garrisons = [garrisonLogic,garrisonLogic_1,garrisonLogic_2,garrisonLogic_3,...,garrisonLogic_n]
3. Below the part you just added, paste this section:
Code: Select all
_units = [];
{
_units append ((_x getVariable "ws_garrisonSettings") call ws_fnc_createGarrison);
} forEach _garrisons;
_units execVM "f\setAISkill\f_setAISkill.sqf";
The last line will make sure that the spawned AI are adjusted by the F3 AI Skill selector.
You can now close and save this file.
4. Next, open init.sqf in your root directy and at the very bottom add
Code: Select all
[] execVM "ws_garrisonControl.sqf";
Debugging
Enabling debug mode
Simply put
Code: Select all
ws_debug = true;