Jump to content
Sign in to follow this  
GuyJ

Restricting a while loop count, but not exiting complete.

Recommended Posts

Hi all.

 

I have been playing since flashy and did very basic editing over the years (triggers and a lot of borrowing from others), but at 36 now I seemingly have the urge to slowly learn how to do more complex stuff, but that also means I have limited time between watch repair and normal life! 

 

Anyway, the issue I'd appreciate some help with is something I'm sure is very simple, or whatever it is could someone be kind enough to explain their process a little or what I'm doing wrong. I don't want to just copy and paste if you know what I mean, but this is something I have tried to understand from Fockers Arma Scripting tutorial.

 

I have a civilian playable with allowDamage false; I am watching a while loop spawn individual soldiers for both sides and then just kill each other.

The while loop does this while my variable of _total <20 is being assessed. I have countAllUnits as the defined variable for _total, but it doesn't count the actual amount of units being created. Why is that, please?

 

My issue I'd like to sort is that once I trigger the while loop from my civi player addAction and I see the units spawn, I don't want to have to repeat the addAction to 'top-up' the _total. I'd like it somewhat dynamic, so some kind of sleep before repeating the process is all my unaware script mind can think of!

 

Hope someone can guide me. Cheers.

_total = count allUnits;
hint format ["Total units in game:%1",_total];
sleep 4;
_grp = createGroup West;
_grp2 = createGroup East;
_blds = nearestBuilding AmmoSups;

while {_total <20} do
{		sleep 1;
        _newsoldier = "B_Soldier_GL_F" createUnit [getPos _blds,_grp];
        hint format ["Units in game:%1", _total];
		_newsoldier2 = "O_support_MG_F" createUnit [getPos AmmoSups,_grp2];
		hint format ["Units in game:%1", _total];
		sleep 1;
		_grp setFormation "STAG COLUMN";
        _grp setBehaviour "AWARE";
        _wp = _grp addWaypoint [position AmmoSups,0];	       
        _total = _total +1;
		sleep 0.5;
};
hint "while loop complete.";

if I local exec the hint for the total I get the actual amount which I don't want it to be so high (above 20), but I also don't want it to drop below 20 alive players at any point. A perpetual war if you will... :)

Share this post


Link to post
Share on other sites

Just worked that out right now killzone_kid. Silly me.. Thank you, though. How do I kick the while loop back in to effect when say the total drops below 10 and keep that looping? Also, if I see a side is dominating, is there a way I can add more units specifically to favour the weaker side?

 

Ok, I have this now which is a little bit more fun.. :)

Still want to work out the rest of my 'issue' but I'll keep plugging away...

 

 
_total = count allUnits;
hint format ["Total units in game:%1",_total];

sleep 4;

_blds = nearestBuilding AmmoSups;

while {_total <20} do
{
        hint "While loop:spawning new group";
		sleep 1;
        _newGroup = [getPos _blds, WEST, (configfile >> "CfgGroups" >> "West" >> "BLU_F" >> "Infantry" >> "BUS_InfAssault")] call BIS_fnc_spawnGroup;
		_newGroup2 = [getPos AmmoSups, EAST, (configfile >> "CfgGroups" >> "East" >> "OPF_F" >> "Infantry" >> "OIA_InfAssault")] call BIS_fnc_spawnGroup;
		_newGroup setFormation "STAG COLUMN";
        _newGroup setBehaviour "AWARE";
        _wp = _newGroup addWaypoint [position AmmoSups,0];
		hint format ["Units in game:%1", _total];		       
        _total = count AllUnits;
		sleep 0.5;
	
};
	
hint "while loop complete.";

 

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  

×