Raised This Month: $32 Target: $400
 8% 

Is it possible to check how much time is left on a timer I create?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ronmelkhior
Member
Join Date: Aug 2013
Old 11-12-2013 , 14:05   Is it possible to check how much time is left on a timer I create?
Reply With Quote #1

I'm trying to do a cooldown rate, but I also want to display in the cooldown message how much time they have left until they have.
ronmelkhior is offline
ecca
Sexy Santa
Join Date: Jan 2011
Old 11-12-2013 , 14:16   Re: Is it possible to check how much time is left on a timer I create?
Reply With Quote #2

I usually do like this , not sure if another way exists , and ofc if you have clients you need to put it in the int and so on. Also you have to reset it to 20 when it expires and so on.

PHP Code:
new TimeLeftOnTimer 20//If you start it on 20

timer function()
{
       
TimeLeftOnTimer--;
       
PrintToChat(client"Time left on timer is , %i"TimeLeftOnTimer);

__________________

Last edited by ecca; 11-12-2013 at 14:18.
ecca is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 11-12-2013 , 15:59   Re: Is it possible to check how much time is left on a timer I create?
Reply With Quote #3

For a cooldown convar, you'll probably want something like this. I've included almost everything you'd need to implement it.

PHP Code:
new Handle:g_hCooldown INVALID_HANDLE;
new 
g_iLastUsed[MAXPLAYERS+1];

public 
OnPluginStart()
{
    
g_hCooldown CreateConVar("sm_test_cooldown""10""Cooldown in seconds."0true0.0);
    
    
RegConsoleCmd("sm_test"Command_Test"Test...");
}

public 
Action:Command_Test(clientargs)
{
    new 
iNow GetTime(), iCooldown GetConVarInt(g_hCooldown);
    if (
iCooldown 0)
    {
        new 
iTimeLeft g_iLastUsed[client] + iCooldown iNow;
        if (
iTimeLeft 0)
        {
            
ReplyToCommand(client"[SM] You must wait another %d second%s."iTimeLeft, (iTimeLeft != "s" ""));
            return 
Plugin_Handled;
        }
    }
    
g_iLastUsed[client] = iNow;
    
    
//Other stuff.
    
return Plugin_Handled;
}

public 
OnClientDisconnect_Post(client)
{
    
g_iLastUsed[client] = 0;

__________________

Last edited by 11530; 11-12-2013 at 16:04.
11530 is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 11-12-2013 , 16:56   Re: Is it possible to check how much time is left on a timer I create?
Reply With Quote #4

I think GetGameTime() counts from 0 at OnMapStart, so there you'd have to go and reset everything to 0. Or just go ahead and do that OnClientConnected and/or OnClientDisconnected because those are fired on map change as well.

EDIT:
Oh 11530 already does this. (I didn't scroll down :p)
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.

Last edited by Dr. Greg House; 11-12-2013 at 16:57.
Dr. Greg House is offline
Reply


Thread Tools
Display Modes

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 19:23.


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