View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-28-2021 , 16:25   Re: [Nvault] Save Data for particular Time Than Remove
Reply With Quote #5

Another method, which will also keep your vault smaller, is to call nvault_prune() every minute or so, instead of letting the records build up and checking each individual players timestamp.

This will delete all records in the vault that are 10 minutes and older.
PHP Code:
nvault_prunenvid get_systime() - 600 ); 

Or, in addition to what was already suggested using nvault_lookup (which may be a little more efficient than calling nvault_prune() repeatedly), call nvault_prune() on map change to cleanup the vault. You can either clear all records with this, or only those that are 10+ minutes old.

Also consider using trie (not tested)
PHP Code:

#include <amxmodx>

#define MAX_PLAYERS 32

new g_szAuthIDMAX_PLAYERS ][ 34 ];
new 
Trie:g_tPlayerUsedItem;
new 
g_pExpireMinutes;

public 
plugin_init()
{
    
g_tPlayerUsedItem TrieCreate();
    
g_pExpireMinutes register_cvar"expire_minutes" "10" );
}

public 
client_authorizedid )
{
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
}

public 
YourFunctionid )
{
    if ( 
CanPlayerUseFunctionid ) )
    {
        
//call something
        
PlayerUsedFunctionid );
    }
    else
    {
        
//tell player that function can only be called every 10 minutes.
        //you could read the value from trie and tell the player the exact time, down to second, when they can use it again
    
}
}

PlayerUsedFunctionid )
{
    
TrieSetCellg_tPlayerUsedItem g_szAuthIDid ] , get_systime() + ( get_pcvar_numg_pExpireMinutes ) * 60 ) );
}

bool:CanPlayerUseFunctionid )
{
    new 
iExpireTime bool:bCanUse true;
    
    if ( 
TrieGetCellg_tPlayerUsedItem g_szAuthIDid ] , iExpireTime ) )
    {
        if ( 
iExpireTime get_systime() )
        {
            
bCanUse false;
        }
        else
        {
            
TrieDeleteKeyg_tPlayerUsedItem g_szAuthIDid ] );
        }
    }
    
    return 
bCanUse;

__________________

Last edited by Bugsy; 05-31-2021 at 22:01.
Bugsy is offline