;**Variables - Feel free to change these**
_MaxSearchDist = 10

;**Initial settings - Do not change**
_Dist = 0

hint "Looking for wounded units to join"

? count (units group player) >= 12 : exit

#FindTarget
~0.01

_Ang = (GetDir player)

_TgtPos = [((getPos player select 0) + ((sin _Ang) * _Dist)),((getPos player select 1) + ((cos _Ang) * _Dist)),(getPos player select 2)]
_Tgt = NearestObject _TgtPos

? (alive _Tgt) AND (captive _Tgt): goto "Join"

_Dist = _Dist + 1
? _Dist > _MaxSearchDist: _Dist = 1
Goto "FindTarget"

#Join

hint "Unit has been found"
[_Tgt] join player
_Tgt setcaptive false
[_Tgt] exec "ammo1777.sqs"
~5
_Tgt switchmove "COMBAT"


exit
