Cockheaven 21 Posted January 19, 2020 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
7erra 629 Posted January 19, 2020 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: Spawning units in general. 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; 2 1 Share this post Link to post Share on other sites
RCA3 593 Posted January 19, 2020 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. 1 1 Share this post Link to post Share on other sites
Cockheaven 21 Posted January 20, 2020 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: Spawning units in general. 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
7erra 629 Posted January 20, 2020 Gotta check the units not the array: CK_Enemies = CK_Enemies select {alive _x}; Share this post Link to post Share on other sites