Raised This Month: $ Target: $400
 0% 

A little help with timers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ScorpFire
Member
Join Date: Sep 2011
Old 07-01-2012 , 08:36   A little help with timers
Reply With Quote #1

Ok guys on my css server i am scripting the with the following code.

If T knife CT, CT has 3 seconds to knife any T or he will explode.
Code:
if(T knife CT ....)
{
    CreateTimer(3.0, ByeZM, client);
    g_ctExplode[attacker] = true;
}

if(CT knife T ....)
{    
    g_ctExplode[attacker] = false;
}

public Action:ByeZM(Handle:timer, any:client)
{
    if (g_ctExplode[client])
    {
        explodect;
    }
}
Im just simplifying the code so its easier to understand.

What i want to know is: Even though a CT manages to catch a T, the ByeZM timer is still running. Is there any way to cancel the timer?
ScorpFire is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 07-01-2012 , 09:15   Re: A little help with timers
Reply With Quote #2

Close the Handle of the timer.

Yours sincerely
Impact
__________________
Impact123 is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 07-01-2012 , 11:49   Re: A little help with timers
Reply With Quote #3

you're also going to want to have something like:

new Handle:ClientTimer[MAXPLAYERS+1] = {INVALID_HANDLE, ...};

Use that global handle and when you're creating a timer for a specific player use:

ClientTimer[client] = CreateTimer(3.0, ByeZM, client);

Your code with suggestions:
PHP Code:
new Handle:ClientTimer[MAXPLAYERS+1] = {INVALID_HANDLE, ...};

if(
T knife CT ....)
{
    
ClientTimer[client] = CreateTimer(3.0ByeZMclient);
    
g_ctExplode[attacker] = true;
}

if(
CT knife T ....)
{    
    
g_ctExplode[attacker] = false;

    if (
ClientTimer[attacker] != INVALID_HANDLE)
    {
        
KillTimer(ClientTimer[attacker]);
        
ClientTimer[attacker] = INVALID_HANDLE;
    }
}

public 
Action:ByeZM(Handle:timerany:client)
{
    
ClientTimer[client] = INVALID_HANDLE;

    if (
g_ctExplode[client])
    {
        
explodect;
    }

__________________
View my Plugins | Donate
TnTSCS is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 07-01-2012 , 14:08   Re: A little help with timers
Reply With Quote #4

Quote:
Originally Posted by Impact123 View Post
Close the Handle of the timer.

Yours sincerely
Impact
You mean KillTimer the timer, right? Right?
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 07-01-2012 , 15:27   Re: A little help with timers
Reply With Quote #5

Quote:
Originally Posted by Powerlord View Post
You mean KillTimer the timer, right? Right?
I had a lot of touble with KillTimer, never really worked out for me.
I normally just close the handle of the timer, why?

Yours sincerely
Impact
__________________

Last edited by Impact123; 07-01-2012 at 15:28.
Impact123 is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 07-01-2012 , 20:31   Re: A little help with timers
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
Quote:
Originally Posted by Impact123 View Post
Close the Handle of the timer.

Yours sincerely
Impact
You mean KillTimer the timer, right? Right?
Closing the handle is a valid method. Quoted from the wiki:

All timers are guaranteed to die either by:
  • CloseHandle() being called (or on plugin unload);
  • KillTimer() being called;
  • Plugin_Stop being returned from a repeatable timer;
  • TriggerTimer() being called on a one-time timer;
  • Execution of a one-time timer finishes.
__________________
11530 is offline
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 07-01-2012 , 21:24   Re: A little help with timers
Reply With Quote #7

yes, but the OP did not have a mechanism in place to know the handle of the timer... so, unless something like the example I posted is implemented, you can't use CloseHandle, amirite?
__________________
View my Plugins | Donate
TnTSCS is offline
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 23:52.


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