I have written a few scripts to do this. Basically I have a loop with a 5 to 10 second delay. I use the count command to count the number of units in a group. eg:
_Grp1units = count units <group1name>
etc for all the other groups. Then join them up if the number of units falls below a set level and if joining them does not exceed 12 units in the group.
This is an extract from a script that shows an example
_smallsize = 3
_largesize = 12
#Loop
~5
_countGrp6 = count units eg6Grp
_countGrp5 = count units eg5Grp
if not ((_countGrp6 >0) and ((_countGrp6 <= _smallsize) or (_countGrp5 <= _smallsize)) and ((_countGrp6 + _countGrp5) <= _largesize)) then {goto"Checkeg8Grp"}
units eg6Grp join eg5Grp
#Checkeg8Grp
.
.
.
Notes:
- once a group has joined another group count units <groupname> will return a zero immediately thereafter
- joining a group to a dead group is no problem. They just continue with the dead groups waypoints.
- there can be a delay of sometimes many seconds between a unit in a group being killed and this being reflected in the result of count units <groupname>. This is especially true when the group has been wiped out. It can take several minutes for count unit <groupname> to return zero. It also seems to depend on whether the dead units were seen by other members of the group.
Using a script like this you can then completely change the behaviour of the groups once the total number of units falls below some predetermined level.
Actually here is a full listing of a script I wrote that will:
- ensure any surviving crew from dead tanks join a local infantry unit.
- consolidate all the infantry groups in to one group as they shrink
- once they have shrunk to a very low total number, any surviving M2 machine gunner then abandons their post and join the infantry
- the infantry will eventually panic (set Base1Panic = true) and then any surviving tank crew will abandon the vehicle and join them. The level at which they panic is determined by whether any tank is still alive.
Base1Panic is a global variable used by a switch trigger to make the remaing soldiers run a long way away.
The following works, but I am about to make some further improvements to it:
; Base1Groupings. Consolidated Russian groups as they take casualties
; called by []exec"Base1Groupings.sqs"
_smallsize = 3
_panicsize = 4
_realpanicsize = 1
_largesize = 12
_Tank5Joined = false
_Tank6Joined = false
_NearPanic = false
#Loop
~5
if ((count units eg3Grp > 9) or (alive Tank5) or _Tank5Joined) then {goto"CheckTank6"}
[Tank5C,Tank5G,Tank5D] join eg3Grp
_Tank5Joined = true
#CheckTank6
if ((count units eg3Grp > 9) or (alive Tank6) or _Tank6Joined) then {goto"CheckJoin1and2"}
[Tank6C,Tank6G,Tank6D] join eg3Grp
_Tank6Joined = true
#CheckJoin1and2
_countGrp1 = count units eg1Grp
_countGrp2 = count units eg2Grp
if ((_countGrp1 < 1) or (_countGrp2 < 1) or ((_countGrp1 > _smallsize) and (_countGrp2 > _smallsize)) or ((_countGrp1 + _countGrp2) > _largesize)) then {goto"CheckJoinPatrol1and2"}
if (_countGrp1 < _countGrp2) then {units eg1Grp join eg2Grp} else {units eg2Grp join eg1Grp}
#CheckJoinPatrol1and2
_countPatrol1 = count units Patrol1Grp
_countPatrol2 = count units Patrol2Grp
if ((_countPatrol1 < 1) or (_countPatrol2 < 1) or ((_countPatrol1 > _smallsize) and (_countPatrol2 > _smallsize)) or ((_countPatrol1 + _countPatrol2) > _largesize)) then {goto"Checkeg1to3Grp"}
if (_countPatrol1 < _countPatrol2) then {units Patrol1Grp join Patrol2Grp} else {units Patrol2Grp join Patrol1Grp}
#Checkeg1to3Grp
_countGrp1 = count units eg1Grp
_countGrp3 = count units eg3Grp
if not ((_countGrp1 >0) and ((_countGrp1 <= _smallsize) or (_countGrp3 <= _smallsize)) and ((_countGrp1 + _countGrp3) <= _largesize)) then {goto"Checkeg2to3Grp"}
units eg1Grp join eg3Grp
#Checkeg2to3Grp
_countGrp2 = count units eg2Grp
_countGrp3 = count units eg3Grp
if not ((_countGrp2 >0) and ((_countGrp2 <= _smallsize) or (_countGrp3 <= _smallsize)) and ((_countGrp2 + _countGrp3) <= _largesize)) then {goto"CheckPatrol1to3Grp"}
units eg2Grp join eg3Grp
#CheckPatrol1to3Grp
_countPatrol1 = count units Patrol1Grp
_countGrp3 = count units eg3Grp
if not ((_countPatrol1 >0) and ((_countPatrol1 <= _smallsize) or (_countGrp3 <= _smallsize)) and ((_countPatrol1 + _countGrp3) <= _largesize)) then {goto"CheckPatrol2to3Grp"}
units Patrol1Grp join eg3Grp
#CheckPatrol2to3Grp
_countPatrol2 = count units Patrol2Grp
_countGrp3 = count units eg3Grp
if not ((_countPatrol2 >0) and ((_countPatrol2 <= _smallsize) or (_countGrp3 <= _smallsize)) and ((_countPatrol2 + _countGrp3) <= _largesize)) then {goto"CheckPanic"}
units Patrol2Grp join eg3Grp
#CheckPanic
_countGrp1 = count units eg1Grp
_countGrp2 = count units eg2Grp
_countGrp3 = count units eg3Grp
_countPatrol1 = count units Patrol1Grp
_countPatrol2 = count units Patrol2Grp
_countTotal = _countGrp1 + _countGrp2 + _countGrp3 + _countPatrol1 + _countPatrol2
if (_countTotal > _panicsize) then {GoTo"Loop"}
if _NearPanic then {goto"Skip"}
_NearPanic = true
unassignVehicle gunnerMG1
unassignVehicle gunnerMG2
unassignVehicle gunnerMG3
unassignVehicle gunnerMG4
if (alive gunnerMG1) then {[gunnerMG1] join eg3Grp}
if (alive gunnerMG2) then {[gunnerMG2] join eg3Grp}
if (alive gunnerMG3) then {[gunnerMG3] join eg3Grp}
if (alive gunnerMG4) then {[gunnerMG4] join eg3Grp}
[Tank5,TankLastStand,150] exec "UnitReturn.sqs"
[Tank6,TankLastStand,150] exec "UnitReturn.sqs"
#Skip
_countGrp3 = count units eg3Grp
_countTotal = _countGrp1 + _countGrp2 + _countGrp3 + _countPatrol1 + _countPatrol2
if (_countTotal <= _realpanicsize) then {goto"Panic"}
if ((_countTotal > _panicsize) or (alive Tank5) or (alive Tank6)) then {GoTo"Loop"}
#Panic
unassignVehicle Tank5C
unassignVehicle Tank5G
unassignVehicle Tank5D
unassignVehicle Tank6C
unassignVehicle Tank6G
unassignVehicle Tank6D
[Tank5C,Tank5G,Tank5D,Tank6C,Tank6G,Tank6D] join eg3Grp
Base1Panic = true
exit