First off, this script is all General Barron's. I'm just editing it because it's an error in my mission, ultimately, will lower my mission score. So I have but one option. Fix it
It's a man MG script - for the exact details, just see the script below. The script works fine, and units will rearm, but occasionally, it will throw an error:
_gunner = _units select _closestUnit |#| Zero divisor
Now, if I assess that right, it's telling me that infact _units select _closestUnit does not exsist. Therefore, I inserted a check immediately before the variable _gunner is initalized with the unit in the array. See below, it's been commented.
The problem is, this still throws an error. Is there any other way that I can stop the zero error? Or ultimately, is there another miniscule error with the script?
;-----------------------------------------------------------------------------------------------------------------
-----------------
;manMG2.sqs
;By General Barron
;aw_barron@hotmail.com
;3/29/03
;Edited by Tyger to provide two extra checks agains the "Zero Divisor" error.
;I believe they were cause when the script just entered a loop when the unit it
;was going to give instructions to was killed.
;This script is used to make units man a machine gun when its gunner gets killed.
;The closest unit to the machine gun will go to man it, as long as they are within the
;reach of the trigger. If no units are currently in the area, the next unit to enter the range
; of the trigger will go to man the MG. If you wish, you can make it so only units of a certain
; side will be affected by this script.
; It is called as follows:
;[mg,trigger,side(optional)] exec "manMG2.sqs"
;"mg" is the name of the machine gun you want manned.
;"trigger" is the name of a trigger. It must be set to "activation ANYBODY".
;Only units within the area of this trigger will be affected by this script.
;(Make sure it is activated by "anybody", NOT "west", "east", etc. It will ONLY work with "anybody"!!!)
;"side" is optional. Placing WEST (no quotes!) here will allow only west units to be affected
;by this script. Other options are EAST and RESISTANCE. You cannot specify the side "civilian".
;If you leave this blank, any unit, regardless of side will be affected by this script.
;You can end all manMG scripts that are running by setting the variable manMG_end to TRUE
;-----------------------------------------------------------------------------------------------------------------
-----------------
manMG_end = FALSE
;set this variable to TRUE to end the script
_gun = _this select 0
;name of the machine gun to be manned
_trigger = _this select 1
;name of trigger covering the area
_side = _this select 2
;side you want to man the gun with (optional). If nothing is entered, any side can man the gun
?_side == west OR _side == east OR _side == resistance : goto "Top"
_side = civilian
;this makes civilian the default _side (if nothing is entered when calling the script)
#Top
@NOT alive gunner _gun OR NOT alive _gun OR manMG_end
?NOT alive _gun OR manMG_end : exit
@"vehicle _x == _x" count list _trigger > 0 OR NOT alive _gun
?NOT alive _gun OR manMG_end : exit
;wait until the gunner is dead, and there are people around who aren't in vehicles
_units = list _trigger
_i = -1
_max = count _units
_minDist = 99999
;set up variables for loop
#Loop
_i = _i + 1
?_max <= _i : goto "Bottom"
;exit loop when end of list is reached
;Inserted by Tyger as a check for the infamous "Zero Divisor"
if ((_units select _i) != nil) then {_man = _units select _i} else {goto "Top"}
;_man = _units select _i
_dist = _man distance _gun
;find distance between selected man and gun
?_dist >= _minDist OR vehicle _man != _man OR _man == player OR vehicle _man == _gun OR (_side != civilian AND side
_man != _side) : goto "Loop"
;move on to the next man if they are further away from the gun than the closest person, or if they are in a
vehicle, or if it is the player, or if they are on the wrong side (unless _side = civilian)
_closestUnit = _i
_minDist = _dist
;if they pass, then they are the current closest man to the mg, and their element # and distance is saved
goto "Loop"
#Bottom
;Inserted by Tyger as a check for the infamous "Zero Divisor"
if ((_units select _closestUnit) != nil) then {_gunner = _units select _closestUnit} else {goto "Top"}
;_gunner = _units select _closestUnit
_gunner assignAsGunner _gun
[_gunner] orderGetIn TRUE
;once the loop is finished, the closest man is selected, assigned to the gun, and ordered in
goto "Top"