Jump to content
Sign in to follow this  
hansson0728

thislist trigger and foreach loop, just wont work.. wierd...

Recommended Posts

Iám trying to get this to work, the shooter should engage all targets who are in the trigger (even if they leave the trigger)

it works great but it allways breaks when theres 2 targets left.. for example if i have 10 units in the trigger area (in Targets) the loop goes trough 8 of them then it breaks. if i have 5 units in the trigger area (in Targets) it goes trough 3 then it breaks..

and it allways breaks with this statement in the RPT file:

/ ---------------------------------------------------------------------------------------------

Error in expression <_sniper doTarget _x;

sleep 3;

_sniper fireAtTarget _x;

sleep 5;

_Watchdir = (>

Error position: <fireAtTarget _x;

sleep 5;

_Watchdir = (>

Error fireattarget: Type Object, expected Array

/ ---------------------------------------------------------------------------------------------

i dont get it, i have tried everything, why ? anyone ?

/ ---------------------------------------------------------------------------------------------
// Create trigger so the sniper knows when to act
// ---------------------------------------------------------------------------------------------

// empty array to store targets in
Targets = [];

// create trigger for sniper to target all enemy in trigger area
_snipertrigger = createTrigger["EmptyDetector",_openarea];
_snipertrigger setTriggerArea[75,75,0,false];
_snipertrigger setTriggerTimeout [5, 10, 7, true];
_snipertrigger setTriggerActivation["WEST","PRESENT",false];
_snipertrigger setTriggerStatements["this","Targets = thislist;", "deleteVehicle thistrigger;"];

// ---------------------------------------------------------------------------------------------
// once the trigger fires, order sniper to engage targets in target array
// ---------------------------------------------------------------------------------------------

waituntil {(triggeractivated _snipertrigger)};
{
sleep 2;
	if (_x isKindOf "Man") 
		then {
			hint format ["Target: %1", _x]; 
			while {alive _x} do 
				{
				_sniper reveal _x; 
				_sniper doTarget _x; 
				sleep 3; 
				_sniper fireAtTarget _x; 
				sleep 5;
				_Watchdir = (([_sniper, _x] call BIS_fnc_relativeDirTo));
				_sniper setDir _Watchdir;
				_sniper setformDir _Watchdir;
				};
		}; 

} foreach Targets;

hint "Trigger Complete done shooting!";

Share this post


Link to post
Share on other sites

okej so after alot of fiddeling with this little script i finally got it. idon't know if it the most effective solution, because the forach loop seems to skip some objects, so i i did a nil check, and a "man check" then after that i iemdedded the whole loop in a while loop checking the array so that it is really empty, forcing the foreach everytime it skipps an object.. the trigger is the same as before.. if any one else had this prioblem this may help.. also i changed _sniper fireAtTarget _x; to a do Fire instead (but i thinsk FireatTarget will work now to.)

waituntil {(triggeractivated _snipertrigger)};

while {!(count Targets == 0)} do 
{
{
	if (!isNil "_x") then {
			if (_x isKindOf "Man") 
			then {
				hint format ["Target: %1", _x]; 
				while {alive _x} do 
					{
					_sniper reveal _x; 
					_sniper doTarget _x;
					sleep 5; 
					_sniper doFire _x; 
					sleep 5;
					_Watchdir = (([_sniper, _x] call BIS_fnc_DirTo));
					_sniper setformDir _Watchdir;
					};

			};

	} else { sleep 5; } ;
} foreach Targets;
};
hint "Trigger Complete done shooting!";
sleep 5;

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×