AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need help adding a delay (https://forums.alliedmods.net/showthread.php?t=82708)

Eagle 12-28-2008 14:15

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?

Hawk552 12-28-2008 19:35

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:
#define MIN_TIME 5 #define MAX_HITS 3 new g_Time[33] new g_Hits[33] public TeammateDamage(Attacker) {     new CurTime = get_gametime()     g_Hits[Attacker] = (CurTime - g_Time[Attacker] < MIN_TIME) ? g_Hits[Attacker] + 1 : 1     if(g_Hits[Attacker] > MAX_HITS)     {         /* Perform your action */     }     g_Time[Attacker] = CurTime }

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.

Eagle 12-29-2008 02:49

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

Hawk552 12-29-2008 02:58

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:
new CurTime = get_gametime()

This should be:

Code:
new Float:CurTime = get_gametime()

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.