Raised This Month: $ Target: $400
 0% 

Storing player data?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 12-18-2016 , 13:15   Storing player data?
Reply With Quote #1

well, let me explain:
i want to have a txt file with listed of player's steamid which is unique and an integer infront of it so it will look like this :
Code:
[STEAM_0_1:AnyThing] = 1
on and on to the down for many players on join.
my problem is i want the plugin to first get the steamid then check for the steamid in the txt file and if it exists look for the int infornt of it and would be able to change it later (this is ok if it removes it and rewrite.
any helps on this?
__________________
ambn is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 12-18-2016 , 14:00   Re: Storing player data?
Reply With Quote #2

What are you wanting to use this for? If you plan on storing user data like credits, then using a file to store info in is a bad idea

Last edited by headline; 12-18-2016 at 14:00.
headline is offline
quake84
Junior Member
Join Date: Aug 2014
Location: Poland
Old 12-18-2016 , 14:11   Re: Storing player data?
Reply With Quote #3

If this is going to be loaded and modified when people connect - use databases. create a sqlite database with a configuration in databases.cfg and make threaded queries to it so there's no visible server lag when the data is being parsed.
__________________
...
quake84 is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 12-18-2016 , 14:12   Re: Storing player data?
Reply With Quote #4

i was thinking about using keyvalues to store their data by steamid and when they for example killed someone they get 1 point to buy something,
is there anyway to change a get a value and change it to something esle then get it to use?
Code:
"PlayerData"
{
    "STEAM_0:0:7"
    {
        "Cash"        "1"
    }
}
PHP Code:
stock AddCashToUser(char[] steamidchar[] cash)
{
    
//new String:sFile[256];
    //BuildPath(Path_SM, sFile, sizeof(sFile), "configs/economy_data.txt");
    
char cash[8];
    
KeyValues kv = new KeyValues("DataFile");
    
kv.ImportFromFile("economy_data.txt");
    
kv.JumpToKey(steamid);
    
kv.GetString("Cash"cashsizeof(cash));
    new 
CashSize StringToInt(cash);
    
CashSize++
    
IntToString(CashSizecashsizeof(cash)); 
i was thinking of this and i don't even know if it's working or not cause i'm just reading the wiki but til here i need to save the added value tu the cash size, how to do so? kv.SetString? but how's that even work?!
__________________
ambn is offline
headline
SourceMod Moderator
Join Date: Mar 2015
Old 12-18-2016 , 14:14   Re: Storing player data?
Reply With Quote #5

Quote:
Originally Posted by ambn View Post
i was thinking about using keyvalues to store their data by steamid and when they for example killed someone they get 1 point to buy something,
is there anyway to change a get a value and change it to something esle then get it to use?
Code:
"PlayerData"
{
    "STEAM_0:0:7"
    {
        "Cash"        "1"
    }
}
PHP Code:
stock AddCashToUser(char[] steamidchar[] cash)
{
    
//new String:sFile[256];
    //BuildPath(Path_SM, sFile, sizeof(sFile), "configs/economy_data.txt");
    
char cash[8];
    
KeyValues kv = new KeyValues("DataFile");
    
kv.ImportFromFile("economy_data.txt");
    
kv.JumpToKey(steamid);
    
kv.GetString("Cash"cashsizeof(cash));
    new 
CashSize StringToInt(cash);
    
CashSize++
    
IntToString(CashSizecashsizeof(cash)); 
i was thinking of this and i don't even know if it's working or not cause i'm just reading the wiki but til here i need to save the added value tu the cash size, how to do so? kv.SetString? but how's that even work?!
I don't want to tell you how for your own sake. Read the Database wiki
headline is offline
KissLick
Veteran Member
Join Date: Nov 2012
Location: void
Old 12-18-2016 , 14:15   Re: Storing player data?
Reply With Quote #6

Don't use keyvalues for this kind of thing... It's slow as it is and imagine how bad it would be in few months after 10 000+ players connect to your server...

Just use database and threaded connection.
__________________
Plugins: TeamGames
Includes: Menu stocks, ColorVariables, DownloadTableConfig

> No help through PM, make a topic.
KissLick is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 12-18-2016 , 14:20   Re: Storing player data?
Reply With Quote #7

well, i guess it your right but at least aren't you going to tell me how? i'm just curious about it
__________________
ambn is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 12-18-2016 , 15:40   Re: Storing player data?
Reply With Quote #8

KeyValuesToFile and KvSetNum should work I believe, have fun buddy
blaacky is offline
ambn
Veteran Member
Join Date: Feb 2015
Location: Fun servers
Old 12-20-2016 , 10:29   Re: Storing player data?
Reply With Quote #9

Quote:
Originally Posted by blaacky View Post
KeyValuesToFile and KvSetNum should work I believe, have fun buddy
is there any way to add and edit keyvalues down to the file?
i mean like this:
PHP Code:
"PlayerData"
{
    
"STEAM_0:0:7"
    
{
        
"nickname"        "Something"
    
}
    
"STEAM_0:0:8"
    
{
        
"nickname"        "Something_else!"
    
}
    and ...

for example i want to make an stock to write everyone i target.
targeting is not my problem , the problem is when i choose someone everything is ok but when i target someone_else , the someone will remove and someone_else will replace and it will look like this:
PHP Code:
"PlayerData"
{
    
"STEAM_0:0:8"
    
{
        
"nickname"        "Something_else!"
    
}
    and ...

I hope you understand what i just said xD!
__________________
ambn 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 14:12.


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