Jump to content

Recommended Posts

Hi guys, I have created a script to spawn enemies until a player in an area has been outnumbered, then wait until the player isn't outnumbers and resume spawning. I'm using a while for this with some If and uisleep. While this script is running I'm seeing a severe impact on performance, FPS is fine but server command processing is slowed, Zeus spawning or module placing lags. Is this an efficient way of performing this task? Is there a better way to do this? Also how do I stop the script from running?

 

Spoiler

[ "t3", ["We have arrived at FARP Winchester which appears abandoned. Secure and hold Winchester until EVAC arrives.","The Gauntlet","Castle"] ] call BIS_fnc_taskSetDescription;
"t3" call BIS_fnc_taskSetCurrent; //set the task as current
["t3","defend"] call BIS_fnc_taskSetType;

if (!isServer) exitWith {}; 
hintSilent "waiting for 15 init";
uisleep 15;

CK_Enemies = []; // empty array for spawned groups

//wait for squad to collect in castle then send initial wave
CSTL_DNFDRS = allPlayers inAreaArray CSTLGNDS; // who goes there
_nearplayercount = count CSTL_DNFDRS; // count players in castle
_playerLoops = _nearplayercount; // used to restrict min player requirement

while {(count (allPlayers inAreaArray CSTLGNDS)) > 0} do 
{
	hintSilent "players in Castle waiting 25";
	uisleep 25;
	CSTL_DNFDRS = allPlayers inAreaArray CSTLGNDS;
	_nearplayercount = count CSTL_DNFDRS;
	_playerLoops = _nearplayercount;
	if ((4*(count (allPlayers inAreaArray CSTLGNDS))) < ({alive _x} count CK_Enemies)) then 
		{
			hintSilent "Outnumbered waiting 20";
			uisleep 20;
		}
		else
		{
			{
				if (_playerLoops > 0) then 
					{
						_grp4Marker = Selectrandom ["IEDAMBUSH1_1","IEDAMBUSH1_2","IEDAMBUSH1_3","IEDAMBUSH1_4","IEDAMBUSH1_5","IEDAMBUSH1_6"]; //select a random spawn point for group 4
						_grp4 = [getmarkerpos _grp4Marker, East, ["CFP_O_HEZBOLLAH_Militia_Squad_Leader_01","CFP_O_HEZBOLLAH_Militia_Rifleman_AT_01"],[],[],[],[],[],116] call BIS_Fnc_spawnGroup; // group unit array and spawn at marker
						[_grp4, getMarkerPos "Castle"] call bis_fnc_taskAttack; //attack this marker
						[_grp4, 1] setWaypointSpeed "FULL";
						[_grp4, 1] setWaypointCombatMode "RED";
						[_grp4, 1] setWaypointBehaviour "COMBAT";
						[_grp4, 1] setWaypointFormation "LINE";
						{
							CK_Enemies pushBack _x;
						} foreach units _grp4;
							 // push groups into CK_Enemies
					};
			} foreach CSTL_DNFDRS;
			hintSilent "second group spawned waiting 5";
			uisleep 5;
			};
		};

 

 

Share this post


Link to post
Share on other sites
8 hours ago, Cockheaven said:

While this script is running I'm seeing a severe impact on performance

Two possible reasons that I know of:

  1. Spawning units in general.
  2. Counting a huge array. Try removing dead units from it. That would also simplify the {alive _x} count CK_Enemies in the while do condition to count CK_Enemies.

 

8 hours ago, Cockheaven said:

Also how do I stop the script from running?

Set a variable to false in the while do condition. If it is from outside of the script then you'll have to use a global variable.

 

Also instead of:

{
	CK_Enemies pushBack _x;
} foreach units _grp4;

You can use:

CK_Enemies append units _grp4;

 

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites
14 hours ago, Cockheaven said:

CSTL_DNFDRS = allPlayers inAreaArray CSTLGNDS;

 You're counting this 3 times. Just use the value from line above in the while loop and on the if then{4*...}.

Also using private and if you can only local variables may speed up the process.

Maybe add a ~5-10 second sleep to the while loop as well.

  • Like 1
  • Thanks 1

Share this post


Link to post
Share on other sites
8 hours ago, RCA3 said:

 You're counting this 3 times. Just use the value from line above in the while loop and on the if then{4*...}.

Also using private and if you can only local variables may speed up the process.

Maybe add a ~5-10 second sleep to the while loop as well.

Thanks, repetitive remedial math is bad.
 

 

13 hours ago, 7erra said:

Two possible reasons that I know of:

  1. Spawning units in general.
  2. Counting a huge array. Try removing dead units from it. That would also simplify the {alive _x} count CK_Enemies in the while do condition to count CK_Enemies.

so redefine CK_Enemies = alive CK_Enemies then do the count?

Share this post


Link to post
Share on other sites

Gotta check the units not the array:

CK_Enemies = CK_Enemies select {alive _x};

 

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

×