Thanks, got that working and adjusted things a little....it fires at the target now, but freezes when the crew jump out of the damaged vehicle.....here's the new script..
private ["_firer","_range","_return","_rangeb","_gunner","_type","_crew","_distance","_targets","_target","_numtgts","_v","_n0","_n1","_tgttype","_tgtcnt","_enunits","_ttype","_tid","_fpos","_typcnt","_distvar","_na","_nb"];
_firer = _this select 0;
_range = _this select 1;
_rangeb = _range;
_gunner = gunner _firer;
_type = [];
_distance = [];
_enunits = [];
_ttype = [];
_tid = [];
_fpos = [];
_distvar = [];
_target = [];
_targets = _firer NearTargets _range;
_numtgts = count _targets;
_return = true;
_v = 0;
_n0 = 0;
_n1 = 1;
_tgttype = ["DSHKM","AGS","D30","BRDM2","UAZMG","UAZ_AGS30","BRDM2_ATGM","BMP2","ZSU","KA50","MI17_MG","SU34B","RHIB","RHIB2Turret"];
_tgtcnt = count _targets;
/*
; SCREEN FOR THREAT
*/
for [{_v = 0},{_v < _tgtcnt},{_v = _v + 1}] do
{
_enunits = _targets select _v;
_ttype = _enunits select 1;
_tid = _enunits select 4;
if (_ttype in _tgttype) then {_type = _type + [_tid];};
};
/*
; GET RANGES TO NEWLY ARRAYED UNITS
*/
_typcnt = count _type;
if (_typcnt == 0) then {_return;};_return;
for [{_v = 0},{_v < _typcnt},{_v = _v + 1}] do
{
_fpos = getpos _firer;
_ttype = _type select _v;
_distance = _fpos distance getpos _ttype;
_distvar = _distvar + [_distance];
};
/*
; USE DISTANCE ARRAY TO FIND OUT CLOSEST TARGET
*/
for [{_v = 0},{_v < _typcnt},{_v = _v + 1}] do
{
_ttype = _distvar select _v;
if (_ttype < _rangeb) then {_rangeb = _ttype};
};
/*
; FIND TARGET IN ENEMY ARRAY THAT MATCHES CLOSEST TARGET RANGE
*/
for [{_v = 0},{_v < _typcnt},{_v = _v + 1}] do
{
_ttype = _type select _v;
_tpos = getpos _ttype;
_distance = _firer distance getpos _ttype;
if ((_distance < _rangeb + 5) and (_distance > _rangeb - 5)) then {_target = _ttype};
};
/*
; ENGAGE TARGET
*/
_crew = crew _target;
While {alive _target} do
{
_ammo = _firer ammo "M2";
_burst = _ammo - 20;
while {_ammo > _burst} do
{
if ((damage _target) > 0.9) then {[_firer,_range] exec "findtgt.sqs";};_return;
_firer dotarget _target;
WaitUntil{unitready _firer};
_firer action ["useWeapon", _firer, _gunner, 0];
_ammo = _firer ammo "M2";
sleep 0.18;
};
sleep 1;
};
_return;
....and here's the error report..
=====================================================================
== E:\Games\ArmA\arma.exe
=====================================================================
Exe version: Wed Oct 31 16:28:06 2007
Item STR_LIB_HILUX listed twice
Updating base class ->Default, by ca\anims\characters\config.bin/CfgMovesBasic/DefaultDie/
Updating base class ->Default, by ca\anims\characters\config.bin/CfgMovesMaleSdr/States/Crew/
Updating base class ->MGunCore, by ca\weapons\config.bin/cfgWeapons/MGun/
Applying controller scheme Default
Applying controller scheme Default
=======================================================
Date: 01/16/08 Time: 19:30:22
-------------------------------------------------------
Exception code: C0000005 ACCESS_VIOLATION at 0082098E
graphics: D3D9, Device: NVIDIA GeForce 8800 GTS, Driver:nvd3dum.dll 7.15.11.6369
resolution: 1024x768x32
Addons:
Datsun_armed_DBE1 in CA\DBE1\datsun_armed\, DBE1 in CA\DBE1\, Desert in ca\desert\
CAIntroAnims in ca\introanims\, CASounds in ca\sounds\, DBE1_UI in CA\DBE1\ui\
Desert2_Buildings in ca\Desert2\build\
CA_Missions_Armory1 in ca\missions\armory1.intro\
CAweapons3_m107 in CA\weapons3\m107\
CAweapons3_m16a4_acg in CA\weapons3\m16a4_acg\, CAWheeled in ca\wheeled\
Desert2_Objects in ca\Desert2\objects\, CA_Missions in ca\missions\
CARoads in ca\roads\, CAWheeled3_TT650 in CA\wheeled3\tt650\, CAAir in ca\air\
CA_Anims in ca\anims\, CAAnimals in CA\animals\
CA_desert2_Characters in ca\Desert2\characters\, CAUI in ca\ui\
CAWeapons in ca\weapons\, CAweapons3_m16a4 in CA\weapons3\m16a4\
CAWeapons3_ammocrates in CA\weapons3\ammocrates\, CAAir3_Su34 in CA\air3\su34\
CACharacters in ca\characters\, CA_CutSceneAnims in ca\cutSceneAnims\
DC3_DBE1 in CA\DBE1\dc3\, CASigns in CA\signs\, CAFonts in ca\UIFonts\
CAweapons3_m16a4_gl in CA\weapons3\m16a4_gl\, CAWeapons3 in CA\weapons3\
CAWheeled3_M1030 in CA\wheeled3\m1030\, CAAir3 in CA\air3\, CAMisc in ca\misc\
CAPlants in CA\plants\, CAVoice in ca\voice\, CAData in ca\
CALanguage in ca\language\, CAWater in CA\water\
CAweapons3_aks74pso in CA\weapons3\aks74pso\
CA_Anims_Char in ca\anims\characters\, CATracked in ca\tracked\
CAweapons3_ksvk in CA\weapons3\ksvk\, CAA10 in ca\a10\, Porto in ca\Desert2\
6G30_DBE1 in CA\DBE1\6g30\, Sara in ca\sara\, CAWheeled3 in CA\wheeled3\
CABuildings in ca\buildings\, Hilux_armed_DBE1 in CA\DBE1\hilux_armed\
CARocks in Ca\Rocks\, CAweapons3_m16a4_acg_gl in CA\weapons3\m16a4_acg_gl\
Mods: CA
Distribution: 1294
Version 1.08.5163
Fault address: 0082098E 01:0041F98E E:\Games\ArmA\arma.exe
file: test
world: Intro
Prev. code bytes: 75 D0 32 C0 5F 5E C9 C3 8B 4C 24 08 8B 44 24 04
Fault code bytes: 8A 10 3A 11 75 17 84 D2 74 10 8A 50 01 3A 51 01
Registers:
EAX:203A7476 EBX:00917F38
ECX:7C264EE0 EDX:00000083
ESI:7FF998D8 EDI:00000001
CS:EIP:001B:0082098E
SS:ESP:0023:01C4F17C EBP:01C4F1B8
DS:0023 ES:0023 FS:003B GS:0000
Flags:00010212
=======================================================
note: Minidump has been generated into the file C:\Users\User\AppData\Local\ArmA\arma.mdmp
Also I dont know if I'm using the _return correctly to exit the script.