Jump to content
Sign in to follow this  
1para{god-father}

Some advise on a While loop

Recommended Posts

The following seems to be causing an issue, it yellow chanes the server , if i take this part out of the script it seems to work fine - is there a better way to spawn in and keep them spawning in untill I want it to stop i.e !alive _alarm1 etc..

Should I use something other than a while loop?

while {alive _alarm1 && alive _alarm2 && alive _alarm3} do {
/////////////////////////ambush ////////////////////////////////////
_grp1 = [[2169.94,12353.6,0.00115585], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSquad")] call BIS_fnc_spawnGroup;
_wp = _grp1 addwaypoint [getPos alarm1,0];  
_wp setWaypointType "SAD";
_wp setWaypointCombatMode "RED";
_wp setWaypointSpeed "FULL";
_wp setWaypointBehaviour "AWARE";
_wp1 = _grp1 addwaypoint [getPos alarm1,0];  
_wp1 setWaypointType "MOVE";
_wp1 setWaypointCombatMode "RED";
_wp1 setWaypointSpeed "FULL";
_wp1 setWaypointBehaviour "AWARE";

_grp2 = [[1124.94,12042.3,0.00132751], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSquad")] call BIS_fnc_spawnGroup;
_wp2 = _grp2 addwaypoint [getPos alarm2,0];  
_wp2 setWaypointType "SAD";
_wp2 setWaypointCombatMode "RED";
_wp2 setWaypointSpeed "FULL";
_wp2 setWaypointBehaviour "AWARE";
_wp12 = _grp2 addwaypoint [getPos alarm2,0];  
_wp12 setWaypointType "MOVE";
_wp12 setWaypointCombatMode "RED";
_wp12 setWaypointSpeed "FULL";
_wp12 setWaypointBehaviour "AWARE";

_grp3 = [[1333.93,11029.9,0.00180054], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSquad")] call BIS_fnc_spawnGroup;
_wp3 = _grp3 addwaypoint [getPos alarm2,0];  
_wp3 setWaypointType "SAD";
_wp3 setWaypointCombatMode "RED";
_wp3 setWaypointSpeed "FULL";
_wp3 setWaypointBehaviour "AWARE";
_wp13 = _grp3 addwaypoint [getPos alarm2,0];  
_wp13 setWaypointType "MOVE";
_wp13 setWaypointCombatMode "RED";
_wp13 setWaypointSpeed "FULL";
_wp13 setWaypointBehaviour "AWARE";

_grp4 = [[2297.37,11465.4,0.00196838], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSection")] call BIS_fnc_spawnGroup;
_wp4 = _grp4 addwaypoint [getPos alarm3,0];  
_wp4 setWaypointType "SAD";
_wp4 setWaypointCombatMode "RED";
_wp4 setWaypointSpeed "FULL";
_wp4 setWaypointBehaviour "AWARE";
_wp14 = _grp4 addwaypoint [getPos alarm3,0];  
_wp14 setWaypointType "MOVE";
_wp14 setWaypointCombatMode "RED";
_wp14 setWaypointSpeed "FULL";
_wp14 setWaypointBehaviour "AWARE";
///put a sleep in before we send more in  say 5 min
sleep 300;
};



Share this post


Link to post
Share on other sites

Four mechanized squads spawning every 5 minutes till things are destroyed? Why not just play call of duty? :)

Not sure if it would help but perhaps change it to checking on the value of a variable and set that variable with a trigger checking the other units being alive or not? You might also toss that spawn code into a precompiled function and just call that instead of all that each time. See the biki about precompiling.

Share this post


Link to post
Share on other sites

Well first off you don't have an if (isServer) statement meaning if this is a MP mission, it will do this script for each client resulting in a full scale military attack instead of a small ambush.

I'm also going to recommend that you put a sleep command between each spawn code, it will give the server some time to sync before spawning in new soldiers (Atleast thats what I think).

Here is a updated version of your script that should hopefully get rid of your yellow chain:

if (isServer) then {
while {alive _alarm1 && alive _alarm2 && alive _alarm3} do {

	_grp1 = [[2169.94,12353.6,0.00115585], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSquad")] call BIS_fnc_spawnGroup;
	_wp = _grp1 addwaypoint [getPos alarm1,0];  
	_wp setWaypointType "SAD";
	_wp setWaypointCombatMode "RED";
	_wp setWaypointSpeed "FULL";
	_wp setWaypointBehaviour "AWARE";
	_wp1 = _grp1 addwaypoint [getPos alarm1,0];  
	_wp1 setWaypointType "MOVE";
	_wp1 setWaypointCombatMode "RED";
	_wp1 setWaypointSpeed "FULL";
	_wp1 setWaypointBehaviour "AWARE";

	// wait here to let the server sync
	sleep 5;

	_grp2 = [[1124.94,12042.3,0.00132751], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSquad")] call BIS_fnc_spawnGroup;
	_wp2 = _grp2 addwaypoint [getPos alarm2,0];  
	_wp2 setWaypointType "SAD";
	_wp2 setWaypointCombatMode "RED";
	_wp2 setWaypointSpeed "FULL";
	_wp2 setWaypointBehaviour "AWARE";
	_wp12 = _grp2 addwaypoint [getPos alarm2,0];  
	_wp12 setWaypointType "MOVE";
	_wp12 setWaypointCombatMode "RED";
	_wp12 setWaypointSpeed "FULL";
	_wp12 setWaypointBehaviour "AWARE";

	// wait here to let the server sync
	sleep 5;

	_grp3 = [[1333.93,11029.9,0.00180054], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSquad")] call BIS_fnc_spawnGroup;
	_wp3 = _grp3 addwaypoint [getPos alarm2,0];  
	_wp3 setWaypointType "SAD";
	_wp3 setWaypointCombatMode "RED";
	_wp3 setWaypointSpeed "FULL";
	_wp3 setWaypointBehaviour "AWARE";
	_wp13 = _grp3 addwaypoint [getPos alarm2,0];  
	_wp13 setWaypointType "MOVE";
	_wp13 setWaypointCombatMode "RED";
	_wp13 setWaypointSpeed "FULL";
	_wp13 setWaypointBehaviour "AWARE";

	// wait here to let the server sync
	sleep 5;

	_grp4 = [[2297.37,11465.4,0.00196838], RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> "GUE_MechInfSection")] call BIS_fnc_spawnGroup;
	_wp4 = _grp4 addwaypoint [getPos alarm3,0];  
	_wp4 setWaypointType "SAD";
	_wp4 setWaypointCombatMode "RED";
	_wp4 setWaypointSpeed "FULL";
	_wp4 setWaypointBehaviour "AWARE";
	_wp14 = _grp4 addwaypoint [getPos alarm3,0];  
	_wp14 setWaypointType "MOVE";
	_wp14 setWaypointCombatMode "RED";
	_wp14 setWaypointSpeed "FULL";
	_wp14 setWaypointBehaviour "AWARE";

	// I'm just putting this in as an option to you, un-comment the following line if you want the script to wait till all enemies are dead, then continue spawning.
	//waitUntil{!alive _grp1 && !alive _grp2 && !alive _grp3 && !alive _grp4};
	sleep 300;
};
};

EDIT: Kylania beat me to the comment of Call of Duty...

Share this post


Link to post
Share on other sites

aside from you are using _alarm1 etc in the while {condition} do {

and inside you use alarm1 in the wps.

here is also a shorter version of it, and remember to include a if (!isServer) exitWith {}; before the while loop if its not a locally spawned script.

while {alive _alarm1 && alive _alarm2 && alive _alarm3} do {
/////////////////////////ambush ////////////////////////////////////
_units = [];  // for the waitUntil instead of sleep, can be deleted if sleep is used.
{
	_grp = [(_x select 1), RESISTANCE, (configFile >> "CfgGroups" >> "Guerrila" >> "GUE" >> "Mechanized" >> (_x select 2))] call BIS_fnc_spawnGroup;
	_units = _units + [units _grp];  // for the waitUntil instead of sleep, can be deleted if sleep is used.
	_info = _x;  // assign _info so we can use it inside wp foreach block.
	{
		_wp = _grp addwaypoint [getPos (_info select 0),0];  
		_wp setWaypointType _x;  // here _x is type of wp, in order from left to right.
		_wp setWaypointCombatMode "RED";
		_wp setWaypointSpeed "FULL";
		_wp setWaypointBehaviour "AWARE";
	} foreach ["SAD","MOVE"];
} foreach [
		[alarm1,[2169.94,12353.6,0.00115585],"GUE_MechInfSquad"],
		[alarm2,[1124.94,12042.3,0.00132751],"GUE_MechInfSquad"],
		[alarm2,[1333.93,11029.9,0.00180054],"GUE_MechInfSquad"],
		[alarm3,[2297.37,11465.4,0.00196838],"GUE_MechInfSection"]
		];
sleep 300;
// or here to wait until all is dead:
// waitUntil { ({alive _x} count _units) <= 0 };  // change 0 to any number and when number of alive units total for all groups combined is same or less it moves on.
};

tested on my SP editor, no lag whatsoever, most likely its the isServer check that is missing or its the __alarm1 VS alarm1 thing...

edit:

// I'm just putting this in as an option to you, un-comment the following line if you want the script to wait till all enemies are dead, then continue spawning.
//waitUntil{!alive _grp1 && !alive _grp2 && !alive _grp3 && !alive _grp4};

you cannot check alive against a group, you use count instead:

waitUntil { ({alive _x} count units _grp1) == 0 AND  ({alive _x} count units _grp2) == 0 AND  ({alive _x} count units _grp3) == 0  ({alive _x} count units _grp4) == 0 };

or the clever version:

waitUntil { ({ ({alive _x} count units _x) != 0 } count [_grp1,_grp2,_grp3,_grp4]) == 0 };

Edited by Demonized
typo and added wait option commented instead of sleep.

Share this post


Link to post
Share on other sites

Thanks guys !

liked your point about COD but it was a test hence 5 min! It will be set a lot longer in game !

I removed that peice of code from the main .sqf which does have the if (!isServer) exitWith {} @ the start, but tested it again with Demonized code and no lagg this time !

Many thanks guys !

Share this post


Link to post
Share on other sites

Well Demonized to the rescue again, he is correct. I've seem to have forgot that you can't you the !alive status for a group. My Bad.

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  

×