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

Working with KeyValues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Shaman
Senior Member
Join Date: Dec 2006
Location: Istanbul, Turkey
Old 07-09-2007 , 15:48   Working with KeyValues
Reply With Quote #1

1-How can I write or change values in a KV file?
2-Is there anyway to access a value like: FindIntKeyValue(kv, 'Data/Players/Shaman/Money')?
3-Is there any other saving method? (Other than SQL. Like nVault?)
I want to use sql, but some users don't have SQL servers and it's hard to install a SQL plugin.

What I am trying to do is make a file that stores users information like experience points, level, money and things that they have bought.
__________________
Shaman is offline
Send a message via ICQ to Shaman Send a message via AIM to Shaman Send a message via MSN to Shaman Send a message via Yahoo to Shaman
sumguy14
Senior Member
Join Date: Apr 2006
Old 07-09-2007 , 16:18   Re: Working with KeyValues
Reply With Quote #2

I suggest SQL, people can go to sites and get free SQL databases if they need one.

KeyValue's work like a tree

Code:
"rootnode"
{
  "key1"
  {
      "valuename" "value"
  }
}
That is a standard KeyValue's file, you can store simple things like XP or level

Code:
"playerdata"
{
  "STEAM_0:0:8274827"
  {
    "xp" "50"
    "level" "2"
  }
}
To create this you would do:

Code:
new Handle:config; // Make db handle

InitDatabase
{
  config=CreateKeyValues("playerdata"); // Creates the KeyValue tree in memory
  decl String:path[PLATFORM_MAX_PATH];
  BuildPath(Path_SM,path,PLATFORM_MAX_PATH,"configs/dbfile.txt"); // Builds a path to your db file
  if(!FileToKeyValues(config,path)) // Transfers the file to memory, if it returns false, it will kill the plugin and spit out an error
    SetFailState("Failed to load database!");
}

AddPlayerToDB(const String:steamid[])
{
  KvRewind(config); // Rewind our keyvalue tree to the top
  if(KvJumpToKey(config,steamid,false))  // Will try to jump to the player's key that holds his info, and if it exists it will stop here
    return;
  KvJumpToKey(config,steamid,true); // This will create the player's key
  KvSetNum(config,"xp",0); // Creates the valuename that stores XP
  KvSetNum(config,"level",1); // Creates the valuename that stores level (defaults to level 1)
  // We're done!
}

SaveDatabase
{
  decl String:path[PLATFORM_MAX_PATH];
  BuildPath(Path_SM,path,PLATFORM_MAX_PATH,"configs/dbfile.txt"); // Builds a path to your db file
  KeyValuesToFile(config,path);   // Transfer to file for storage
}
Hope this helps! There might be a few minor mistakes or typos, not exactly a SM pro
sumguy14 is offline
Shaman
Senior Member
Join Date: Dec 2006
Location: Istanbul, Turkey
Old 07-09-2007 , 16:35   Re: Working with KeyValues
Reply With Quote #3

Thanks
__________________
Shaman is offline
Send a message via ICQ to Shaman Send a message via AIM to Shaman Send a message via MSN to Shaman Send a message via Yahoo to Shaman
Shaman
Senior Member
Join Date: Dec 2006
Location: Istanbul, Turkey
Old 07-11-2007 , 05:13   Re: Working with KeyValues
Reply With Quote #4

Solved.
__________________

Last edited by Shaman; 07-11-2007 at 09:48.
Shaman is offline
Send a message via ICQ to Shaman Send a message via AIM to Shaman Send a message via MSN to Shaman Send a message via Yahoo to Shaman
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 05:07.


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