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

[INC] nVault Utility


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 10-02-2010 , 21:58   [INC] nVault Utility
Reply With Quote #1

nVault Utility
Update:
  • Removed nvault_get_array(), nvault_set_array(), nvault_util_read_array() and nvault_util_readall_array(). These functions were moved to the nVault Array include.

Note: The nVault array functions require 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 so an update is required. This fixed module is attached below and also available in AMX-X dev builds >= 4589. Thanks to Arkshine for fixing this so quickly for me. This fixed module is only required for nvault_set_array(), nvault_get_array(), nvault_util_read_array(), and nvault_util_readall_array(), but I recommend everyone updates anyway. You should be careful if your vault contains a mixture of regular entries and array entries if you plan to use the read and read_all functions. There is currently no code in place to differentiate the difference between a native string entry and an array entry and you could get data that you do not expect. This will be implemented in a future release.

This include file provides the ability to:
  • Retrieve the number of entries in a vault file.
  • Iterate through all entries one at a time.
  • Iterate through all entries with a single function call.
  • Store arrays in nvault.

Functions
  • nvault_util_open() - Open a vault.
  • nvault_util_close() - Close a vault.
  • nvault_util_count() - Number of items stored in vault.
  • nvault_util_pos() - Returns the file position of current vault.
  • nvault_util_read() - Read an entry.
  • nvault_util_readall() - Read all entries.
  • nvault_util_read_array() - Read an array.
  • nvault_util_readall_array() - Read all array entries from vault.

Descriptions
  • nvault_util_open( const szVault[] )
    This opens a vault file and returns a vault handle. Vault handles used by nvault and nvault_util are NOT interchangeable. If you are using nvault in your plugin in combination with nvault_util, you will be using 2 different nvault handles, one for each.
    Code:
    szVault[] - Name of vault to open (Usage is identical to nvault_open).
  • nvault_util_close( iVaultHandle )
    Close a vault handle. Again, this is only for closing vaults that were opened with nvault_util.
    Code:
    iVaultHandle - Vault handle to close.
  • nvault_util_count( iVaultHandle )
    This will return the total number of entries saved in a vault. An entry consists of [key,value,timestamp].
    Code:
    iVaultHandle - Vault handle to get number of entries.
  • nvault_util_pos( iVaultHandle )
    This function returns the current file position of the vault file. This can be used if, for any reason, you need to know exactly where in a vault file a particular entry exists. The return value is equal to ftell().
    Code:
    iVaultHandle - Vault handle to get position.
  • nvault_util_read( iVaultHandle , iOffset , szKey[] , iKeySize , szVal[] , iValSize , &iTimeStamp )
    This will read an entry from the vault file. The function returns an offset value which can then be used for the next function call to read the next entry in the vault file. Do NOT pass a random value as the offset because this will most likely cause a crash; use only 0 or a value returned by the function.
    Code:
    iVaultHandle - Vault handle to read from.
    iOffset - Offset to read from. Pass only 0 or a value that was returned from a previous nvault_util_read() call. Passing any other values will most likely result in a crash.
    szKey[] - The key for entry. (passed by ref)
    iKeySize - Max chars to read for key. (use charsmax( szKey ))
    szVal[] - The value for entry. (passed by ref) ,
    iValSize - Max chars to read for value. (use charsmax( szVal))
    iTimeStamp (Optional) - Timestamp for entry. (passed by ref)
  • nvault_util_readall( iVaultHandle , const szForwardFunc[] )
    This will read all entries in a vault file. Put all of your data handling in the forward function. You can use iCurrent and iTotal for determining exactly how many entries have been read and how many are left to read.
    Code:
    iVaultHandle - Vault handle the read from.
    szForwardFunc[] - Forward function where data from vault reading will be retrieved.
    Forward function params
    ForwardFunc( iCurrent , iTotal , const szKey[] , const szVal[] , iTimeStamp , Data[] , iSize )

    Code:
    iCurrent = Current entry being read.
    iTotal = Total number of entries in vault.
    szKey[] = Key for current entry.
    szVal[] = Value for current entry.
    iTimeStamp = Time stamp for current entry.
    Data[] = Array containing any data you need passed to forward.
    iSize = The size of data being passed.
  • nvault_util_read_array( iVaultHandle , iOffset , szKey[] , iKeySize , iArray[] , iArraySize , &iItemsRead , &iTimeStamp )
    This will read an array entry from the vault file. The function returns an offset value which can then be used for the next function call to read the next entry in the vault file. Do NOT pass a random value as the offset because this will most likely cause a crash; use only 0 or a value returned by the function.
    Code:
    iVaultHandle - Vault handle to read from.
    iOffset - Offset to read from. Pass only 0 or a value that was returned from a previous nvault_util_read() call. Passing any other values will most likely result in a crash.
    szKey[] - The key for entry. (passed by ref)
    iKeySize - Max chars to read for key. (use charsmax( szKey ))
    iArray[] - The array data for the entry. (passed by ref) ,
    iArraySize - Size of array for the data. (use sizeof( iArray ))
    iItemsRead (Optional) - The number of array items that were read (passed by ref)
    iTimeStamp (Optional) - Timestamp for entry. (passed by ref)
  • nvault_util_readall_array( iVaultHandle , const szForwardFunc[] )
    This will read all array entries in a vault file. Put all of your data handling in the forward function. You can use iCurrent and iTotal for determining exactly how many entries have been read and how many are left to read. Use iItemsRead to determine how many items in each array were read.
    Code:
    iVaultHandle - Vault handle the read from.
    szForwardFunc[] - Forward function where data from vault reading will be retrieved.
    Forward function params
    ForwardFunc( iCurrent , iTotal , const szKey[] , const iArray[] , iItemsRead , iTimeStamp , Data[] , iSize )

    Code:
    iCurrent = Current entry being read.
    iTotal = Total number of entries in vault.
    szKey[] = Key for current entry.
    iArray[] = Value for current entry.
    iItemsRead = The number of array items that were read for the current entry.
    iTimeStamp = Time stamp for current entry.
    Data[] = Array containing any data you need passed to forward.
    iSize = The size of data being passed.
nVault Utility example
Spoiler
Attached Files
File Type: zip nvault_amxx_fixed.zip (148.2 KB, 1667 views)
File Type: inc nvault_util.inc (6.5 KB, 1637 views)
__________________

Last edited by Bugsy; 12-22-2018 at 10:39. Reason: Removed nvault_get_array & nvault_set_array code example
Bugsy is offline
Emp`
AMX Mod X Plugin Approver
Join Date: Aug 2005
Location: Decapod 10
Old 10-02-2010 , 22:55   Re: [INC] nVault Utility
Reply With Quote #2

Nicely done.
Emp` is offline
Send a message via AIM to Emp` Send a message via MSN to Emp` Send a message via Yahoo to Emp` Send a message via Skype™ to Emp`
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 10-03-2010 , 02:17   Re: [INC] nVault Utility
Reply With Quote #3

good job man
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
xiaojian
Member
Join Date: Jan 2009
Location: the world's end
Old 10-08-2010 , 01:33   Re: [INC] nVault Utility
Reply With Quote #4

perfectly good!

Last edited by xiaojian; 11-07-2010 at 00:47.
xiaojian is offline
Enum
Junior Member
Join Date: Oct 2010
Location: ee.uu
Old 10-18-2010 , 21:40   Re: [INC] nVault Utility
Reply With Quote #5

Perfect ;)
Enum is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 11-06-2010 , 22:44   Re: [INC] nVault Utility
Reply With Quote #6

Code:
public plugin_cfg()
{
    g_iValut = nvault_util_open( "valut" );
}
public client_authorized( id )
{
    get_user_authid( id , g_szAuthid[ id ] , charsmax( g_szAuthid[] ) );
 
    new iPos , szKey[ 32 ] , szVal[ 64 ] , iTimeStamp;
    new iCount = nvault_util_count( g_iValut );
 
    for ( new iCurrent = 1 ; iCurrent <= iCount ; iCurrent++ )
    {
        iPos = nvault_util_read( g_iValut , iPos , szKey , charsmax( szKey ) , szVal , charsmax( szVal ) , iTimeStamp );
        if ( equal( szKey , g_szAuthid[ id ] ) )
        {
            g_iVal[ id ] = str_to_num( szVal );
            break;
        }
    }
}
 
public plugin_end()
{
    nvault_util_close( g_iValut );
}
Is it right ?
if so, the problem is coming,
1. whether I should use the loop to get the player data when player is connecting to the server ?
2. If I want to set player data, just use nvault's nvault_set(), right ?
__________________
QQ:116268742

Last edited by K.K.Lv; 11-06-2010 at 22:49.
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-06-2010 , 23:32   Re: [INC] nVault Utility
Reply With Quote #7

Don't keep the vault open the whole map since it is a file handle and not an actual vault.
Open it each time it's being used.

Also, don't use a loop if you are just reading a value for a known key. Use nvault_get().

Yes, nvault_set() will work, but nvault_open() and nvault_util_open() are 2 different handles so you cannot mix handles between the nvault and nvault util.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
K.K.Lv
Veteran Member
Join Date: Aug 2008
Location: GameFolder
Old 11-07-2010 , 00:06   Re: [INC] nVault Utility
Reply With Quote #8

the problem is I want to get all entry from the valut when map start and new round, and set the data in clinet disconnect, round end ?

how to get it ?
just use nvalut can handle it ?
__________________
QQ:116268742
K.K.Lv is offline
Send a message via MSN to K.K.Lv
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 11-07-2010 , 01:40   Re: [INC] nVault Utility
Reply With Quote #9

This utility is only for when you need to read all entries in an nvault.
In all other cases, use the default natives for nvault.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Jacob
Senior Member
Join Date: Oct 2010
Old 11-09-2010 , 21:28   Re: [INC] nVault Utility
Reply With Quote #10

Quote:
Originally Posted by Exolent[jNr] View Post
Don't keep the vault open the whole map since it is a file handle and not an actual vault.
Open it each time it's being used.

Also, don't use a loop if you are just reading a value for a known key. Use nvault_get().

Yes, nvault_set() will work, but nvault_open() and nvault_util_open() are 2 different handles so you cannot mix handles between the nvault and nvault util.
Exolent, if keep the vault open the whole map,will it cause Reliable channel overflowed ?

Last edited by Jacob; 11-09-2010 at 22:54.
Jacob 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 05:53.


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