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

Solved [CSGO] Print remaining time from a timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 12-15-2017 , 04:01   [CSGO] Print remaining time from a timer
Reply With Quote #1

1. How can I print the reaming time from a timer?

PHP Code:
RollTheDiceUser[client] = CreateTimer(60.0AllowRTDGetClientUserId(client)); 

PHP Code:
public Action PrepareTheDice(int clientint args)
{
    if (
client && client <= MaxClients && IsClientInGame(client) && !RolledTheDice[client])
    {
        switch(
IsPlayerAlive(client))
        {
            case 
trueRollTheDice(client);
            case 
falseCPrintToChat(client"[{orange}RollTheDice{default}] You must be {gree}alive {default} to use RTD.");
        }
    }
    else{
CPrintToChat(client"[{orange}RollTheDice{default}] You {red}can't {default}use RTD yet. Please wait {green}%i {default} more seconds", ?!? );}

    return 
Plugin_Handled;

2. If player A used !rtd how can I tell user B that he used the command and that he(B) should wait until the X item that player A got is gone.
__________________

Last edited by PinHeaDi; 12-17-2017 at 03:14.
PinHeaDi is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 12-15-2017 , 07:05   Re: [CSGO] Print remaining time from a timer
Reply With Quote #2

You don't need a timer, you can implement it like this
PHP Code:
int g_iLastCommand[MAXPLAYERS +1];

// This should probably be a convar
#define WAIT_TIME 10


public void OnPluginStart()
{
    
RegConsoleCmd("sm_test"Command_Test);
}


public 
Action Command_Test(int clientint args)
{
    if (
g_iLastCommand[client] == || g_iLastCommand[client] <= GetTime())
    {
        
// Your command goes here
        
        
g_iLastCommand[client] = GetTime() + WAIT_TIME;
    }
    else
    {
        
ReplyToCommand(client"You have to wait %d seconds to be able to use the command again"g_iLastCommand[client] - GetTime());
    }
    

    return 
Plugin_Handled;
}


public 
void OnClientConnected(int client)
{
    
g_iLastCommand[client] = 0;

__________________

Last edited by Impact123; 12-15-2017 at 07:10.
Impact123 is offline
PinHeaDi
Senior Member
Join Date: Jul 2013
Location: Bulgaria
Old 12-15-2017 , 08:44   Re: [CSGO] Print remaining time from a timer
Reply With Quote #3

PHP Code:
public void OnClientConnected(int client)
{
    
g_iLastCommand[client] = 0;

With that they can use the command again even if the time isn't passed when they retry? Or I got it wrong.

Maybe:

PHP Code:
public void OnClientConnected(int client)
{
    if (
g_iLastCommand[client] < 1){
    
g_iLastCommand[client] = 0;}

__________________

Last edited by PinHeaDi; 12-15-2017 at 08:50.
PinHeaDi is offline
Impact123
Veteran Member
Join Date: Oct 2011
Location: Germany
Old 12-15-2017 , 10:14   Re: [CSGO] Print remaining time from a timer
Reply With Quote #4

Yes, but that's the same as with the timer. Client indexes are not unique so it makes sense to reset the variable when a client connects. If you want to track reconnecting player you can use a stringmap with a steamid as key.
__________________

Last edited by Impact123; 12-15-2017 at 10:32.
Impact123 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 22:41.


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