Need help adding a delay
When an action is triggered, for instance, when you attack a teammate multiple times in a short amount of time like attack your teammate 3 times within a second, how do you add a delay so that that action will be called after like 5 seconds to prevent that action from spamming over and over again?
|
Re: Need help adding a delay
You can use a cooldown timer.
Create two global variables: one that tracks time and another that tracks hits. Next, in the function where damage is done, check if the current time minus the time stored in the variable is less than the allowed time. If it is, raise the tracked hits. Next, check if the tracked hits is higher than your allowed value and if it's not do whatever action you think is appropriate. Here's a skeletal version of what I just said: Code:
I left out a lot of stuff, such as the hook for damage, but by the way you asked it sounds like you already know how to do everything else. |
Re: Need help adding a delay
So far so good, but when I try to compile, I get a tag mismatch for the following line:
Code:
g_Hits[Attacker] = (CurTime - g_Time[Attacker] < MIN_TIME) ? g_Hits[Attacker] + 1 : 1 |
Re: Need help adding a delay
It's actually on the previous line, sorry. I didn't bother compiling it or testing it. The problem is here:
Code:
This should be: Code:
Tag mismatches aren't important though and can be ignored unless you're releasing it. |
| All times are GMT -4. The time now is 09:12. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.