Jump to content
Sign in to follow this  
sturmfalkerda

WaitUntil inside forEach loops?

Recommended Posts

I am attempting to optimize a script, and I have done something stupid. I cant finish the part that detaches stuff and the ground detection.... Any ideas?

OPTIMIZED 0 = ["lz", Pcar1, Pcar2] execVM "boxdroponmarker3.sqf"

		if(isServer) then {
	_wpPos = _this select 0;
       _chuteType = "B_Parachute_02_F";	
       _carnameType =  "B_supplyCrate_F";
	_stuff1 = "chemlight_red";
	_stuff2 = "SmokeShellRed";
	_stuff3 = "F_20mm_Red";
	_stuff = [_stuff1, _stuff2, _stuff3];
	_carname = _this select 1;
	_carname2 = _this select 2;
	_handle = [_carname, _carname2];

    {
    _chute = createVehicle [_chuteType, [100, 100, 200], [], 0, 'FLY'];
	_chute setPos [getMarkerPos _wpPos select 0, getMarkerPos _wpPos select 1, 200];
	_x attachTo [_chute, [0, 0, 0.2]];
	{
	_randomstuff = _x createVehicle [0,0,0];
	_randomstuff attachTo [_chute, [0, 0, 0.2]];

	} forEach _stuff;

	} forEach _handle;


//		waitUntil {position _carname select 2 < 0.5 || isNull _chute};

UNOPTIMIZED

	if(isServer) then {
	_wpPos = _this select 0;
       _chuteType = "B_Parachute_02_F";
       _carnameType =  "B_supplyCrate_F";	

	_chute = createVehicle [_chuteType, [100, 100, 200], [], 0, 'FLY'];
       _chute setPos [getMarkerPos _wpPos select 0, getMarkerPos _wpPos select 1, 200];
    _carname = _this select 1;
       _light = "chemlight_red" createVehicle [0,0,0]; //create the chemlight
	_smokegrenade = "SmokeShellRed" createVehicle [0,0,0]; //create the Smoke
	_carflare = "F_20mm_Red" createVehicle [0,0,0]; //create the Flare
	_carname attachTo [_chute, [0, 0, 0.2]];
	_light attachTo [_chute, [0, 0, 0.2]];
	_smokegrenade attachTo [_chute, [0, 0, 0.2]];
	_carflare attachTo [_chute, [0, 0, 0.2]];
       waitUntil {position _carname select 2 < 0.5 || isNull _chute};
       detach _carname;
	detach _light;
	detach _SmokeGrenade;
	detach _carflare;
       _carname setPos [position _carname select 0, position _carname select 1, 0];
	[_carname, "mis_fnc_boxInit"] spawn BIS_fnc_MP; //remove this if you don't want VAS on your box
	};

Share this post


Link to post
Share on other sites

You can try to put

private ["_x"];

in second forEach loop. Or just use something like this instead:

for "_i" from 0 to (count _stuff - 1) do {
_thing = _stuff select _i;

_randomstuff = _thing createVehicle [0,0,0]; 
_randomstuff attachTo [_chute, [0, 0, 0.2]]; 
};

Share this post


Link to post
Share on other sites

First forEach loop defines _x and second forEach loop does the same thing. They may conflict.

Private command makes it... well private for that loop. Not sure though, it might not work.

Share this post


Link to post
Share on other sites

It works at the moment, I have no idea how.

I will try setting them private.

How do I implement the following for each vehicle? My attempts result in wierdness.

This prevents the vehicle from slamming into the ground.

     waitUntil {position _carname select 2 < 0.5 || isNull _chute};
      _carname setPos [position _carname select 0, position _carname select 1, 0]; 

Thank you for the help!

Share this post


Link to post
Share on other sites
{
[_x] spawn {
	_carname = _this select 0;

	waitUntil {position _carname select 2 < 0.5 || isNull _chute};
	_carname setPos [position _carname select 0, position _carname select 1, 0];
};
} forEach _cars;

Somthing like this?

Edited by Champ-1

Share this post


Link to post
Share on other sites

Where? _chute is local and cant be seen by the above because it is inside a forEach loop. I may need to rewrite my script, :|

Share this post


Link to post
Share on other sites

You need to pass all variables through squre brackets and then define them via "_this select".

[_carname, _chute, _whatever] spawn {
_carname = _this select 0;
_chute = _this select 1;

Spawn is basicly a way to create new loop that doesn't stop your script from working. It's like another script inside a script.

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  

×