R4IDER 10 Posted March 11, 2014 Hi, I have put together the code below for a paradrop mission that I have made but it seems that it has a dramatic impact on FPS overtime where you go from 60FPS to roughly 20FPS after around 2 minutes. Even when the targets are destroyed the FPS doesn't recover. Does anyone know a better way of achieving this without impacting the performance as much if at all. if (!isServer) exitWith {}; private ["_veh","_targets","_shoot","_count"]; _veh = _this select 0; _veh setVehicleAmmo 1; _targets = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13]; _shoot = true; _count = 0; _target = _targets select floor(random(count _targets)); sleep 0.3; while {(_shoot) and (alive _veh)} do { _count = _count + 1; if (_count == 15000) then { _shoot = false; doStop _veh;}; _veh doWatch _target; _veh action ["useWeapon", _veh, gunner _veh, 0]; }; Share this post Link to post Share on other sites
Tajin 348 Posted March 11, 2014 You shouldn't use loops that run without any delay in them. That's a sure way to bring your FPS down. Share this post Link to post Share on other sites
fusion13 11 Posted March 11, 2014 Well its adding to the var A LOT so if u switched it up a bit and used alive (aircraft) instead or somethung Share this post Link to post Share on other sites
laxemann 1673 Posted March 11, 2014 You might want to have a look at my Random AA Script :) Share this post Link to post Share on other sites
dwringer 45 Posted March 11, 2014 (edited) I am only basing this on the reply that says "you shouldn't use loops that run without any delay in them", with the techniques that I myself use for this issue: if (!isServer) exitWith {}; private ["_veh","_targets","_shoot","_count"]; _veh = _this select 0; _veh setVehicleAmmo 1; _targets = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13]; _shoot = true; _count = 0; _target = _targets select floor(random(count _targets)); sleep (0.2 + random 0.2); // Multiple scripts now much less likely to compete in the same frame while {(_shoot) and (alive _veh)} do { _count = _count + 1; if (_count == 15000) then { _shoot = false; doStop _veh;}; _veh doWatch _target; _veh action ["useWeapon", _veh, gunner _veh, 0]; sleep 0.05; // assuming the user gets at least 20fps, this almost as fast as visually perceptible. much longer sleep is usually ok. }; EDIT: sorry, i see now after actually reading the code that the firing occurs every cycle of the loop (if possible). Thus the sleep duration I put as 0.05 will give you a firing rate of 20 rounds a second, or 1200 rounds per minute - probably still much higher than the actual rate of fire. Just find what your weapon's intended firing rate is, and use the appropriate sleep value (60/rds per min). There are also commands to order a unit to fire at a target, or to use suppressive fire at a target, but I'm not familiar enough with how they work to see how they may or may not be more suitable here. Edited March 11, 2014 by dwringer Share this post Link to post Share on other sites
R4IDER 10 Posted March 12, 2014 Thanks for your replies guys. After plenty of tests I have found that the below only causes the server FPS to drop by 2 which obviously doesn't effect client FPS. if (!isServer) exitWith {}; private ["_veh","_targets","_target","_count"]; _veh = _this select 0; _veh setVehicleAmmo 1; _targets = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13]; _count = 0; _target = _targets select floor(random(count _targets)); sleep (0.2 + random 0.2); // Multiple scripts now much less likely to compete in the same frame while {(alive _veh)} do { _count = _count + 1; _veh doWatch _target; _veh action ["useWeapon", _veh, gunner _veh, 0]; sleep 0.05; if (_count == 25) then { doStop _veh; _count = 0; sleep 2; _veh setVehicleAmmo 1; _target = _targets select floor(random(count _targets));}; }; Share this post Link to post Share on other sites
R4IDER 10 Posted March 13, 2014 Well I have noticed a new problem now and at the moment I have no idea how to go about fixing it. The problem is no matter what sleeps you include in the while loop it slowly eats away at the client FPS, server FPS remains at 48 but for me for example using the below after around 10 minutes I go down from 60FPS to 5FPS. I have tried using ScopeName to ensure that the while loop is exited when it is no longer needed. When testing this code in the editor I take no FPS hit what so ever its only when this script is running on the server does my FPS start dropping. if (!isServer) exitWith {}; private ["_targets","_target","_count","_shoot"]; aa1 setVehicleAmmo 1; aa2 setVehicleAmmo 1; aa3 setVehicleAmmo 1; aa4 setVehicleAmmo 1; _targets = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13]; _count = 0; _shoot = true; _target = _targets select floor(random(count _targets)); sleep (0.2 + random 0.2); // Multiple scripts now much less likely to compete in the same frame scopeName "main"; while {_shoot} do { if (!alive aa1 && !alive aa2 && !alive aa3 && !alive aa4) then { _shoot = false; breakTo "main"; }; _count = _count + 1; aa1 doWatch _target; aa2 doWatch _target; aa3 doWatch _target; aa4 doWatch _target; sleep 0.05; if (_count <= 25) then { aa1 action ["useWeapon", aa1, gunner aa1, 0]; aa2 action ["useWeapon", aa2, gunner aa2, 0]; aa3 action ["useWeapon", aa3, gunner aa3, 0]; aa4 action ["useWeapon", aa4, gunner aa4, 0]; }; sleep 0.3; if (_count == 26) then { sleep (2 + random 0.2); doStop aa1; doStop aa2; doStop aa3; doStop aa4; _count = 0; aa1 setVehicleAmmo 1; aa2 setVehicleAmmo 1; aa3 setVehicleAmmo 1; aa4 setVehicleAmmo 1; _target = _targets select floor(random(count _targets)); }; }; Share this post Link to post Share on other sites
king_richard 10 Posted March 13, 2014 (edited) Not sure if this will work since I'm still learning arma scripting but may be worth a shot to see if it improves performance. Also note that I have not tested this code, and the "_x" parts is the area I'm unsure of, I usually have to test it out a few times to get those _x references down. if (!isServer) exitWith {}; private ["_targets","_target","_count","_shoot","AA"]; _AA = ["aa1", "aa2", "aa3", "aa4"]; aa1 setVehicleAmmo 1; aa2 setVehicleAmmo 1; aa3 setVehicleAmmo 1; aa4 setVehicleAmmo 1; _targets = [t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,t11,t12,t13]; _count = 0; _shoot = true; _target = _targets select floor(random(count _targets)); sleep (0.2 + random 0.2); // Multiple scripts now much less likely to compete in the same frame scopeName "main"; while {_shoot} do { // Could possibly group these AA then just count the # alive if (!alive aa1 && !alive aa2 && !alive aa3 && !alive aa4) then { _shoot = false; breakTo "main"; }; _count = _count + 1; // have the AA track the randomly selected target and fire { _x doWatch _target; sleep 0.05; _x action ["useWeapon", _x, gunner _x, 0]; } foreach _AA; // if (_count <= 25) then // no reason to have this check since you catch it at 26 anyways which will only fire one more time sleep 0.3; if (_count >= 26) then // greater or equal just incase even though it never should exceed 26 { sleep 2; // didn't see the reasoning for a random .02 added // stop AA fire and refill ammo { doStop _x; // but why stop if it's just going to loop right back through and watch again? _x setVehicleAmmo 1; sleep 0.05; } foreach _AA; _count = 0; _target = _targets select floor(random(count _targets)); }; }; For your client side performance issue. Perhaps you should exit this script at a given time and then restart it? Maybe that'd help. Edited script to remove semi colon's, and thank you F2k Sel. Edited March 13, 2014 by King_Richard Share this post Link to post Share on other sites
f2k sel 164 Posted March 13, 2014 I don't think there should be a ; between } ; foreach _aa; Share this post Link to post Share on other sites
R4IDER 10 Posted March 15, 2014 There seems to be some sort of bug with while loops in ARMA3. It doesn't matter what delay you put in them they always seem to reduce FPS. A while loop with a 2 second delay running for 1 hour will cause an FPS drop from 60 to 5. Even with nothing in the while loop other than the delay this is still the case. Share this post Link to post Share on other sites