Raised This Month: $51 Target: $400
 12% 

[SOLVED] Few Timers Work


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
thecount
Veteran Member
Join Date: Jul 2013
Old 06-17-2014 , 15:40   [SOLVED] Few Timers Work
Reply With Quote #1

So I have about 4 or 5 timers in my plugin, and only 1 or 2 work. I've gone over to see if I've made them in different ways but they seem to be same syntax. Plugin compiles and everything, but when in-game nothing happens and it says something about an invalid timer handle.

Example of Timer:
PHP Code:
new Handle:h_kickall INVALID_HANDLE;
h_kickall CreateTimer(12.0Timer_KickAll);

public 
Action:Timer_KickAll(Handle:timer){
    new 
String:daTeam[25];
    if(
winnerByte == CS_TEAM_T){
        
Format(daTeamsizeof(daTeam), "Terrorists");
    }else{
        if(
winnerByte == CS_TEAM_CT){
            
Format(daTeamsizeof(daTeam), "Counter-Terrorists");
        }else{
            
Format(daTeamsizeof(daTeam), "Nobody");
        }
    }
    for(new 
i=1;i<11;i++){
        
KickClient(i"Match over: %s won"daTeam);
    }
    
ServerCommand("quit");
    
CloseHandle(h_kickall);
    return 
Plugin_Continue;

Thanks if you can help.

Last edited by thecount; 06-18-2014 at 18:33.
thecount is offline
xf117
Senior Member
Join Date: Mar 2010
Location: Russia
Old 06-17-2014 , 16:08   Re: Few Timers Work
Reply With Quote #2

Never close timer's handle inside itself.
PHP Code:
public Action:Timer_KickAll(Handle:timer){
    new 
String:daTeam[25];
    if(
winnerByte == CS_TEAM_T){
        
Format(daTeamsizeof(daTeam), "Terrorists");
    }else{
        if(
winnerByte == CS_TEAM_CT){
            
Format(daTeamsizeof(daTeam), "Counter-Terrorists");
        }else{
            
Format(daTeamsizeof(daTeam), "Nobody");
        }
    }
    for(new 
i=1;i<11;i++){
        
KickClient(i"Match over: %s won"daTeam);
    }
    
ServerCommand("quit");
    
h_kickall INVALID_HANDLE;
    return 
Plugin_Handled;

xf117 is offline
Send a message via ICQ to xf117
thecount
Veteran Member
Join Date: Jul 2013
Old 06-17-2014 , 16:25   Re: Few Timers Work
Reply With Quote #3

Quote:
Originally Posted by xf117 View Post
Never close timer's handle inside itself.
Ok I changed that but still doesn't call the timer.
thecount is offline
sheo
SourceMod Donor
Join Date: Jul 2013
Location: Russia, Moscow
Old 06-17-2014 , 16:37   Re: Few Timers Work
Reply With Quote #4

Quote:
Originally Posted by thecount View Post
PHP Code:
for(new i=1;i<11;i++){
        
KickClient(i"Match over: %s won"daTeam);
    } 
You need some extra checks for valid players here (is in game, is not a bot...)
__________________

Last edited by sheo; 06-17-2014 at 16:37.
sheo is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 06-17-2014 , 16:55   Re: Few Timers Work
Reply With Quote #5

Quote:
Originally Posted by sheo View Post
You need some extra checks for valid players here (is in game, is not a bot...)
Still doesn't work after adding that.
thecount is offline
sheo
SourceMod Donor
Join Date: Jul 2013
Location: Russia, Moscow
Old 06-17-2014 , 17:02   Re: Few Timers Work
Reply With Quote #6

Post your error than
__________________
sheo is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-17-2014 , 17:07   Re: Few Timers Work
Reply With Quote #7

Are you using global Handle at all... ?
You could just createtimer without it.

PHP Code:


that_callback_which_team_won
()
{
    ...

    
CreateTimer(12.0timer_kickallteam);
    ...
}

public 
Action:timer_kickall(Handle:timerany:team)
{
    for(new 
1<= MaxClientsi++)
    {
        if(
IsClientConnected(i) && !IsFakeClient(i))
        {
            
KickClient(i" \n Match over: %s won"team == "Terrorists":(team == "Counter-Terrorists":"Nobody") );
        }
    }

    
ServerCommand("quit");

Bacardi is offline
thecount
Veteran Member
Join Date: Jul 2013
Old 06-17-2014 , 18:24   Re: Few Timers Work
Reply With Quote #8

Quote:
Originally Posted by Bacardi View Post
Are you using global Handle at all... ?
You could just createtimer without it.
Ok I got rid of the global handle and changed the timer to your sample code, but still doesn't call the action when the timer ends.

Error:
HTML Code:
[SM] Invalid timer handle 820078 (error 3) during timer end, displayed function is timer callback, not the stack trace
thecount is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 06-18-2014 , 01:43   Re: Few Timers Work
Reply With Quote #9

show your code, all of it
Bacardi is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 06-18-2014 , 09:47   Re: Few Timers Work
Reply With Quote #10

I've never found a use to actually save a timer's handle, as you could just check a boolean before any of the functions in side the timer fire, and just return it to stop. (it'll free up the handle too)
Maybe i'm missing something though. Also there is the repeat flag, and no map change flag, that also helps.
Mitchell 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 00:56.


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