AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Suggestions / Requests (https://forums.alliedmods.net/forumdisplay.php?f=12)
-   -   save data (https://forums.alliedmods.net/showthread.php?t=321063)

Sanjay Singh 01-23-2020 05:14

save data
 
can I get an example of save & load player data in nvault
PHP Code:

gXP[32];
gLevel[32];
gClass[32]; 

LoadData(id)
SaveData(id)

Napoleon_be 01-23-2020 05:32

Re: save data
 
Here's an example, also check this out: https://forums.alliedmods.net/showthread.php?t=91503

PHP Code:

public client_disconnect(id)
{
    new 
szAuth[35], szTemp[60]; 
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    
formatex(szTempcharsmax(szTemp), "%i %i %i"iPoints[id], iTsKilled[id], iCtKilled[id]);
    
    
nvault_set(szVaultNameszAuthszTemp);
}

public 
client_authorized(id)
{
    new 
szAuth[35], szTemp[20], szTsKills[5], szCtKills[5], szPoints[10];
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    
nvault_get(szVaultNameszAuthszTempcharsmax(szTemp));
    
    
parse(szTempszPointscharsmax(szPoints), szTsKillscharsmax(szTsKills), szCtKillscharsmax(szCtKills));
    
    
iPoints[id] = str_to_num(szPoints);
    
iTsKilled[id] = str_to_num(szTsKills);
    
iCtKilled[id] = str_to_num(szCtKills);



Sanjay Singh 01-23-2020 09:11

Re: save data
 
Do i need to do formatex ? when loading data?

Napoleon_be 01-23-2020 09:41

Re: save data
 
Not if u do it this way, bugsy & ocixcrom have been helping me with this method and i would recomend using it

iceeedr 01-23-2020 11:19

Re: save data
 
I think it works like that too, I haven't tested it.

PHP Code:

#include <nvault_array>

enum _:Data
{
    
iPoints,
    
iTsKilled,
    
iCtKilled
}

new 
iData[33][Data]

public 
client_disconnect(id)
{
        new 
szAuth[35]
        
get_user_authid(idszAuthcharsmax(szAuth));
    
        
nvault_set_array(NameVaultszAuthiData[id][Data:0], sizeof(iData[]));
}

public 
client_authorized(id)
{
        new 
szAuth[35]
        
get_user_authid(idszAuthcharsmax(szAuth));
    
        
nvault_get_array(NameVaultszAuthiData[id][Data:0], sizeof(iData[]));



Bugsy 01-23-2020 18:29

Re: save data
 
Quote:

Originally Posted by Sanjay Singh (Post 2681343)
Do i need to do formatex ? when loading data?

Think about it. Why would you format a string when loading it? Loading a string gets the data from the vault file and puts it into a string. So now you have a string with values that you want to put into variables so they can be used in your plugin.

It's when you save that you need format, because you have variables with data that you need to put into a string so it can be saved into a single vault record...which can later be loaded back into variables.

Data to be saved (each in their own variable): 1 , 2 , 3
Formatted so it can be saved into the vault "1 2 3"

Data loaded from vault "1 2 3"
Parse values back into variables: 1 , 2 , 3

I recommend you study some plugins and code that is posted on the forums to help you better understand.

Sanjay Singh 01-24-2020 03:11

Re: save data
 
Quote:

Originally Posted by Bugsy (Post 2681393)
Think about it. Why would you format a string when loading it? Loading a string gets the data from the vault file and puts it into a string. So now you have a string with values that you want to put into variables so they can be used in your plugin.

It's when you save that you need format, because you have variables with data that you need to put into a string so it can be saved into a single vault record...which can later be loaded back into variables.

Data to be saved (each in their own variable): 1 , 2 , 3
Formatted so it can be saved into the vault "1 2 3"

Data loaded from vault "1 2 3"
Parse values back into variables: 1 , 2 , 3

I recommend you study some plugins and code that is posted on the forums to help you better understand.

Yea i never used nvault before but now I am using it and working fine without errors.


All times are GMT -4. The time now is 19:43.

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