Jump to content
CraveMode

Disable PAK through initplayerlocal.sqf Issue

Recommended Posts

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

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.

  • Like 2

Share this post


Link to post
Share on other sites

Wow thank you Sarogahtyp, I appreciate the information and the suggestion. I have a lot to learn lol. 

  • Like 1

Share this post


Link to post
Share on other sites

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

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

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.

  • Like 3

Share this post


Link to post
Share on other sites

Ah figured I was doing it wrong. Thanks 😛 

Share this post


Link to post
Share on other sites
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

  • Like 1

Share this post


Link to post
Share on other sites
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";
};
}];
};

 

  • Like 1

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

×