Raised This Month: $196 Target: $400
 49% 

FVault - A new vault system!


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-24-2008 , 18:23   FVault - A new vault system!
Reply With Quote #1

I created this for a few reasons:
  • This does not require any special modules. All that is required is:
    Code:
    #include <amxmodx> #include <fvault>
  • Has the ability to iterate through all vault names and all vault keys within each vault.
  • Keeps the original functionality of nvault with more features.

Functions:
  • PHP Code:
    /** 
     * Retrieves a key name specified by its number
     * 
     * @param vaultname    Vault name to look in
     * @param keynum    Key number within the vault to find key name
     * @param key        String which key name will be copied to
     * @param len        Length of key name
     * @return        Returns 1 on success, 0 on failue.
     */
    fvault_get_keyname(const vaultname[], const keynumkey[], len
  • PHP Code:
    /** 
     * Retrieves a key number specified by its name
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to search for
     * @return        Returns key number on success, -1 on failure
     */
    fvault_get_keynum(const vaultname[], const key[]) 
  • PHP Code:
    /** 
     * Retrieves data specified by a key
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to look for the data
     * @param data        String which data will be copied to
     * @param len        Length of data
     * @param timestamp    The unix time of when the data was last set ( -1 if permanent data, 0 if old fvault version ) ( optional param )
     * @return        Returns 1 on success, 0 on failue.
     */
    fvault_get_data(const vaultname[], const key[], data[], len, &timestamp=0
  • PHP Code:
    /** 
     * Sets data of a key with current timestamp
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to which data will be set
     * @param data        Data to set to key
     * @return        Does not return a value.
     */
    fvault_set_data(const vaultname[], const key[], const data[]) 
  • PHP Code:
    /** 
     * Sets data of a key permanently (can't be removed with fvault_prune)
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key name to which data will be set
     * @param data        Data to set to key
     * @return        Does not return a value.
     */
    fvault_pset_data(const vaultname[], const key[], const data[]) 
  • PHP Code:
    /** 
     * Removes a key from a vault
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key to remove
     * @return        No return
     */
    fvault_remove_key(const vaultname[], const key[]) 
  • PHP Code:
    /**
     * Prunes the vault for keys that are within the given timestamps
     * 
     * @param vaultname    Vault name to look in
     * @param start        If timestamp is after this Unix Time (set -1 to prune from very start)
     * @param end        If timestamp is before this Unix Time (set -1 to prune to most time)
     * @return        Returns number of keys pruned
     */
    fvault_prune(const vaultname[], const start=-1, const end=-1
  • PHP Code:
    /**
     * Updates the timestamp on a key located within the vault
     * 
     * @param vaultname    Vault name to look in
     * @param key        Key to update timestamp (if it doesn't exist, a blank value will be set)
     * @param timestamp    Unix Time to set for the key (-1 for current time)
     * @return        Returns 2 on new entry, 1 on success, 0 on failure for the key having a permanent timestamp
     */
    fvault_touch(const vaultname[], const key[], const timestamp=-1
  • PHP Code:
    /** 
     * Retrieves total keys located within the vault
     * 
     * @param vaultname    Vault name to look in
     * @return        Returns amount of keys in vault
     */
    fvault_size(const vaultname[]) 
  • PHP Code:
    /** 
     * Clears all key entries for a vault
     * 
     * @param vaultname    Vault name to erase
     * @return        No return
     */
    fvault_clear(const vaultname[]) 
  • PHP Code:
    /** 
     * Retrieves a vault name specified by its number
     * 
     * @param vaultnum    Vault number to find the vault name
     * @param vaultname    String which vault name will be copied to
     * @param len        Length of vault name
     * @return        Returns 1 on success, 0 on failue.
     */
    fvault_get_vaultname(const vaultnumvaultname[], len
  • PHP Code:
    /** 
     * Retrieves a vault number specified by its name
     * 
     * @param vaultname    Vault name to find the number
     * @return        Returns vault number on success, -1 on failure
     */
    fvault_get_vaultnum(const vaultname[]) 
  • PHP Code:
    /** 
     * Retrieves total vaults ever created
     * 
     * @return        Returns amount of vaults
     */
    fvault_total() 
  • PHP Code:
    /**
     * Gets all vault keys, data, and timestamps
     * 
     * @param        vaultname - Vault name to look in
     * @param        keys - cellarray holding all of the keys
     * @param        datas - cellarray holding all of the data values
     * @param        timestamps - cellarray holding all of the timestamps
     * 
     * @return        Returns total number of entries in vault
     * 
     * @note        keys needs to be created like this: ArrayCreate(64)
     *             datas needs to be created like this: ArrayCreate(512)
     *             timestamps need to be created like this: ArrayCreate()
     */
    fvault_load(const vaultname[], Array:keys=Invalid_Array, Array:datas=Invalid_Array, Array:timestamps=Invalid_Array

Some examples:
  • Code:
    // How to find all vaults created: new total = fvault_total(); new vaultname[32]; for( new i = 0; i < total; i++ ) {     fvault_get_vaultname(i, vaultname, sizeof(vaultname) - 1);     server_print("Vault [%i]: %s", i, vaultname); }
  • Code:
    // How to find all keys within a vault: new const vaultname[] = "myvault"; new total = fvault_size(vaultname); new key[32], data[64]; for( new i = 0; i < total; i++ ) {     fvault_get_keyname(vaultname, i, key, sizeof(key) - 1);     fvault_get_data(vaultname, key, data, sizeof(data) - 1);         server_print("Key: %s | Data: %s", key, data); }
  • Code:
    // More efficient method to find all keys within a vault: new const vaultname[] = "myvault"; new Array:keys = ArrayCreate(64); new Array:datas = ArrayCreate(512); new total = fvault_load(vaultname, keys, datas); new key[64], data[512]; for( new i = 0; i < total; i++ ) {     ArrayGetString(keys, i, key, 31);     ArrayGetString(datas, i, data, 511);         server_print("Key: %s | Data: %s", key, data); }
  • Code:
    // Pruning player agree/decline after 15 days of not being updated // 15 days * 24 hours * 60 minutes * 60 seconds = 15 days in seconds new end_prune_time = get_systime() - (15 * 24 * 60 * 60); fvault_prune("player_agree", _, end_prune_time);
  • Code:
    // A simple exp mod #include <amxmodx> #include <fvault> new const g_vault_name[] = "EXP_MOD"; new g_exp[33]; public client_authorized(plr) {     if( !is_user_hltv(plr) && !is_user_bot(plr) )     {         LoadExp(plr);     } } public client_disconnect(plr) {     if( g_exp[plr] > 0 )     {         SaveExp(plr);                 g_exp[plr] = 0;     } } LoadExp(plr) {     new authid[35];     get_user_authid(plr, authid, sizeof(authid) - 1);         new data[16];     if( fvault_get_data(g_vault_name, authid, data, sizeof(data) - 1) )     {         g_exp[plr] = str_to_num(data);     }     else     {         g_exp[plr] = 0;     } } SaveExp(plr) {     new authid[35];     get_user_authid(plr, authid, sizeof(authid) - 1);         new data[16];     num_to_str(g_exp[plr], data, sizeof(data) - 1);         fvault_set_data(g_vault_name, authid, data); }

If there are any problems, please tell me so that I can fix them.
Attached Files
File Type: inc fvault.inc (14.3 KB, 6658 views)
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!

Last edited by Exolent[jNr]; 02-07-2011 at 00:21. Reason: Updated.
Exolent[jNr] is offline
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 08-24-2008 , 18:46   Re: FVault - A new vault system!
Reply With Quote #2

[1] You didn't test it? Beyond wow.

[2] If you're going to post a new vault system, make damn sure you list the advantages and disadvantages compared to existing methods.

Brad is offline
Alka
AMX Mod X Plugin Approver
Join Date: Dec 2006
Location: malloc(null)
Old 08-24-2008 , 18:58   Re: FVault - A new vault system!
Reply With Quote #3

I remember that i maked something like this too, but was named "fdata.inc", anyway good job.
__________________
Still...lovin' . Connor noob! Hello
Alka is offline
minimiller
Veteran Member
Join Date: Aug 2007
Location: United Kingdom
Old 08-24-2008 , 19:04   Re: FVault - A new vault system!
Reply With Quote #4

Brad +1
What are the advantages of this over nVault?
__________________
minimiller is offline
Send a message via MSN to minimiller
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 08-24-2008 , 19:56   Re: FVault - A new vault system!
Reply With Quote #5

Just a suggestion,on _FormatVaultName, the invalid characters can be a one dimension array if you make the identifiers characters instead of strings(' instead of ").
Edit: Just saw,you're using replace,that needs a string. Just ignore it.

Last edited by danielkza; 08-24-2008 at 20:00.
danielkza is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 08-24-2008 , 20:22   Re: FVault - A new vault system!
Reply With Quote #6

Vaults are ridiculously slow. It's much better to use celltravtrie for this purpose in general. Also, celltravtrie uses iterators rather than a static nth value for iteration.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 08-25-2008 , 16:40   Re: FVault - A new vault system!
Reply With Quote #7

Updated:
  • Added fvault_remove_key()
  • Added fvault_clear()
  • Fixed compile error "define"
    - Thanks atomen for pointing out
  • Fixed bug in fvault_get_keyname()
    - Thanks atomen for pointing out
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-01-2008 , 13:59   Re: FVault - A new vault system!
Reply With Quote #8

Updated:
  • Fixed fvault_set_data()
    - Thanks atomen
  • Fixed description for fvault_remove_key()
    - Thanks atomen
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
atomen
Veteran Member
Join Date: Oct 2006
Location: Stockholm, Sweden
Old 09-01-2008 , 14:06   Re: FVault - A new vault system!
Reply With Quote #9

Great, thanks for the quick update!
__________________
atomen is offline
Send a message via MSN to atomen
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 09-02-2008 , 18:56   Re: FVault - A new vault system!
Reply With Quote #10

Updated!
  • Fixed fvault_set_data()
  • Fixed fvault_get_keyname()
  • Fixed fvault_get_keynum()
  • Fixed fvault_get_vaultname()
  • Fixed fvault_get_vaultnum()
  • Changed fvault_size()
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 09:57.


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