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

[INC] nVault Array


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-17-2016 , 12:42   [INC] nVault Array
Reply With Quote #1

nVault Array

This include provides the ability to store arrays in nVault. Out of the box, nVault allows you to only save data as a single string. This is cumbersome when you need to store multiple pieces of data because you first need to convert it to a single sting before saving. On top of that, when retrieving the data you then need to parse each value out of the string and then convert it back to an integer and/or copy it back to a string/float variable. This include file solves this problem by allowing you to save and retrieve data directly to and from an array. Data of various types (int, bool, string, float) can all be stored in a single array by using an enum sized array (see example plugin).

Note: This include file requires that you use a fixed version of the nVault module. During the development of these new functions, a bug was discovered in the nVault module that will result in invalid values and possibly errors. This fixed module is attached below and is also available in AMX-X dev builds >= 4589. Thanks to Arkshine for fixing this so quickly for me.

Functions
  • nvault_set_array() - Save an array to vault.
  • nvault_get_array() - Read an array from vault.
  • nvault_arraysize() - Returns size of array stored.
  • nvault_isarray() - Returns true/false for if data is an array.
Note: This include file uses the nVault handle returned from nvault_open(). It does NOT use the nvault_util_open() file handle used by nVault Utility. This include file has no dependency on nVault Utility. nVault Utility does, however, provide the ability to read all array entries. For nvault_util_read_array()/nvault_util_readall_array(), you would use the nvault_util_open() file handle as with all functions in nVault Utility.

Descriptions
  • nvault_set_array( vault , key , array[] , size )
    This function saves an array to vault. The largest array that can be saved is 500 cells; you can increase this by increasing the constant _NVAULT_ARRAY_MAXARRAYSIZE in the include file. Multidimensional arrays are not directly supported, but if you use an enum to size your array, it can be accomplished. Arrays are stored in a binary format with encoding to prevent null bytes from being included in the output string .. which means you cannot edit/view arrays saved in nVault with an nVault viewer application.
    Code:
    vault - Vault handle.
    key - Key for entry.
    array[] - Array to store in vault.
    size - Size of array.
  • nvault_get_array( vault , key , array[] , size )
    This function reads an array from vault. This will only read arrays that were stored in the vault using nvault_set_array().
    Code:
    vault - Vault handle.
    key - Key for entry.
    array[] - Array to read data in to.
    size - Size of array.
  • nvault_arraysize( vault , key )
    This function returns the size of the array data stored in nvault. It will return 0 if the record does not exist or if the data in the nVault record is not an array. It will otherwise return the size of the array in cells.
    Code:
    vault - Vault handle.
    key - Key for entry.
  • nvault_isarray( vault , key )
    This function determines whether or not the data is an array.
    Code:
    vault - Vault handle.
    key - Key for entry.
nVault Array Example
Spoiler
Attached Files
File Type: zip nvault_amxx_fixed.zip (148.2 KB, 1105 views)
File Type: inc nvault_array.inc (7.6 KB, 1768 views)
__________________

Last edited by Bugsy; 12-22-2018 at 10:37.
Bugsy is offline
Craxor
Veteran Member
Join Date: Jan 2016
Location: Romania
Old 12-18-2016 , 02:48   Re: [INC] nVault Array
Reply With Quote #2

First Comment.

Amazing WORK BUGSYYYYYYYY
__________________
Project: Among Us

Last edited by Craxor; 12-18-2016 at 02:49.
Craxor is offline
Send a message via ICQ to Craxor
EFFx
Veteran Member
Join Date: Feb 2016
Location: São Paulo, Brasil
Old 12-18-2016 , 13:16   Re: [INC] nVault Array
Reply With Quote #3

Quote:
Originally Posted by Craxor View Post
Amazing WORK BUGSYYYYYYYY
Bugsy is the daddy of Arrays
__________________
• Ranking System • AutoMix 5vs5 System
• Web Ban System • Plugins for free

____________________________________________
For private works:
• Discord: EFFEXo#8850 • Steam: EFFEXo
EFFx is offline
shehzad1234
BANNED
Join Date: Jan 2016
Location: https://t.me/pump_upp
Old 12-21-2016 , 09:24   Re: [INC] nVault Array
Reply With Quote #4

Awsome
shehzad1234 is offline
Send a message via ICQ to shehzad1234 Send a message via AIM to shehzad1234 Send a message via Yahoo to shehzad1234
ish12321
Veteran Member
Join Date: May 2016
Old 06-17-2018 , 08:29   Re: [INC] nVault Array
Reply With Quote #5

Could you also add nvault_pset_array ?
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 06-17-2018 , 12:00   Re: [INC] nVault Array
Reply With Quote #6

Quote:
Originally Posted by ish12321 View Post
Could you also add nvault_pset_array ?
Yes, I'll add it when I get a chance. For now, you can see if the below works:
PHP Code:
nvault_touchvault key ); 
__________________

Last edited by Bugsy; 06-17-2018 at 12:01.
Bugsy is offline
aEEk
Member
Join Date: May 2012
Location: Romania
Old 05-26-2020 , 15:53   Re: [INC] nVault Array
Reply With Quote #7

Hello @Bugsy, I am facing a problem regarding Loading and Saving data using nvault_array.
Players data is missing sometimes, not immediately after changelevel... they are able to play all day and tomorrow all of the data, skins, keys, etc are not in their inventory. How is that possible? Give me a hint, I am not so friendly with SQL saving and loading data....

Source:
PHP Code:
LoadData(id)
{
    if(!
is_user_connected(id) && !isUserLoged[id])
    {
        return 
1;
    }

    new 
auth[32], szKey[32];
    
    switch(
get_pcvar_num(RANK_SAVE_TYPE))
    {
        case 
1get_user_ip(idauthcharsmax(auth), 1)
        case 
2get_user_name(idauthcharsmax(auth))
        case 
3get_user_authid(idauthcharsmax(auth))
    }    
    
    
// LOAD DATABASE to USER ID
    
formatex(szKeycharsmax(szKey), "%s-DB"auth);

    if(
nvault_get_array(vault_database_idszKeyuserDATA[id][ePlayerData:0], sizeof(userDATA[])))
    {
        
PLAYER_LEVEL[id]         =     userDATAid ][ pdLevel ];
        
PLAYER_XP[id]            =    userDATAid ][ pdExperience ];
        
PLAYER_XP_FULL[id]        =    userDATAid ][ pdFullXP ];
        
PLAYER_MONEY[id]        =    userDATAid ][ pdPoints ];
        
PLAYER_KEYS[id]            =    userDATAid ][ pdKeys ];

        for(new 
1<= MAX_CASESi++)
        {
            
playerCases[i][id]     = userDATA[id][pdCases][i];
        }
    }

    
// LOAD SKINS to USER ID
    
formatex(szKeycharsmax(szKey), "%s-SKINS"auth);

    if(
nvault_get_array(vault_skins_idszKeyuserSKINS[id][ePlayerSkins:0], sizeof(userSKINS[])))
    {                
        for(new 
1ALL_WEAPONSi++)
        {
            
playerSkin[i][id]     = userSKINS[id][pdSkinsVault][i];
        }
    }

    
// LOAD STATTRAK SKINS to USER ID
    
formatex(szKeycharsmax(szKey), "%s-STTK"auth);

    if(
nvault_get_array(vault_stattrak_idszKeyuserSTATTRAK[id][ePlayerStattrak:0], sizeof(userSTATTRAK[])))
    {        
        for(new 
1100i++)
        {
            
stattrak[i][id]     = userSTATTRAK[id][pdStatTrak][i];
            
kill[i][id]         = userSTATTRAK[id][pdStatTrakKills][i];
        }
    }

    
// LOAD SELECTED SKINS to USER ID
    
formatex(szKeycharsmax(szKey), "%s-USKINS"auth);

    if(
nvault_get_array(vault_uskins_idszKeyuserUSKINS[id][ePlayerUskins:0], sizeof(userUSKINS[])))
    {
        for(new 
0WEAPONSKINi++)
        {
            
UsingWeapon[i][id]     = userUSKINS[id][pdSelectedSkin][i];
        }
    }
    
    
check_level(id1);
    return 
0;
}

SaveData(id)
{    
    if(!
is_user_connected(id) && !isUserLoged[id])
    {
        return 
1;
    }    
    
    new 
auth[32], szKey[32], casesNumberskinsNumbersttNumberkillsNumberskinSelected;
    
    switch(
get_pcvar_num(RANK_SAVE_TYPE))
    {
        case 
1get_user_ip(idauthcharsmax(auth), 1)
        case 
2get_user_name(idauthcharsmax(auth))
        case 
3get_user_authid(idauthcharsmax(auth))
    }

    
// SAVE DATABASE to USER ID
    
formatex(szKeycharsmax(szKey), "%s-DB"auth);

    
userDATAid ][ pdLevel ]            = PLAYER_LEVEL[id];
    
userDATAid ][ pdExperience ]         = PLAYER_XP[id];
    
userDATAid ][ pdFullXP ]            = PLAYER_XP_FULL[id];
    
userDATAid ][ pdPoints ]             = PLAYER_MONEY[id];
    
userDATAid ][ pdKeys ]             = PLAYER_KEYS[id];

    for(new 
1<= MAX_CASESi++)
    {
        if(
MAX_CASES)
            break;
        
        if(
playerCases[i][id] < 0)
            
playerCases[i][id] = 0

        casesNumber 
playerCases[i][id];        
          
userDATAid ][ pdCases ][i]     = _:casesNumber;
    }
    
nvault_set_array(vault_database_idszKeyuserDATAid ][ ePlayerData:], sizeofuserDATA[] ));

    
// SAVE SKINS to USER ID
    
formatex(szKeycharsmax(szKey), "%s-SKINS"auth);

    for(new 
1ALL_WEAPONSi++)
    {
        if(
MAX)
            break;

        if(
playerSkin[i][id] < 0)
            
playerSkin[i][id] = 0

        skinsNumber 
playerSkin[i][id];

        
userSKINSid ][ pdSkinsVault ][ ] = _:skinsNumber;    
    }
    
nvault_set_array(vault_skins_idszKeyuserSKINSid ][ ePlayerSkins:], sizeofuserSKINS[] ));

    
// SAVE STATTRAK SKINS to USER ID
    
formatex(szKeycharsmax(szKey), "%s-STTK"auth);

    for(new 
1ALL_WEAPONSi++)
    {
        if(
MAX)
            break;
        
        if(
stattrak[i][id] < 0)
            
stattrak[i][id] = 0

        
if(kill[i][id] < 0)
            
kill[i][id] = 0

        sttNumber 
stattrak[i][id];
        
killsNumber kill[i][id];

        
userSTATTRAKid ][ pdStatTrak ][ ] = _:sttNumber;
        
userSTATTRAKid ][ pdStatTrakKills ][ ] = _:killsNumber;        
    }
    
nvault_set_array(vault_stattrak_idszKeyuserSTATTRAKid ][ ePlayerStattrak:], sizeofuserSTATTRAK[] ));

    
// SAVE SELECTED SKINS to USER ID
    
formatex(szKeycharsmax(szKey), "%s-USKINS"auth);

    for(new 
0WEAPONSKINi++)
    {
        
skinSelected UsingWeapon[i][id];        
        
userUSKINSid ][ pdSelectedSkin ][ ] = _:skinSelected;
    }
    
nvault_set_array(vault_uskins_idszKeyuserUSKINSid ][ ePlayerUskins:], sizeofuserUSKINS[] ));
    

    return 
0;

how much information can be stored using nvault_array?

Last edited by aEEk; 05-26-2020 at 15:54.
aEEk is offline
Send a message via Yahoo to aEEk Send a message via Skype™ to aEEk
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-26-2020 , 16:47   Re: [INC] nVault Array
Reply With Quote #8

Shouldn't these codes:

PHP Code:
playerCases[i][id]     = userDATA[id][pdCases][i];
sttNumber stattrak[i][id];
killsNumber kill[i][id];
skinSelected UsingWeapon[i][id]; 
be
PHP Code:
playerCases[id[i]     = userDATA[id][pdCases][i];
sttNumber stattrak[id][i];
killsNumber kill[id][i];
skinSelected UsingWeapon[id][i]; 
I didn't look closely at your code but you are using many nvault array records, ideally you should have all data in the same one. Are you changing the save method of an existing plugin to use nVault array?
__________________

Last edited by Bugsy; 05-26-2020 at 18:15.
Bugsy is offline
aEEk
Member
Join Date: May 2012
Location: Romania
Old 05-27-2020 , 11:21   Re: [INC] nVault Array
Reply With Quote #9

Quote:
Originally Posted by Bugsy View Post
Shouldn't these codes:

PHP Code:
playerCases[i][id]     = userDATA[id][pdCases][i];
sttNumber stattrak[i][id];
killsNumber kill[i][id];
skinSelected UsingWeapon[i][id]; 
be
PHP Code:
playerCases[id[i]     = userDATA[id][pdCases][i];
sttNumber stattrak[id][i];
killsNumber kill[id][i];
skinSelected UsingWeapon[id][i]; 
I think it's same think, it depends how you declare variables (eg: new stattrak[MAX+1][33] where max could be more than 100)...


----
Quote:
I didn't look closely at your code but you are using many nvault array records, ideally you should have all data in the same one. Are you changing the save method of an existing plugin to use nVault array?
I choosed the option to separate data because I like the code to be clean and code readable and friendly to read.
First I have used nvault, but because there is so much data to store I faced some issues that data strings can not be so longer and had to split in more strings and using strok method, etc, headacke, with nvault_array is much easier. but now I am facing this...

Last edited by aEEk; 05-27-2020 at 11:23.
aEEk is offline
Send a message via Yahoo to aEEk Send a message via Skype™ to aEEk
Old 05-27-2020, 11:21
aEEk
This message has been deleted by aEEk.
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 05:10.


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