;formup.sqs
;part of the custom formations script pack
;see the readme for instructions on usage
;by General Barron
;aw_barron@hotmail.com
;9/28/03

;This script is called by a formation script. It is passed the values: [group, formation],
;where formation is an array of 11 ordered pairs (the positions for the 11 squad members)

_group = _this select 0
_formation = _this select 1

?_group == group player : enableradio false
;disable the radio if the player is in the group, because the script causes lots of radio chatter
~0.1

_group setformation "line"
~2.5
;this turns off any previous formations on the group
;_group setformation "wedge"
;formation must be wedge for custom formation to function

{_x disableAI "TARGET"} foreach units _group
_group setspeedMode "LIMITED"

_i = 1
_p = 0
_max = count units _group
#Loop
?driver (vehicle (units _group select _i)) != (units _group select _i) OR vehicle (units _group select _i) == vehicle leader (units _group select _i) : _i = _i + 1
?driver (vehicle (units _group select _i)) != (units _group select _i) OR vehicle (units _group select _i) == vehicle leader (units _group select _i) : goto "Loop"

[(units _group select _i), _formation select _p] exec "formunit.sqs"
_i = _i + 1
_p = _p + 1
?_max > _i:goto "Loop"
;this loop executes formunit.sqs on every unit in the squad except the leader,
;sequentially assigning the ordered pairs in _formation to each member
;if the unit is in a vehicle, and not the driver, or the driver of the leader's vehicle, it does not apply the script
;this prevents the units from exiting their vehicles