View Single Post
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 07-31-2021 , 19:25   Re: save nvault on plugin_end
Reply With Quote #6

Quote:
Originally Posted by Bugsy View Post
plugin_end() is only called on a graceful shutdown or map change. In the case of a crash, everything comes to a dead stop with no events getting triggered. You should concentrate on fixing the crash and then save data at disconnect.

Only other option is to save data at an interval using a timer/set_task(). I would avoid saving to vault every time data changes since you have a large number of variables.
plugin_end() is calling when the server get shotdown or map change??
But why when i close vault using function of plugin end() and if the server has shutdown the data doesn't get saved!!

Code:
PHP Code:
if ( ( g_Vault nvault_open"Bank" ) ) == INVALID_HANDLE )
        
set_fail_state"Error opening vault." );

public 
client_authorized(id
{
    
get_user_authidid g_iPlayerDataid ][ AuthID ] , charsmaxg_iPlayerData[ ][ AuthID ] ) );
    
get_user_nameid g_iPlayerDataid ][ Name ] , charsmaxg_iPlayerData[ ][ Name ] ) );
    
get_user_ipidg_iPlayerDataid ][ IP ] , charsmax(g_iPlayerData[ ][ IP ]), );
    
    if(!
is_user_hltv(id) && !is_user_bot(id))
    {
        
LoadData(id);
    }
}

public 
client_disconnect(id)
{
    if(!
is_user_hltv(id) && !is_user_bot(id))
    {
        
SaveData(id);
    }
}

public 
SaveData(id)
{
    new 
szData[8], szKey[64];   
        
    switch( 
get_pcvar_num(g_iCvars[SAVE_DATA]) )
    {
        case 
2formatex(szKey charsmax(szKey), "%s-NAME" g_iPlayerDataid ][ Name ] );
        case 
3formatex(szKey charsmax(szKey), "%s-IP" g_iPlayerDataid ][ IP ] );
        default: 
formatex(szKey charsmax(szKey), "%s-ID" g_iPlayerDataid ][ AuthID ] );
    }
        
    
formatexszData charsmaxszData ) , "%i" g_iPlayerDataid ][ Cash ] );
    
    
nvault_setg_Vault szKey szData );
}

public 
LoadData(id)
{
    new 
szData[8], szKey[64], iCash[10];   
        
    switch( 
get_pcvar_num(g_iCvars[SAVE_DATA]) )
    {
        case 
2formatex(szKey charsmax(szKey), "%s-NAME" g_iPlayerDataid ][ Name ] );
        case 
3formatex(szKey charsmax(szKey), "%s-IP" g_iPlayerDataid ][ IP ] );
        default: 
formatex(szKey charsmax(szKey), "%s-ID" g_iPlayerDataid ][ AuthID ] );
    }
        
    
formatexszData charsmaxszData ) , "%i" g_iPlayerDataid ][ Cash ] );
    
    
nvault_getg_VaultszKeyszDatacharsmax(szData) )
    
parse(szDataiCashcharsmax(iCash));
    
g_iPlayerDataid ][ Cash ] = str_to_num(iCash)
}

public 
plugin_end()
{
    
nvault_closeg_Vault );

Should i put the function of plugin_end() on the top of the plugin !?
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.

Last edited by Supremache; 07-31-2021 at 19:28.
Supremache is offline