OK here is the code for a reasonably generic combining of infantry groups. The names of some of the variables reflect the particular mission I wrote it for. I expect the code can be tightened up significantly but at least what follows seems to work.
In the init.sqs file put:
CheckInProgress = false
You also need to give each of the infantry groups a name. You should then create an array of all the names of the groups you want to consolidate together. This is an extract from my mission:
Base2Groups = [eg12Grp,eg6Grp,eg8Grp,eg14Grp,eg15Grp,eg13Grp,eg5Grp]
(The sequence is relevant but I wouldn't worry about it)
Note you can add to this array during the mission as reinforcing groups arrive.
You can use a different name for the array providing you edit the scripts below (only one line needs to be changed in each script.)
Now you need to decide if you want all survivors to consolidate ultimately to one specific group, or do you not care which group is the last one standing.
If one specific group is to be the last one standing then put:
[this] exec "JoinToThisGroup.sqs" in the initialisation field of the group leader for that one group.
and put:
[this] exec "JoinToOtherGroup.sqs" in the initialisation field of the leaders of all the other groups.
If you don't care which is the last group standing just use the JoinToOtherGroups script for all of the groups.
JoinToThisGroup.sqs
; JoinToThisGroup.sqs. Consolidated Russian groups as they take casualties
; called by [unit]exec"JoinToThisGroup.sqs"
; unit is one unit in the specific group that all join to in the end
; a global array called Base2Groups should exist and contain each of the groups to be
; considered for joining together
_unit = _this select 0
_group = group _unit
_smallsize = 3
_largesize = 12
goto"FirstTime"
#Loop
CheckInProgress = false
#FirstTime
~10
#NotReady
~ random 1
if CheckInProgress then {goto"NotReady"}
CheckInProgress = true
_othergroups = Base2Groups - [_group]
_NumOfGrps = count _othergroups
_i = 0
#LoopOthGroups
_OthGroup = _othergroups select _i
_SizeThisGroup = count units _group
_SizeOthGroup = count units _OthGroup
if ((_SizeOthGroup < 1) or ((_SizeThisGroup + _SizeOthGroup) > _largesize) or ((_SizeThisGroup > _smallsize) and (_SizeOthGroup > _smallsize))) then {goto"SkipGrp"}
units _OthGroup join _group
#SkipGrp
_i = _i + 1
if (_i <_NumOfGrps) then {goto"LoopOthGroups"}
goto"Loop"
#End
CheckInProgress = false
exit
JoinToOtherGroup.sqs
; JoinToOtherGroup.sqs. Runs for selected Russian groups
; checks the size of the group and when it is small seeks other groups to join with
; called by [unit]exec"JoinToOtherGroup.sqs"
; unit is one unit in the specific group
; a global array called Base2Groups should exist and contain each of the groups to be
; considered for joining together
_unit = _this select 0
_group = group _unit
_smallsize = 3
_largesize = 12
~ 5 + random 10
goto"FirstTime"
#Loop
CheckInProgress = false
#FirstTime
~10
#NotReady
~ random 1
if CheckInProgress then {goto"NotReady"}
CheckInProgress = true
_othergroups = Base2Groups - [_group]
_SizeThisGroup = count units _group
if (_SizeThisGroup > _smallsize) then {goto"Loop"}
if (_SizeThisGroup < 1) then {goto"End"}
_NumOfGrps = count _othergroups
_i = _NumOfGrps - 1
#LoopOthGroups
_OthGroup = _othergroups select _i
_SizeOthGroup = count units _OthGroup
if ((_SizeOthGroup < 1) or ((_SizeThisGroup + _SizeOthGroup) > _largesize)) then {goto"SkipGrp"}
units _group join _OthGroup
goto"End"
#SkipGrp
_i = _i - 1
if (_i >= 0) then {goto"LoopOthGroups"}
goto"Loop"
#End
CheckInProgress = false
exit