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", cmdPhrase, ADMFLAG_ROOT, "Set a phrase");
}
public Action cmdPhrase(int client, int args)
{
char sPhrase[64];
GetCmdArgString(sPhrase, sizeof(sPhrase));
StorePhrase(client, sPhrase);
return Plugin_Handled;
}
stock void StorePhrase(int client, const char[] phrase)
{
char sFilePath[PLATFORM_MAX_PATH];
BuildPath(Path_SM, sFilePath, sizeof(sFilePath), "configs/phrases.cfg");
KeyValues kvm = new KeyValues("Player Phrases");
kvm.ImportFromFile(sFilePath);
char sSteamID[32];
if (GetClientAuthId(client, AuthId_Steam2, sSteamID, sizeof(sSteamID)))
{
if (kvm.JumpToKey(sSteamID, true))
{
char sCheck[64];
kvm.GetString("phrase", sCheck, sizeof(sCheck), "");
if (!StrEqual(sCheck, phrase))
{
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!
[SM] You set your new phrase to: "Hello there!"
__________________