Hi there,
I just found another bug. Hopefully, this will solve the problem. I haven't tested the code, yet, but I think this will do it.
;###############################################
; NewGunner.sqs
; By Ranger @ www.ofpec.com
;
; Usage: [mg,gunner1,gunner2,...,gunnerN] exec "NewGunner.sqs"
;
; This script checks if the gunner for a machine gun is dead, and if so,
; orders another unit to use the MG. It chooses randomly from among
; the specified replacement gunners. Example usages:
;
; [mg1,guy1,guy2,guy3] exec "NewGunner.sqs"
; ([mg1] + units group1) exec "NewGunner.sqs"
;###############################################
; Take the passed parameters and assign the data to local variables.
; _mg is the machine gun.
; _gunners is an array of replacement gunners.
_mg = _this select 0
_gunners = _this - [_this select 0]
#Loop
; Wait until there is no one "in" the MG.
@ count (crew _mg) < 1
; Check if the MG itself is destroyed. If so, exit the script.
? not alive _mg : exit
#Choose
; Choose a new gunner randomly from the array.
_newGunner = _gunners select random(count _gunners)
; Remove the gunner from the array.
_gunners = _gunners - [_newGunner]
; This script is no longer needed if there are no extra gunners left and
; the last gunner is dead already.
? (count _gunners < 1) and (not alive _newGunner) : exit
; Verify that the new gunner is alive. If not, choose again.
? not alive _newGunner : goto "Choose"
; Assign the gunner to the MG and tell him to get in.
_newGunner assignAsGunner _mg
[_newGunner] orderGetIn TRUE
; This script is no longer needed if there are no extra gunners left.
? count _gunners < 1 : exit
goto "Loop"
For your information, the bug was that the code was checking if _gunner was alive. However, there is no variable named "_gunner", so I"m surprised that it even worked once. IN any event, I fixed it, so give it another try. Good luck!