Raised This Month: $32 Target: $400
 8% 

[HELP] KeyValues bad writing


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 10-05-2019 , 12:09   [HELP] KeyValues bad writing
Reply With Quote #1

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 clientint args)
{
    if(
args 1)
    {
        
ReplyToCommand(client"[SM] Use: sm_setnum <number>");
        return 
Plugin_Handled;
    }
    
    
char argNum[32];
    
GetCmdArg(1argNumsizeof(argNum));
    
SaveNumberOnFile(clientargNum);
    
    return 
Plugin_Handled;
}

public 
void SaveNumberOnFile(int client, const char[] number)
{
    
char file[64];
    
BuildPath(Path_SMfilesizeof(file), "configs/nmr_cfg.cfg");
    
KeyValues kv = new KeyValues("NUMEROS");
    
kv.ImportFromFile(file);
    
    
char sid[64];
    if(
GetClientAuthId(clientAuthId_Steam2sidsizeof(sid)))
    {
        if(
kv.JumpToKey(sidtrue))
        {
            
char check[32];
            
kv.GetString("numero"checksizeof(check));
            
            if(!
StrEqual(checknumber))
            {
                
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.
__________________

Last edited by SpirT; 10-05-2019 at 12:10.
SpirT is offline
Ilusion9
Veteran Member
Join Date: Jun 2018
Location: Romania
Old 10-05-2019 , 12:26   Re: [HELP] KeyValues bad writing
Reply With Quote #2

kv.ExportToFile - Exports a KeyValues tree to a file. The tree is dumped from the current position.
https://sm.alliedmods.net/new-api/ke...s/ExportToFile

Use kv.Rewind() before kv.ExportToFile()
https://sm.alliedmods.net/new-api/Ke...yValues/Rewind
__________________
Ilusion9 is offline
SpirT
Senior Member
Join Date: Sep 2018
Location: Portugal
Old 10-06-2019 , 05:55   Re: [HELP] KeyValues bad writing
Reply With Quote #3

Quote:
Originally Posted by Ilusion9 View Post
kv.ExportToFile - Exports a KeyValues tree to a file. The tree is dumped from the current position.
https://sm.alliedmods.net/new-api/ke...s/ExportToFile

Use kv.Rewind() before kv.ExportToFile()
https://sm.alliedmods.net/new-api/Ke...yValues/Rewind
Thanks for ur reply. So it should be like this?
PHP Code:
if(!StrEqual(checknumber))
            {
                
kv.SetString("numero"number);
                
kv.Rewind(); //this thing over here!!!!!
                
kv.ExportToFile(file);
                
                
ReplyToCommand(client"[SM] Number set to: %s"number);
            } 
Then can you help me with this? I am having this problem a long time ago and i didn't figure out already how can it be fixed.

Best Regards,

SpirT.
__________________
SpirT 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 18:58.


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