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

Solved Repeatable Timer & Client Index


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 09-12-2018 , 08:15   Repeatable Timer & Client Index
Reply With Quote #1

Hello!

I have a quick question in regard to what I am coding:
PHP Code:
#include <sourcemod>

#define CONFIG "addons/sourcemod/configs/commandcooldown.cfg"

StringMap g_hHashMap;
Handle g_hTimer[MAXPLAYERS+1];
int g_iTimeleft[MAXPLAYERS+1];

public 
void OnPluginStart()
{
    
BrowseKeyValues();
}

public 
void OnClientDisconnect(int client)
{
    
delete g_hTimer[client];
    
g_iTimeleft[client] = 0;
}

public 
Action OnCommand(int client, const char[] commandint argc)
{
    if (
g_iTimeleft[client])
    {
        
ReplyToCommand(client"[SM] You cannot use this command again for %i seconds."g_iTimeleft[client]);
        return 
Plugin_Handled;
    } else {
        
g_hHashMap.GetValue(commandg_iTimeleft[client]);
        
g_hTimer[client] = CreateTimer(1.0Timer_CallbackclientTIMER_REPEAT);
    }

    return 
Plugin_Continue;
}

public 
Action Timer_Callback(Handle timerint client)
{
    
g_iTimeleft[client]--;
    if (!
g_iTimeleft[client])
    {
        
g_hTimer[client] = null;
        return 
Plugin_Stop;
    }

    return 
Plugin_Continue;
}

void BrowseKeyValues()
{
    
delete g_hHashMap;
    
KeyValues kv = new KeyValues("Command Cooldown");
    if (!
FileExists(CONFIG))
    {
        
kv.SetString("kill""30");
        
kv.Rewind();
        
kv.ExportToFile(CONFIG);
    }

    if (!
kv.ImportFromFile(CONFIG) || !kv.GotoFirstSubKey(false))
    {
        
delete kv;
        
SetFailState("Failure parsing the config file %s!"CONFIG);
    }

    
g_hHashMap = new StringMap();
    
char command[64];
    
int cooldown;
    do {
        
kv.GetSectionName(commandsizeof(command));
        
kv.GotoFirstSubKey(false);
        
cooldown kv.GetNum(NULL_STRING);
        
g_hHashMap.SetValue(commandcooldown);
        
AddCommandListener(OnCommandcommand);
        
LogMessage("Added %i second cooldown for command %s."cooldowncommand);
    } while 
kv.GotoNextKey(false);
    
delete kv;

Do I need to pass the client's UserID instead of their index or not (in the CreateTimer() function)? By my understanding, since I am assigning the timer handle to each client specifically, then I don't need to.

Thanks,
Grant

Last edited by ThatKidWhoGames; 09-12-2018 at 10:22.
ThatKidWhoGames is offline
 


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 21:47.


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