Jump to content
Sign in to follow this  
A-SUICIDAL

How do I prevent mutiple instances of 1 script from running?

Recommended Posts

It's hard to explain an example of this. I have a punish script that when you kill a friendly unit or civilian it executes a script that punishes the player, and lets say that I just accidentally killed 3 teammates. I want to then execute a script that actually punishes the player and does a bunch of stuff, but I do not want the script to run multiple times, in this case 3 times for each of the 3 teammates that were killed. I tried adding a counter that first counts the kills, then pauses for a second and then executes a script based on the counted kills being >0. And then after the punish script finishes it sets the kill count back to 0 again. But so far I can't even get this to work. So I figured that I need to try a different method, but I first wanted to find out what other methods might be possible.

So is it possible, once a script starts running, to prevent the same script from running again until the original script has finished? Basically prevent 1 script from running multiple times.

So if I kill 3 teammates, it then executes only 1 punish script.

My punish script is working great, but there are times when I kill more than one teammate with something like an explosion where the punish script then runs multiple times and just seems freaky.

Share this post


Link to post
Share on other sites

Start your script function with something like:

if (player getVariable ["TAG_isPunished", false]) exitWith{};
player setVariable ["TAG_isPunished", true];

Hope that helps.

Edit: Of course, whenever your punishment is finished,

player setVariable ["TAG_isPunished", false];

Share this post


Link to post
Share on other sites

I will try that now.

I did manage to get it to work by adding this to my init.sqf:

s1_KillCount = 0;
s1_Killer = false;
publicVariable "s1_killer";

Later when a teammate or civilian is killed, it set it to be:

s1_Killer = true;
publicVariable "s1_killer";

Then I added a repeating trigger in the mission with the condition:

s1_Killer

and in the On Act:

s1_KillCount = s1_KillCount +1;

Then I added another repeating trigger with the condition:

s1KillCount == 1

and in the "On Act":

null = [s1] execVM "jail\punish.sqf";

Now if I blow up three enemy with a grenade, it only runs the punish script 1 time, and at the end of the punish script, just as it releases the player from jail, it sets it back to:

"s1_KillCount = 0;"
s1_Killer = false;
publicVariable "s1_killer";

Edited by A-SUICIDAL

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
Sign in to follow this  

×