Description This inc file have functions for saving/retrieving designed for beginners, if you know how to use nvault please DO NOT USE THIS INC.
Source
Spoiler
Code:
#if defined _nvp_included
#endinput
#endif
#define _nvp_included
#include <nvault>
/**
* Open a vault by its name.
*
* @param VaultName The vault name to open/create if non-existend.
* @return: Vault Id
*
*/
stock nvp_open( VaultName[] )
{
new iOpened = nvault_open( VaultName );
new iClosed;
/**
* Save an integer to an index.
*
* @param Vaultid The id of the vault.(The handler)
* @param id The index of the player.
* @pram Symbol[] The Symbol to make unique the save for your needs/plugin.
* @param Integer The Integer to save.
* @return true/false If we found the 'id' saved.
*/
stock nvp_set_integer( VaultId, id, const Symbol[], int)
{
new szAuthId[34]; get_user_authid( id, szAuthId, charsmax(szAuthId) );
new buffer[64]; formatex( buffer, charsmax(buffer), "%s%s", szAuthId, Symbol );
new szData[11]; num_to_str( int, szData, charsmax( szData ) );
nvault_set( VaultId, buffer, szData );
}
/**
* Retrieve an integer from an index.
*
* @param Vaultid The id of the vault.(The handler)
* @param id The index of the player.
* @param Symbol[] The symbol to perform the search.
* @param Integer The Integer to save.
* @return The Integer result.
*/
stock nvp_get_integer( VaultId, id, const Symbol[] )
{
new szAuthId[34]; get_user_authid( id, szAuthId, charsmax(szAuthId) );
new buffer[64]; formatex( buffer, charsmax(buffer), "%s%s", szAuthId, Symbol );
/**
* Save an string to an index.
*
* @param Vaultid The id of the vault.(The handler)
* @param id The index of the player.
* @pram Symbol[] The Symbol to make unique the save for your needs/plugin.
* @param String[] The string to save.
* @noreturn
*/
stock nvp_set_string( VaultId, id, const Symbol[], const String[])
{
new szAuthId[34]; get_user_authid( id, szAuthId, charsmax(szAuthId) );
new buffer[64]; formatex( buffer, charsmax(buffer), "%s%s", szAuthId, Symbol );
nvault_set( VaultId, buffer, String );
}
/**
* Retrieve an string from an index.
*
* @param Vaultid The id of the vault.(The handler)
* @param id The index of the player.
* @param Symbol[] The symbol to perform the search.
* @param String[] The string to copy data from the savement.
* @param maxchars The lengh of the String[] ( use charsmax(String[]) ).
* @noreturn
*/
stock nvp_get_string( VaultId, id, const Symbol[], const String[], maxchars=0 )
{
new szAuthId[34]; get_user_authid( id, szAuthId, charsmax(szAuthId) );
new buffer[64]; formatex( buffer, charsmax(buffer), "%s%s", szAuthId, Symbol );
new iTs;
return nvault_lookup( VaultId, buffer, String, maxchars, iTs );
}
/**
* Reset the vault, so it deletes all the entries
* @noreturn
*/
stock nvp_reset( VaultId )
{
nvault_prune( VaultId, 0, get_systime( ) );
}
Testing code
Spoiler
PHP Code:
#include <amxmodx> #include <nvp>
new VaultId; #define SYMBOL "HealthTest"
public plugin_init() { VaultId = nvp_open("MyVaultTest");