Raised This Month: $ Target: $400
 0% 

Remember more values with nVault?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-16-2020 , 19:25   Remember more values with nVault?
Reply With Quote #1

Hey, so I want to have nVault remember 2 values. Now it just remembers 1 of them:
PHP Code:
    new szClass[20];
    new 
szKey[40];

    
formatex(szKeycharsmaxszKey ), "%sCLASS"g_szAuthID[id]);
    
formatex(szClasscharsmaxszClass ), "%d"g_Class[id]); // Wizard

    
nvault_set(g_VaultszKeyszClass); 
And this is how I retrieve it:
PHP Code:
        new szKey[40];
        
formatex(szKeycharsmaxszKey ), "%sCLASS"g_szAuthID[id3]);
        new 
iClass nvault_get(g_VaultszKey ); 
But how do I remember 2 values, for example his class (like shown) and his level?
I was thinking something like this
PHP Code:
    new szClass[20];
    new 
szLevel[20];
    new 
szKey[40];

    
formatex(szKeycharsmaxszKey ), "%sCLASS"g_szAuthID[id]);
    
formatex(szClasscharsmaxszClass ), "%d"g_Class[id]); // Wizard
    
formatex(szLevelcharsmaxszLevel ), "%d"g_Level[id]);

    
nvault_set(g_VaultszKeyszClassszLevel); 
If that is possible, but then how do I retrieve it?
__________________
Contact! || Discord:
Mr_Boopsy_#2066

Last edited by supertrio17; 06-16-2020 at 19:26.
supertrio17 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-16-2020 , 19:32   Re: Remember more values with nVault?
Reply With Quote #2

A few options:

4-byte integers you would need to store side by side in a string "434 34343 3141414" and then parse when retrieved
2-byte integers - You can fit 2 into a 4-byte integer and save as a single integer value
1-byte integers - You can fit 4 into a 4-byte integer and save as a single integer value

String or float values
Pack side by side, similar to the 4-byte integer way above "string1" "string2" "string3"

OR use nVault Array and storing anything is simple
__________________

Last edited by Bugsy; 06-16-2020 at 19:34.
Bugsy is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-16-2020 , 19:40   Re: Remember more values with nVault?
Reply With Quote #3

Hey, so I didn't understand you quite well, I need something like this. First value: 1/2/3/4/5/6. Second value 1/2.
Is it problem for you to give me a simple example?
__________________
Contact! || Discord:
Mr_Boopsy_#2066
supertrio17 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-16-2020 , 19:57   Re: Remember more values with nVault?
Reply With Quote #4

All numbers in AMX-X are stored in a 4-byte cell. Each byte can hold a value between 0 and 255. So you can pack 4 0 to 255 values within 1 cell. If the values are between 1 and 6 only, you can pack more than just 4 into a cell.

For your example, you need 6 so this idea wouldn't work.

I would use nVault Array, it's the simplest if you are not experienced.
__________________

Last edited by Bugsy; 06-16-2020 at 19:58.
Bugsy is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-16-2020 , 20:01   Re: Remember more values with nVault?
Reply With Quote #5

Quote:
Originally Posted by Bugsy View Post
All numbers in AMX-X are stored in a 4-byte cell. Each byte can hold a value between 0 and 255. So you can pack 4 0 to 255 values within 1 cell. If the values are between 1 and 6 only, you can pack more than just 4 into a cell.

For your example, you need 6 so this idea wouldn't work.

I would use nVault Array, it's the simplest if you are not experienced.
I don't really feel like using it, simply because I don't want to get includes for everyone who want's this plugin, so I ended up using something like this:
PHP Code:
    new szClass[20];
    new 
szKey[40];

    
formatex(szKeycharsmaxszKey ), "%sCLASS"g_szAuthID[id]);
    
formatex(szClasscharsmaxszClass ), "%d"g_Class[id]); // Soul Master

    
nvault_set(g_VaultszKeyszClass);

    new 
szCLevel[20]

    
formatex(szKeycharsmaxszKey ), "%sCLEVEL"g_szAuthID[id]);
    
formatex(szCLevelcharsmaxszCLevel ), "%d"g_ClassLevel[id]);

    
nvault_set(g_VaultszKeyszCLevel); 
And loading it like this:
PHP Code:
        new cLevel crxranks_get_user_level(id3);
        new 
szKey[40];
        
formatex(szKeycharsmaxszKey ), "%sCLASS"g_szAuthID[id3]);
        new 
iClass nvault_get(g_VaultszKey );
        
formatex(szKeycharsmaxszKey ), "%sCLEVEL"g_szAuthID[id3]);
        new 
iCLevel nvault_get(g_VaultszKey ); 
__________________
Contact! || Discord:
Mr_Boopsy_#2066
supertrio17 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 06-16-2020 , 20:00   Re: Remember more values with nVault?
Reply With Quote #6

Code:
#include <amxmodx> #include <nvault> new g_vault public plugin_init() {     register_plugin("NVault Example", "Version", "Author")     g_vault = nvault_open("ExampleVault") } public client_disconnected(id) {     if (!is_user_bot(id) && !is_user_hltv(id))         save_player_data(id) } public client_authorized(id, const authid[]) {     if (!is_user_bot(id) && !is_user_hltv(id))         load_player_data(id, authid) } public save_player_data(id) {     new authid[MAX_AUTHID_LEN]     get_user_authid(id, authid, charsmax(authid))     new data[256]     new value1 = 100     new value2 = 200     new value3 = 300     formatex(data, charsmax(data), "%d %d %d", value1, value2, value3)     nvault_set(g_vault, authid, data) } public load_player_data(id, authid[] = "") {     if (!authid[0])         get_user_authid(id, authid, charsmax(authid))     new data[256]     nvault_get(g_vault, authid, data, charsmax(data))     new values[3][85]     parse(data, values[0], charsmax(values[]), values[1], charsmax(values[]), values[2], charsmax(values[]))     new value1 = str_to_num(values[0])     new value2 = str_to_num(values[1])     new value3 = str_to_num(values[2]) }

If you need to store multiple strings consider using nVault Array instead. It's just an include with utility functions, easy, really.
__________________









Last edited by CrazY.; 06-16-2020 at 20:05.
CrazY. is offline
supertrio17
Senior Member
Join Date: May 2020
Location: Serbia
Old 06-16-2020 , 20:03   Re: Remember more values with nVault?
Reply With Quote #7

Quote:
Originally Posted by CrazY. View Post
Code:
#include <amxmodx> #include <nvault> new g_vault public plugin_init() {     register_plugin("NVault Example", "Version", "Author")     g_vault = nvault_open("ExampleVault") } public client_disconnected(id) {     if (!is_user_bot(id) && !is_user_hltv(id))         save_player_data(id) } public client_authorized(id, const authid[]) {     if (!is_user_bot(id) && !is_user_hltv(id))         load_player_data(id, authid) } public save_player_data(id) {     new authid[MAX_AUTHID_LEN]     get_user_authid(id, authid, charsmax(authid))     new data[256]     new value1 = 100     new value2 = 200     new value3 = 300     formatex(data, charsmax(data), "%d %d %d", value1, value2, value3)     nvault_set(g_vault, authid, data) } public load_player_data(id, authid[] = "") {     if (!authid[0])         get_user_authid(id, authid, charsmax(authid))     new data[256]     nvault_get(g_vault, authid, data, charsmax(data))     new values[3][85]     parse(data, values[0], charsmax(values[]), values[1], charsmax(values[]), values[2], charsmax(values[]))     new value1 = str_to_num(values[0])     new value2 = str_to_num(values[1])     new value3 = str_to_num(values[2]) }
I'll try this and see if it works, thanks for replying
__________________
Contact! || Discord:
Mr_Boopsy_#2066
supertrio17 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-16-2020 , 20:13   Re: Remember more values with nVault?
Reply With Quote #8

Storing things side-by-side in a string like that was the only way prior to the creation of nVault Array. The nVault Array include just allows you to do it more elegantly in code, even though it's not the most efficient thing in the world.

It's not unheard of/unusual for plugins to require 3rd-party includes, so I wouldn't always rule them out. You can make your code much cleaner using nVault Array, just throwing it out there.
__________________
Bugsy is offline
Reply


Thread Tools
Display Modes

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 16:58.


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