View Single Post
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 09-12-2019 , 15:32   Re: [HELP] Get All Cmd Args
Reply With Quote #8

In your code, you're not exporting the new data to the file, so any phrase you set isn't being stored. You're also not closing the KV handle afterward, so you have Handle leaks.

Here's how I would store a phrase:

PHP Code:
#include <sourcemod>

public void OnPluginStart()
{
    
RegAdminCmd("sm_phrase"cmdPhraseADMFLAG_ROOT"Set a phrase");
}

public 
Action cmdPhrase(int clientint args)
{
    
char sPhrase[64];
    
GetCmdArgString(sPhrasesizeof(sPhrase));
    
StorePhrase(clientsPhrase);

    return 
Plugin_Handled;
}

stock void StorePhrase(int client, const char[] phrase)
{
    
char sFilePath[PLATFORM_MAX_PATH];
    
BuildPath(Path_SMsFilePathsizeof(sFilePath), "configs/phrases.cfg");

    
KeyValues kvm = new KeyValues("Player Phrases");
    
kvm.ImportFromFile(sFilePath);

    
char sSteamID[32];
    if (
GetClientAuthId(clientAuthId_Steam2sSteamIDsizeof(sSteamID)))
    {
        if (
kvm.JumpToKey(sSteamIDtrue))
        {
            
char sCheck[64];
            
kvm.GetString("phrase"sChecksizeof(sCheck), "");

            if (!
StrEqual(sCheckphrase))
            {
                
kvm.SetString("phrase"phrase);
                
kvm.ExportToFile(sFilePath);

                
ReplyToCommand(client"[SM] You set your new phrase to: \"%s\""phrase);
            }
            else
            {
                
ReplyToCommand(client"[SM] The phrase you entered is the same one that is already saved on the server.");
            }
        }
    }

    
delete kvm;

Example output:

PHP Code:
Crasher_3637 :  !phrase Hello there!
[
SMYou set your new phrase to"Hello there!" 
__________________
Psyk0tik is offline