Hey guys.
I tried to do some stuff on key values, a simple one, but it does work as I expect.
I left this file (configs/nmr_cfg.cfg) like this
Code:
"NUMEROS"
{
"STEAMID_OF_PLAYER"
{
"numero" "1"
}
}
And I done the command !setnum 1 and it replaced everything with this:
Code:
"STEAM_1:1:419435558" //This is my steam id (this line is not in the file obviously
{
"numero" "1"
}
So the KV got "deleted" why?
Source of the plugin:
PHP Code:
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR ""
#define PLUGIN_VERSION "0.00"
#include <sourcemod>
#include <sdktools>
#pragma newdecls required
public Plugin myinfo =
{
name = "",
author = PLUGIN_AUTHOR,
description = "",
version = PLUGIN_VERSION,
url = ""
};
public void OnPluginStart()
{
RegConsoleCmd("sm_setnum", Command_SetNum);
}
public Action Command_SetNum(int client, int args)
{
if(args < 1)
{
ReplyToCommand(client, "[SM] Use: sm_setnum <number>");
return Plugin_Handled;
}
char argNum[32];
GetCmdArg(1, argNum, sizeof(argNum));
SaveNumberOnFile(client, argNum);
return Plugin_Handled;
}
public void SaveNumberOnFile(int client, const char[] number)
{
char file[64];
BuildPath(Path_SM, file, sizeof(file), "configs/nmr_cfg.cfg");
KeyValues kv = new KeyValues("NUMEROS");
kv.ImportFromFile(file);
char sid[64];
if(GetClientAuthId(client, AuthId_Steam2, sid, sizeof(sid)))
{
if(kv.JumpToKey(sid, true))
{
char check[32];
kv.GetString("numero", check, sizeof(check));
if(!StrEqual(check, number))
{
kv.SetString("numero", number);
kv.ExportToFile(file);
ReplyToCommand(client, "[SM] Number set to: %s", number);
}
else
{
ReplyToCommand(client, "[SM] Numbers are the same. Please try another one");
}
}
}
delete kv;
}
What is the problem?
Best Regards,
SpirT.
__________________