CraveMode 16 Posted June 20, 2019 I am very new to scripting in SQF but I am not a stranger to modifying scripts to tweak and break things. However, trying to learn and one of the projects is very simple.. disable the Personal Aid Kit on our mission. I am not sure if it is an issue with multiple loops with "while", but hoping someone could assist me with what I am doing wrong or at least let me know if there are limitations with the initplayerlocal.sqf. The following is my entire initplayerlocal.sqf file but the code I am trying to get to work is at the bottom. // UnderCover Script initialization (Incontinentia's undercover / incognito simulation script for Arma 3) if (player getVariable ["isSneaky",false]) then { [player] execVM "TAC\scripts\INC_undercover\Scripts\initUCR.sqf"; }; // External camera view in Pilot seat of Helis while {true} do { waitUntil {cameraView == "External"}; if (vehicle player == player || !(vehicle player isKindOf "air") || player != driver vehicle player) then { player switchCamera "Internal"; }; sleep 0.10; }; // Remove PAKs from Inventories while {true} do { if ("ACE_personalAidKit" in items player) then { player removeItems "ACE_personalAidKit"; }; sleep 5; }; Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 20, 2019 one scripting goal should be to avoid to have a lots of endless while loops but what is your while loop for? maybe there is another way but idk why you need to check it every 5 seconds... A way I use to avoid multiple endless while loops is to use the cron manager script provided by @ussrlongbow. It checks every 0.5 second for jobs which need to be executed and it uses only one trigger for this. Using this I get rid of a bunch of while loops by just registering the while-content as a job. Also many while loops can be avoided by using Armas Event Handlers. Why to avoid multiple while loops? One point is that they prevent a script to get finished and therefore they may overload the script scheduler which has to handle those opened scripts. 2 Share this post Link to post Share on other sites
CraveMode 16 Posted June 20, 2019 Wow thank you Sarogahtyp, I appreciate the information and the suggestion. I have a lot to learn lol. 1 Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 20, 2019 what I forgot to mention is that the cron manager script is designed to run server side only. therefore you can't run it on client in its current state. But you could easily delete the if (isServer) conditions on the script files to get it work on clients... Share this post Link to post Share on other sites
CraveMode 16 Posted June 20, 2019 Yeah I am running a dedicated server so this is perfect, it is going to come in handy. Increasing performance is always a better option. Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 20, 2019 other useful stuff: Init order event scripts Script Optimization Array Stuff just ask if u need more ;-) 2 Share this post Link to post Share on other sites
sarogahtyp 1104 Posted June 20, 2019 huh, took a second look at your script... you cant just do two endless while loops behind each other. the second loop will never get executed at least how u do it. It can be done this way: [] spawn { while {true} do { your code }; }; [] spawn { while {true} do { your code }; }; spawn will spawn a new script and put it to script scheduler which takes care of it after that. 3 Share this post Link to post Share on other sites
CraveMode 16 Posted June 20, 2019 Ah figured I was doing it wrong. Thanks 😛 Share this post Link to post Share on other sites
Dedmen 2581 Posted June 21, 2019 On 6/20/2019 at 8:36 AM, CraveMode said: if ("ACE_personalAidKit" in items player) then { The performance on this can get VERY bad, as especially with ACE the number of items can become huge with stuff like bandages. ACE is implementing a new system for that in the next version which you can then use https://github.com/acemod/ACE3/pull/7064 1 Share this post Link to post Share on other sites
CraveMode 16 Posted June 21, 2019 2 hours ago, Dedmen said: The performance on this can get VERY bad, as especially with ACE the number of items can become huge with stuff like bandages. ACE is implementing a new system for that in the next version which you can then use https://github.com/acemod/ACE3/pull/7064 Thanks for the information. I actually steered away from using loops for this as @sarogahtyp has made me realize how good eventHandlers are. I have been able to make functions and creating an eventhandler "Take" to remove the PAK once someone puts it in their inventory and it works well. Once they implement the change, I will have no need for the script and that is fine by me! Surprised it wasn't included sooner. my functions loading this class file (I have multiple scripts in the file) removePak = { player addeventHandler ["Take",{ _unit = _this select 0; _pak = _this select 2; if(_pak isEqualTo "ACE_personalAidKit") then { player removeItems "ACE_personalAidKit"; }; }]; }; 1 Share this post Link to post Share on other sites