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

nvault.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-19-2020 , 12:48   nvault.
Reply With Quote #1

So, i've been reading bugsy's tutorial on how to save and load data using nVault. I understand how to save and load a single array, but i have more than 1 array to save & load. The thing is i want to use formatex and use nvault_set just once to save the data. I'm not even sure if i can use nvault_set multiple times to save multiple arrays.

my current code (Code which doesn't work when i change map)
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_connect(id)
{
    new 
szAuth[35], szTemp[60], szTsKills[33], szCtKills[33], szPoints[33];
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    
formatex(szTempcharsmax(szTemp), "%i#%i#%i"iPoints[id], iTsKilled[id], iCtKilled[id]);
    
nvault_get(szVaultNameszAuthszTemp);
    
    
replace_all(szTempcharsmax(szTemp), "#"" ");
    
    
parse(szTempszTsKillscharsmax(szTsKills), charsmax(szCtKills), szPointscharsmax(szPoints));
    
    
iTsKilled[id] = str_to_num(szTsKills);
    
iCtKilled[id] = str_to_num(szCtKills);
    
iPoints[id] = str_to_num(szPoints);

__________________

Last edited by Napoleon_be; 01-19-2020 at 13:27.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-19-2020 , 13:19   Re: nvault.
Reply With Quote #2

A key is unique in a vault, so you cannot save multiple items under the same key..the last nvault_set() will overwrite all the previous ones. This is the whole idea behind nvault array, allowing you to save multiple pieces of data under a single key.

Looking at your code it seems as if your mindset is that the variable name has a bearing on the type of data you are saving and retrieving, and this is not the case.

The only thing the nvault module sees is:

nvault_get( vault id , string variable , string variable , length )
nvault_set( vault id , string variable , string variable )
__________________
Bugsy is offline
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-19-2020 , 13:25   Re: nvault.
Reply With Quote #3

Quote:
Originally Posted by Bugsy View Post
A key is unique in a vault, so you cannot save multiple items under the same key..the last nvault_set() will overwrite all the previous ones. This is the whole idea behind nvault array, allowing you to save multiple pieces of data under a single key.

Looking at your code it seems as if your mindset is that the variable name has a bearing on the type of data you are saving and retrieving, and this is not the case.

The only thing the nvault module sees is:

nvault_get( vault id , string variable , string variable , length )
nvault_set( vault id , string variable , string variable )
Okay so my second thought wasn't good either, thanks for explaining. Could u tell me what's wrong in my first code which doesn't save or load my values properly?
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-19-2020 , 13:47   Re: nvault.
Reply With Quote #4

Quote:
Originally Posted by Napoleon_be View Post
Okay so my second thought wasn't good either, thanks for explaining. Could u tell me what's wrong in my first code which doesn't save or load my values properly?
Code:
public client_disconnect(id) {     new szAuth[35], szTemp[60];     get_user_authid(id, szAuth, charsmax(szAuth));         formatex(szTemp, charsmax(szTemp), "%i#%i#%i", iPoints[id], iTsKilled[id], iCtKilled[id]);         nvault_set(szVaultName, szAuth, szTemp); }
get_user_authid() should not be called until client_authorized()
public client_connect(id) {     new szAuth[35], szTemp[60], szTsKills[33], szCtKills[33], szPoints[33];     get_user_authid(id, szAuth, charsmax(szAuth));    
    It makes no sense to format this string since it gets immediately overwritten with what nvault_get() retrieves from the vault
    formatex(szTemp, charsmax(szTemp), "%i#%i#%i", iPoints[id], iTsKilled[id], iCtKilled[id]);     nvault_get(szVaultName, szAuth, szTemp);         replace_all(szTemp, charsmax(szTemp), "#", " ");
    You are missing the szCtKills variable before charsmax(szCtKills)
    parse(szTemp, szTsKills, charsmax(szTsKills), charsmax(szCtKills), szPoints, charsmax(szPoints));         iTsKilled[id] = str_to_num(szTsKills);     iCtKilled[id] = str_to_num(szCtKills);     iPoints[id] = str_to_num(szPoints); }
__________________
Bugsy is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-19-2020 , 14:03   Re: nvault.
Reply With Quote #5

Also, I don't think there's a need to use "#" as a replacement for a whitespace. Just do "%i %i %i" directly. They're all integers, so there shouldn't be any problems.

PS: the max AuthId length is 64, not 35. You probably don't need 33 for a buffer that holds a single integer, the integer itself can't even be that big.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-20-2020 , 06:53   Re: nvault.
Reply With Quote #6

This doesn't work either

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[64], szTemp[20], szTsKills[5], szCtKills[5], szPoints[10];
    
get_user_authid(idszAuthcharsmax(szAuth));
    
    
nvault_get(szVaultNameszAuthszTsKillsszCtKillsszPoints);
    
    
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);

__________________

Last edited by Napoleon_be; 01-20-2020 at 07:05.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-20-2020 , 07:11   Re: nvault.
Reply With Quote #7

Code:
nvault_get(szVaultName, szAuth, szTemp, charsmax(szTemp))
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-20-2020 , 07:14   Re: nvault.
Reply With Quote #8

Quote:
Originally Posted by OciXCrom View Post
Code:
nvault_get(szVaultName, szAuth, szTemp, charsmax(szTemp))
Thanks, it worked. Also, i see someone else has done the job i was working on before me and used another method, which one is better and more efficient to use?

https://forums.alliedmods.net/showpo...78&postcount=4
__________________

Last edited by Napoleon_be; 01-20-2020 at 07:14.
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 01-20-2020 , 07:17   Re: nvault.
Reply With Quote #9

There are many things in his code that need fixing/optimizing, starting from the natives that won't even work.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Napoleon_be
Veteran Member
Join Date: Jul 2011
Location: Belgium
Old 01-20-2020 , 07:19   Re: nvault.
Reply With Quote #10

Quote:
Originally Posted by OciXCrom View Post
There are many things in his code that need fixing/optimizing, starting from the natives that won't even work.
Yea, i figured those natives won't work. I've posted my code there too, just without natives though.
__________________
Napoleon_be is offline
Send a message via Skype™ to Napoleon_be
Old 01-20-2020, 09:27
Natsheh
This message has been deleted by Natsheh. Reason: Swag
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 07:06.


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