Comrades in Arms Discussion Board

Full Version: FHQ retreat
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Since we had some instances of "let's spread out and find the last guy sitting in some obscure corner somewhere" recently, I thought I'd release my retreat script that I usually use in such missions that require you to clear an area to prevent the situation described above.

What is it ?

The script simply receives an array of units and a marker name (optionally, a piece of code that is executed when the group reaches the marker). It will make all of these units flee in terror to the given waypoint where they are deleted (or the custom code executed for them.


How to use the script

The script only handles the fleeing part, not the decision when to flee.  See below for an example on how to check for possible fleeing.

The script is called with two to three arguments:

Code:
[_units, _markerName, _endCode] execvm "fhq_retreat.sqf";

_units is an array of group leaders that need to order their group to retreat. _markerName is the name of a marker ("markRetreate"). _endCode is optional and will default to deleting the group. This code is executed in the waypoint's onAct field, so this refers to the group reached the waypoint.

How do I let all enemy units flee if they are losing ?

Usually, I include a spawned thread in init.sqf that checks if the amount of enemy units has dropped below a certain thershold. Note that the example checks for all enemy units, you might need to adjust the code if you only want certain units/groups to flee, or different units under different conditions. The simple case, all units, is illustrated in this example:

Code:
init.sqf:

if (isServer) then {
    [] spawn {
       /* "Morale" watcher. Once the OPFOR drops under 10 % of it's original strength,
           * they will start to retreat. This prevents "hide and seek" with the last few
        * remaining enemy units
         */
 
        _numUnits = { side _x == east } count allUnits;
        _threshold = _numUnits / 10;
       
    while {_numUnits > _threshold} do {
    Â        sleep 2;
            _numUnits = { side _x == east } count allUnits;
        };
       
        {
            if (side _x == east) then {
                [[leader _x], "markRetreat"] execVM "library\retreat.sqf";
            }
        } forEach allGroups;
       
        if (FHQ_DebugMode == 1) then {
            hint "Enemy is retreating";
        };
    };   
};

Hope it's of some use to you all.
Download corrupted