Raised This Month: $ Target: $400
 0% 

Killing Timer Fixed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 05-23-2015 , 16:42   Killing Timer Fixed
Reply With Quote #1

Hey guys,

I am having trouble killing a timer on round end. Any help would be greatly appreciated.

PHP Code:
public Action:roundEnd(Handle:event, const String:name[], bool:dontBroadcast
{
    
ServerCommand("sm_gravity @all 1");
    
GravityFreeday 0;
    
KillTimer(WardayExpand);
    
KillTimer(WardayStart);

PHP Code:
public Action:WardayExpand(Handle:timer)
{
    
PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01")
    
PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01")
    
PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01")
    
PrintHintTextToAll("Warday has expanded")
}

public 
Action:WardayStart(Handle:timer)
{
    
PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01")
    
PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01")
    
PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01")
    
PrintHintTextToAll("Warday has started")

Errors:
Code:
.../warden/wardenmenu.sp(421) : error 130: cannot coerce functions to values
.../warden/wardenmenu.sp(422) : error 130: cannot coerce functions to values

//
// 2 Errors.
//

Last edited by Addicted.; 06-15-2015 at 22:21.
Addicted. is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 05-23-2015 , 16:56   Re: [Help] Killing Timer
Reply With Quote #2

WardayExpand and WardayStart it isn't timer handle, it is timer handler. You need register global handle (named MyTimerHandle). When you start timer you need replace
Code:
CreateTimer(<time>, WardayExpand);
on
Code:
MyTimerHandle = CreateTimer(<time>, WardayExpand);
When in the right place you use
Code:
KillTimer(MyTimerHandle);

Last edited by Kailo; 05-23-2015 at 16:57.
Kailo is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 05-24-2015 , 10:30   Re: [Help] Killing Timer
Reply With Quote #3

I guess I was wrong, I am no longer getting that error but the timers still carry out past the round end.

PHP Code:
new Handle:WardayStartTimer;
new 
Handle:WardayExpandTimer;

public 
wardayfreezetime(Handle:menuMenuAction:actionclientitemNum)
{
    if ( 
action == MenuAction_Select )
    {
        switch (
itemNum)
        {
            case 
0:
            {
                
WardayStartTimer CreateTimer(30.0WardayStart);
                new 
Handle:menu CreateMenu(wardayexpandtime);
                
SetMenuTitle(menu"Warday - Expand Time");
                
AddMenuItem(menu"option1""In 3 Minutes");
                
AddMenuItem(menu"option2""In 4 Minutes");
                
AddMenuItem(menu"option3""In 5 Minutes");
                
AddMenuItem(menu"option5""In 6 Minutes");
                
SetMenuExitButton(menutrue);
                
DisplayMenu(menuclientMENU_TIME_FOREVER);
                
                
ServerCommand("sm_freeze @t 30");
                
PrintToChatAll("[\x07Warden\x01] \x04Warday will start in\x01 \x0730\x01 \x04seconds!\x01");
                
PrintToChatAll("[\x07Warden\x01] \x04Guards, remember to open the cells before the freezetime is over.\x01");
            }
            case 
1:
            {
                
WardayStartTimer CreateTimer(45.0WardayStart);
                new 
Handle:menu CreateMenu(wardayexpandtime);
                
SetMenuTitle(menu"Warday - Expand Time");
                
AddMenuItem(menu"option1""In 3 Minutes");
                
AddMenuItem(menu"option2""In 4 Minutes");
                
AddMenuItem(menu"option3""In 5 Minutes");
                
AddMenuItem(menu"option5""In 6 Minutes");
                
SetMenuExitButton(menutrue);
                
DisplayMenu(menuclientMENU_TIME_FOREVER);
                
                
ServerCommand("sm_freeze @t 45");
                
PrintToChatAll("[\x07Warden\x01] \x04Warday will start in\x01 \x0745\x01 \x04seconds!\x01");
                
PrintToChatAll("[\x07Warden\x01] \x04Guards, remember to open the cells before the freezetime is over.\x01");
            }
            case 
2:
            {
                
WardayStartTimer CreateTimer(60.0WardayStart);
                new 
Handle:menu CreateMenu(wardayexpandtime);
                
SetMenuTitle(menu"Warday - Expand Time");
                
AddMenuItem(menu"option1""In 3 Minutes");
                
AddMenuItem(menu"option2""In 4 Minutes");
                
AddMenuItem(menu"option3""In 5 Minutes");
                
AddMenuItem(menu"option5""In 6 Minutes");
                
SetMenuExitButton(menutrue);
                
DisplayMenu(menuclientMENU_TIME_FOREVER);
                
                
ServerCommand("sm_freeze @t 60");
                
PrintToChatAll("[\x07Warden\x01] \x04Warday will start in\x01 \x0760\x01 \x04seconds!\x01");
                
PrintToChatAll("[\x07Warden\x01] \x04Guards, remember to open the cells before the freezetime is over.\x01");
            }
        }
    }
    else if (
action == MenuAction_End )
    {
    
CloseHandle(menu);
    } 
}

public 
wardayexpandtime(Handle:menuMenuAction:actionclientitemNum)
{
    if ( 
action == MenuAction_Select )
    {
        switch (
itemNum)
        { 
            case 
0:
            {
                
PrintToChatAll("[\x07Warden\x01] \x04Warday will expand in\x01 \x073\x01 \x04minutes!\x01");
                
WardayExpandTimer CreateTimer(180.0WardayExpand);
            }
            case 
1:
            {
                
PrintToChatAll("[\x07Warden\x01] \x04Warday will expand in\x01 \x074\x01 \x04minutes!\x01");
                
WardayExpandTimer CreateTimer(240.0WardayExpand);
            }
            
            case 
2:
            {
                
PrintToChatAll("[\x07Warden\x01] \x04Warday will expand in\x01 \x075\x01 \x04minutes!\x01");
                
WardayExpandTimer CreateTimer(300.0WardayExpand);
            }
            
            case 
3:
            {
                
PrintToChatAll("[\x07Warden\x01] \x04Warday will expand in\x01 \x076\x01 \x04minutes!\x01");
                
WardayExpandTimer CreateTimer(360.0WardayExpand);
            }
        }
    }
    else if (
action == MenuAction_End )
    {
    
CloseHandle(menu);
    } 
}

public 
Action:roundEnd(Handle:event, const String:name[], bool:dontBroadcast
{
    
ServerCommand("sm_gravity @all 1");
    
GravityFreeday 0;
    
KillTimer(WardayExpandTimer);
    
KillTimer(WardayStartTimer);

Addicted. is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 05-24-2015 , 11:55   Re: [Help] Killing Timer
Reply With Quote #4

Are you creating multiple of each timer?
Miu is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 05-24-2015 , 12:07   Re: [Help] Killing Timer
Reply With Quote #5

Quote:
Originally Posted by Miu View Post
Are you creating multiple of each timer?
No, each one is an option in a menu. Only the Warden can access the menu and pick one item.
Addicted. is offline
abgar
Senior Member
Join Date: Apr 2015
Old 05-25-2015 , 04:25   Re: [Help] Killing Timer
Reply With Quote #6

Change the global handles to:

new Handle:WardayStartTimer[MAXPLAYERS+1];
new
Handle:WardayExpandTimer
[MAXPLAYERS+1];

Change each 'CreateTimer' to be like this:
WardayStartTimer[client] = CreateTimer(30.0, WardayStart);

To kill the timer,
KillTimer(WardayExpandTimer[client]);
KillTimer(WardayStartTimer
[client]);

That should hopefully resolve it?
abgar is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 05-25-2015 , 13:00   Re: [Help] Killing Timer
Reply With Quote #7

Quote:
Originally Posted by abgar View Post
Change the global handles to:

new Handle:WardayStartTimer[MAXPLAYERS+1];
new
Handle:WardayExpandTimer
[MAXPLAYERS+1];

Change each 'CreateTimer' to be like this:
WardayStartTimer[client] = CreateTimer(30.0, WardayStart);

To kill the timer,
KillTimer(WardayExpandTimer[client]);
KillTimer(WardayStartTimer
[client]);

That should hopefully resolve it?

Then I would have to define client in each of the menus which I don't think is necessary.

I'll try it later when I get a chance.
Addicted. is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 05-26-2015 , 00:40   Re: [Help] Killing Timer
Reply With Quote #8

So I tried that out and I still have no luck, anyone else have ideas?
Addicted. is offline
DorCoMaNdO
Senior Member
Join Date: Feb 2012
Old 05-26-2015 , 01:25   Re: [Help] Killing Timer
Reply With Quote #9

Code:
new Handle:WardayStartTimer; 
new Handle:WardayExpandTimer; 

public wardayfreezetime(Handle:menu, MenuAction:action, client, itemNum) 
{
	if (action == MenuAction_Select)
	{
		new freezetime = 30 + (15 * itemNum);
		WardayStartTimer = CreateTimer(Float:freezetime, WardayStart); 
		new Handle:expandmenu = CreateMenu(wardayexpandtime); 
		SetMenuTitle(expandmenu, "Warday - Expand Time"); 
		AddMenuItem(expandmenu, "option1", "In 3 Minutes"); 
		AddMenuItem(expandmenu, "option2", "In 4 Minutes"); 
		AddMenuItem(expandmenu, "option3", "In 5 Minutes"); 
		AddMenuItem(expandmenu, "option5", "In 6 Minutes"); 
		SetMenuExitButton(expandmenu, true); 
		DisplayMenu(expandmenu, client, MENU_TIME_FOREVER); 
		 
		ServerCommand("sm_freeze @t %d", freezetime); 
		PrintToChatAll("[\x07Warden\x01] \x04Warday will start in\x01 \x07%d\x01 \x04seconds!", freezetime); 
		PrintToChatAll("[\x07Warden\x01] \x04Guards, remember to open the cells before the freezetime is over."); 
	} 
	else if (action == MenuAction_End)
	{ 
		CloseHandle(menu); 
	}  
} 

public wardayexpandtime(Handle:menu, MenuAction:action, client, itemNum) 
{ 
	if ( action == MenuAction_Select ) 
	{ 
		PrintToChatAll("[\x07Warden\x01] \x04Warday will expand in\x01 \x073\x01 \x04minutes!\x01", itemNum + 3); 
		WardayExpandTimer = CreateTimer((itemNum + 3) * 60.0, WardayExpand); 
	} 
	else if (action == MenuAction_End ) 
	{ 
		CloseHandle(menu); 
	}  
} 

public Action:roundEnd(Handle:event, const String:name[], bool:dontBroadcast)  
{ 
	ServerCommand("sm_gravity @all 1"); 
	GravityFreeday = 0;
	if(WardayExpandTimer != INVALID_HANDLE) KillTimer(WardayExpandTimer); 
	WardayExpandTimer = INVALID_HANDLE;
	if(WardayStartTimer != INVALID_HANDLE) KillTimer(WardayStartTimer); 
	WardayStartTimer = INVALID_HANDLE;
}  

public Action:WardayExpand(Handle:timer)
{
	if(WardayExpandTimer != timer) return Plugin_Stop;
	
	WardayExpandTimer = INVALID_HANDLE;
	
	PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01");
	PrintHintTextToAll("Warday has expanded");
	
	 
	return Plugin_Stop;
}

public Action:WardayStart(Handle:timer)
{
	if(WardayStartTimer != timer) return Plugin_Stop;
	
	WardayStartTimer = INVALID_HANDLE;
	
	PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01");
	PrintHintTextToAll("Warday has started");
	
	return Plugin_Stop;
}
I think this will work, didn't test it though, I usually use CloseHandle to kill timers, so if it still fails, replace KillTimer with CloseHandle.
I cleaned up some stuff for you.
DorCoMaNdO is offline
Addicted.
AlliedModders Donor
Join Date: Dec 2013
Location: 0xA9D0DC
Old 05-26-2015 , 09:16   Re: [Help] Killing Timer
Reply With Quote #10

Quote:
Originally Posted by DorCoMaNdO View Post
Code:
new Handle:WardayStartTimer; 
new Handle:WardayExpandTimer; 

public wardayfreezetime(Handle:menu, MenuAction:action, client, itemNum) 
{
	if (action == MenuAction_Select)
	{
		new freezetime = 30 + (15 * itemNum);
		WardayStartTimer = CreateTimer(Float:freezetime, WardayStart); 
		new Handle:expandmenu = CreateMenu(wardayexpandtime); 
		SetMenuTitle(expandmenu, "Warday - Expand Time"); 
		AddMenuItem(expandmenu, "option1", "In 3 Minutes"); 
		AddMenuItem(expandmenu, "option2", "In 4 Minutes"); 
		AddMenuItem(expandmenu, "option3", "In 5 Minutes"); 
		AddMenuItem(expandmenu, "option5", "In 6 Minutes"); 
		SetMenuExitButton(expandmenu, true); 
		DisplayMenu(expandmenu, client, MENU_TIME_FOREVER); 
		 
		ServerCommand("sm_freeze @t %d", freezetime); 
		PrintToChatAll("[\x07Warden\x01] \x04Warday will start in\x01 \x07%d\x01 \x04seconds!", freezetime); 
		PrintToChatAll("[\x07Warden\x01] \x04Guards, remember to open the cells before the freezetime is over."); 
	} 
	else if (action == MenuAction_End)
	{ 
		CloseHandle(menu); 
	}  
} 

public wardayexpandtime(Handle:menu, MenuAction:action, client, itemNum) 
{ 
	if ( action == MenuAction_Select ) 
	{ 
		PrintToChatAll("[\x07Warden\x01] \x04Warday will expand in\x01 \x073\x01 \x04minutes!\x01", itemNum + 3); 
		WardayExpandTimer = CreateTimer((itemNum + 3) * 60.0, WardayExpand); 
	} 
	else if (action == MenuAction_End ) 
	{ 
		CloseHandle(menu); 
	}  
} 

public Action:roundEnd(Handle:event, const String:name[], bool:dontBroadcast)  
{ 
	ServerCommand("sm_gravity @all 1"); 
	GravityFreeday = 0;
	if(WardayExpandTimer != INVALID_HANDLE) KillTimer(WardayExpandTimer); 
	WardayExpandTimer = INVALID_HANDLE;
	if(WardayStartTimer != INVALID_HANDLE) KillTimer(WardayStartTimer); 
	WardayStartTimer = INVALID_HANDLE;
}  

public Action:WardayExpand(Handle:timer)
{
	if(WardayExpandTimer != timer) return Plugin_Stop;
	
	WardayExpandTimer = INVALID_HANDLE;
	
	PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07expanded!\x01");
	PrintHintTextToAll("Warday has expanded");
	
	 
	return Plugin_Stop;
}

public Action:WardayStart(Handle:timer)
{
	if(WardayStartTimer != timer) return Plugin_Stop;
	
	WardayStartTimer = INVALID_HANDLE;
	
	PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01");
	PrintToChatAll("[\x07Warden\x01] Warday has \x07started!\x01");
	PrintHintTextToAll("Warday has started");
	
	return Plugin_Stop;
}
I think this will work, didn't test it though, I usually use CloseHandle to kill timers, so if it still fails, replace KillTimer with CloseHandle.
I cleaned up some stuff for you.
That works for killing the timer but the WardayStartTimer gets called instantly. The other timer works perfectly with the menu options.
Addicted. 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 09:58.


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