Jump to content

Sign in to follow this  
kolpo

Adding a cooldown to actions

Recommended Posts

For example I want the use of this:

onMapSingleClick "hint 'This action has a 5 second cooldown'";

To have a 5 seconds delay. Once you activate it can't you activate it again for 5 seconds

Share this post


Link to post
Share on other sites

Remove the action at the start of the script (incase you use addAction) and add a sleep of 5 secs (sleep 5) to the end before adding the action again.

Share this post


Link to post
Share on other sites

Cooldown = 0;
player addAction ["Action","script.sqf",[],1,true,true,"","Cooldown < 1"];

In script.sqf

Cooldown = 1;
//Your code
sleep 5;
Cooldown = 0;

Share this post


Link to post
Share on other sites

Thank you, with what you suggested as a basis have I come up with something that does what I want to do:

On player unit init : cooldown=0; onMapSingleClick "If (_alt) then { temp = execVM 'cooldown.sqf'}";

cooldown.sqf: if (cooldown<1) then {hint "allowed";cooldown = 1; sleep 5; cooldown=0}

Share this post


Link to post
Share on other sites

EDIT: I found an answer myself to my second question, I think this shall let it work with more then 1 player. I shall ask a friend to test it with me later online to make sure it works:

On each playable unit init : this setVariable ["cooldown", 0, false]; onMapSingleClick "If (_alt) then { temp = execVM 'cooldown.sqf'}";

cooldown.sqf: if (player getVariable "cooldown"<1) then {hint "allowed";player setVariable ["cooldown", 1, false]; sleep 5; player setVariable ["cooldown", 0, false];}

Edited by kolpo

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  

×