|
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
|
05-31-2021
, 12:40
Re: [Nvault] Save Data for particular Time Than Remove
|
#6
|
Quote:
Originally Posted by Bugsy
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_prune( nvid , 0 , 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_szAuthID[ MAX_PLAYERS + 1 ];
new Trie:g_tPlayerUsedItem;
new g_pExpireMinutes;
public plugin_init()
{
g_tPlayerUsedItem = TrieCreate();
g_pExpireMinutes = register_cvar( "expire_minutes" , "10" );
}
public client_authorized( id )
{
get_user_authid( id , g_szAuthID[ id ] , charsmax( g_szAuthID[] ) );
}
public YourFunction( id )
{
if ( CanPlayerUseFunction( id ) )
{
//call something
PlayerUsedFunction( id );
}
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
}
}
PlayerUsedFunction( id )
{
TrieSetCell( g_tPlayerUsedItem , g_szAuthID[ id ] , get_systime() + ( get_pcvar_num( g_pExpireMinutes ) * 60 ) );
}
bool:CanPlayerUseFunction( id )
{
new iExpireTime , bool:bCanUse = true;
if ( TrieGetCell( g_tPlayerUsedItem , g_szAuthID[ id ] , iExpireTime ) )
{
if ( iExpireTime > get_systime() )
{
bCanUse = false;
}
else
{
TrieDeleteKey( g_tPlayerUsedItem , g_szAuthID[ id ] );
}
}
return bCanUse;
}
|
Thank you Bugsy i will try the Nvault thing because i want to save the data after the map change if happens between the 10 min… tries don’t save data on map changes thats why I can’t use that ..
__________________
SED LYF !!!
|
|
|
|