Raised This Month: $ Target: $400
 0% 

Need help adding a delay


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Eagle
Junior Member
Join Date: Dec 2008
Old 12-28-2008 , 14:15   Need help adding a delay
Reply With Quote #1

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?
Eagle is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 12-28-2008 , 19:35   Re: Need help adding a delay
Reply With Quote #2

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.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Eagle
Junior Member
Join Date: Dec 2008
Old 12-29-2008 , 02:49   Re: Need help adding a delay
Reply With Quote #3

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
Eagle is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 12-29-2008 , 02:58   Re: Need help adding a delay
Reply With Quote #4

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.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:12.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode