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

Solved [Nvault] Save Data for particular Time Than Remove


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 05-28-2021 , 04:00   [Nvault] Save Data for particular Time Than Remove
Reply With Quote #1

Hello ..
as title says i wanted to Save Player Steam id in Nvault and after 'X' Minute Remove The Steam id from Nvault

Let me explain more
a player connected .. he called a Particular function (lets say he buys any item) than his Steam id saves in Nvault.. for 10 Minutes... After X minutes the Player calls the particular Function and before the Do, his steam id will check in Nvault if it exist block the Do. and if not exist than go on and Save again...

I hope i make you understand
__________________
SED LYF !!!

Last edited by SHIELD755; 06-01-2021 at 12:57.
SHIELD755 is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 05-28-2021 , 09:32   Re: [Nvault] Save Data for particular Time Than Remove
Reply With Quote #2

You could use nvault_lookup to also get the timestamp and compare with get_systime().
__________________








CrazY. is offline
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 05-28-2021 , 12:33   Re: [Nvault] Save Data for particular Time Than Remove
Reply With Quote #3

Quote:
Originally Posted by CrazY. View Post
You could use nvault_lookup to also get the timestamp and compare with get_systime().
Timestamp comes in which format ?
__________________
SED LYF !!!
SHIELD755 is offline
jimaway
Heeeere's Jimmy!
Join Date: Jan 2009
Location: Estonia
Old 05-28-2021 , 12:42   Re: [Nvault] Save Data for particular Time Than Remove
Reply With Quote #4

Quote:
Originally Posted by SHIELD755 View Post
Timestamp comes in which format ?
unix timestamp
jimaway is offline
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
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 05-31-2021 , 12:40   Re: [Nvault] Save Data for particular Time Than Remove
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
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 ];
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;

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 !!!
SHIELD755 is offline
SHIELD755
Veteran Member
Join Date: Feb 2018
Location: FROM MARVEL STUDIO
Old 06-01-2021 , 12:58   Re: [Nvault] Save Data for particular Time Than Remove
Reply With Quote #7

Solved.. thanks all
__________________
SED LYF !!!
SHIELD755 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 11:13.


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