Raised This Month: $ Target: $400
 0% 

How to reset or close a timer before it fired


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xuxinsheng1
Junior Member
Join Date: May 2013
Old 02-05-2015 , 09:21   How to reset or close a timer before it fired
Reply With Quote #1

sorry my bad English

I create a function to make player move slowly:

PHP Code:
public OnPlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
iUserid GetClientOfUserId(GetEventInt(event"userid"));
    
SetEntPropFloat(iUseridProp_Data"m_flMaxspeed"45);
    
CreateTimer(1Reset_Movespeed_FunctioniUserid);

but now if some one do 2 shoots in first second,victim's speed will be reset by that CreateTimer
How can reset that Timer Interval to 1 second at every shoot.
Or it can be close by another command,I will restart a new timer with 1 second
please help me please
I very need help as fast as possible

Thank every one read my thread thanks
xuxinsheng1 is offline
th7nder
Senior Member
Join Date: Oct 2014
Old 02-05-2015 , 09:31   Re: How to reset or close a timer before it fired
Reply With Quote #2

Just store timer in Handle and then KillTimer(handle);
th7nder is offline
xuxinsheng1
Junior Member
Join Date: May 2013
Old 02-05-2015 , 11:46   Re: How to reset or close a timer before it fired
Reply With Quote #3

Quote:
Originally Posted by th7nder View Post
Just store timer in Handle and then KillTimer(handle);
I do this but not work
PHP Code:
new Handle:MoveTHandle INVALID_HANDLE;
public 
OnPlayerHurt(Handle:event, const String:name[], bool:dontBroadcast

    
KillTimer(MoveTHandle);
    new 
iUserid GetClientOfUserId(GetEventInt(event"userid")); 
    
SetEntPropFloat(iUseridProp_Data"m_flMaxspeed"45); 
    
MoveTHandle CreateTimer(1Reset_Movespeed_FunctioniUserid); 

any command not work in these,even "SetEntPropFloat" and "new iUserid"
what's wrong
xuxinsheng1 is offline
Kailo
Senior Member
Join Date: Sep 2014
Location: Moscow, Russia
Old 02-05-2015 , 12:19   Re: How to reset or close a timer before it fired
Reply With Quote #4

My code was wrong, see code below!

Last edited by Kailo; 02-05-2015 at 12:28.
Kailo is offline
ici
Member
Join Date: Jan 2014
Old 02-05-2015 , 12:22   Re: How to reset or close a timer before it fired
Reply With Quote #5

PHP Code:
#pragma semicolon 1

#include <sourcemod>

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

public 
OnPluginStart()
{
    
HookEvent("player_hurt"Event_PlayerHurt);
}

public 
OnClientDisconnect(client)
{
    if (
gH_Timers[client] != INVALID_HANDLE)
    {
        
KillTimer(gH_Timers[client]);
        
gH_Timers[client] = INVALID_HANDLE;
    }
}

public 
Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
userid GetEventInt(event"userid");
    new 
client GetClientOfUserId(userid);
    
    if (!
client || !IsClientInGame(client))
        return;
    
    
SetEntPropFloat(clientProp_Data"m_flMaxspeed"45.0);
    
    if (
gH_Timers[client] != INVALID_HANDLE)
    {
        
KillTimer(gH_Timers[client]);
        
gH_Timers[client] = INVALID_HANDLE;
    }
    
    
gH_Timers[client] = CreateTimer(1.0Reset_Movespeed_Functionuserid);
}

public 
Action:Reset_Movespeed_Function(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    
    if (!
client || !IsClientInGame(client))
        return;

    
gH_Timers[client] = INVALID_HANDLE;
    
    
// do stuff ...
    
    // The return value has no meaning for one-time timers.


Last edited by ici; 02-05-2015 at 16:26.
ici is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 02-05-2015 , 15:38   Re: How to reset or close a timer before it fired
Reply With Quote #6

Don't pass a client index through a timer. Always use GetClientUserId and GetClientOfUserId.

This is because the client may be replaced (disconnect and a new player takes the client index) while the timer is waiting to fire.

GetClientOfUserId will return 0 if the client is no longer connected
__________________
Neuro Toxin is offline
ici
Member
Join Date: Jan 2014
Old 02-05-2015 , 16:19   Re: How to reset or close a timer before it fired
Reply With Quote #7

Thanks for the info bro.

Btw, I've seen people pass the client's unique serial identifier (GetClientSerial).

What is this actually? Is it better to pass that than the userid?

Edit:
Found some information about client serials.
https://forums.alliedmods.net/showpo...90&postcount=4

Last edited by ici; 02-05-2015 at 16:39.
ici is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 02-05-2015 , 21:07   Re: How to reset or close a timer before it fired
Reply With Quote #8

I believe userid is better as its an int value.
__________________
Neuro Toxin is offline
xuxinsheng1
Junior Member
Join Date: May 2013
Old 02-05-2015 , 21:35   Re: How to reset or close a timer before it fired
Reply With Quote #9

Quote:
Originally Posted by ici View Post
PHP Code:
#pragma semicolon 1

#include <sourcemod>

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

public 
OnPluginStart()
{
    
HookEvent("player_hurt"Event_PlayerHurt);
}

public 
OnClientDisconnect(client)
{
    if (
gH_Timers[client] != INVALID_HANDLE)
    {
        
KillTimer(gH_Timers[client]);
        
gH_Timers[client] = INVALID_HANDLE;
    }
}

public 
Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
userid GetEventInt(event"userid");
    new 
client GetClientOfUserId(userid);
    
    if (!
client || !IsClientInGame(client))
        return;
    
    
SetEntPropFloat(clientProp_Data"m_flMaxspeed"45.0);
    
    if (
gH_Timers[client] != INVALID_HANDLE)
    {
        
KillTimer(gH_Timers[client]);
        
gH_Timers[client] = INVALID_HANDLE;
    }
    
    
gH_Timers[client] = CreateTimer(1.0Reset_Movespeed_Functionuserid);
}

public 
Action:Reset_Movespeed_Function(Handle:timerany:userid)
{
    new 
client GetClientOfUserId(userid);
    
    if (!
client || !IsClientInGame(client))
        return;

    
gH_Timers[client] = INVALID_HANDLE;
    
    
// do stuff ...
    
    // The return value has no meaning for one-time timers.

thank you very much that worked!!!!!

)))))))))))))))))))))))))))))))))))))))

thanks thanks very thanks


and thanks every one
xuxinsheng1 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:17.


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