AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   save nvault on plugin_end (https://forums.alliedmods.net/showthread.php?t=333710)

SoccerjamTR 07-30-2021 17:22

save nvault on plugin_end
 
I have this public and it is working in plugin_init but it is not working or saving on plugin_end. What is wrong my code can you help me?
PHP Code:

public saveVault(){
        new 
id
        
for(id=1id<=maxplayersid++) {
        if(!
is_user_bot(id)) {
        new 
szKey[64];
        new 
playername[MAX_PLAYER 1]
        
get_user_name(idplayernameMAX_PLAYER);
        
formatex(szKey 63 "%s-ID#" playername)    
        new 
szData[256]
        
formatex(szData 255 "%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#",a[id], b[id], c[id][aba],d[id][ada],e[id][ava],
        
f[id][ata],g[id][aza],h[id][aha],i[id][ala],j[id][aja],k[id][aka],
        
l[id][afa],m[id][ama],n[id],o[id][aya],p[id][ara],
        
r[id][sa],s[id][as],t[id][aca],u[id][ayas],v[id][sc],y[id],z,se,ke,te,ce,ze,xd,kd)
        
nvault_set(yukleVaultszKey szData)
}
}    
    



Bugsy 07-30-2021 20:56

Re: save nvault on plugin_end
 
You need to provide more code if you want help.

I made a few improvements to your above save function, but its likely not the cause of your problem.

When is saveVault() called? You may want to instead call it on each individual player as they leave, instead of all players who are on the server when the map changes or shutsdown. You are not currently getting all player data saved if you are saving at plugin_end(), since players come and go throughout a single map. I provided the client_disconnect() version below.

PHP Code:

public saveVault()
{
    new 
iPlayers32 ] , iNum id;
    new 
szKey37 ] , szData256 ];

    
get_playersiPlayers iNum "ch" );
    
    for ( new 
iNum i++ ) 
    {
        
id iPlayers];
        
        
get_user_nameid szKey charsmaxszKey ) );
        
addszKey charsmaxszKey ) , "-ID#" );
        
        
formatexszData charsmaxszData ) , "%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#",a[id], b[id], c[id][aba],d[id][ada],e[id][ava],
            
f[id][ata],g[id][aza],h[id][aha],i[id][ala],j[id][aja],k[id][aka],
            
l[id][afa],m[id][ama],n[id],o[id][aya],p[id][ara],
            
r[id][sa],s[id][as],t[id][aca],u[id][ayas],v[id][sc],y[id],z,se,ke,te,ce,ze,xd,kd)
        
        
nvault_setyukleVault szKey szData );
    }    
    


You can call this on a player at client_disconnect( id )
PHP Code:

public saveVaultid )
{
    new 
szKey37 ] , szData256 ];

    
get_user_nameid szKey charsmaxszKey ) );
    
addszKey charsmaxszKey ) , "-ID#" );
    
    
formatexszData charsmaxszData ) , "%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#%i#",a[id], b[id], c[id][aba],d[id][ada],e[id][ava],
        
f[id][ata],g[id][aza],h[id][aha],i[id][ala],j[id][aja],k[id][aka],
        
l[id][afa],m[id][ama],n[id],o[id][aya],p[id][ara],
        
r[id][sa],s[id][as],t[id][aca],u[id][ayas],v[id][sc],y[id],z,se,ke,te,ce,ze,xd,kd)
    
    
nvault_setyukleVault szKey szData );



SoccerjamTR 07-31-2021 05:51

Re: save nvault on plugin_end
 
First public at plugin_end didn't work and didn't save vault. However at plugin_init worked like my previous code.
Second public(at client_discconect) worked and saved. Does the reason stems from the fact that much of the value? I want plugin_end but i need all of players's value simultaneously and i do not want to be saved I do not want an disconnect and i want only save at server crash. I need players only on when server crashed.

Natsheh 07-31-2021 06:28

Re: save nvault on plugin_end
 
Well you need to open nvault file and save data then close nvault, you need to do this setup each time a value changes.

Best choice is to fix the server and prevent the crash.

Bugsy 07-31-2021 13:10

Re: save nvault on plugin_end
 
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.

Supremache 07-31-2021 19:25

Re: save nvault on plugin_end
 
Quote:

Originally Posted by Bugsy (Post 2754225)
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 !?

Bugsy 08-01-2021 00:00

Re: save nvault on plugin_end
 
I didn't read your code thoroughly, but loading at authorized, saving at disconnect, and closing at plugin_end() is the ideal way for storing data, IMO. It doesn't matter where you place the function in your code.

Supremache 08-01-2021 02:05

Re: save nvault on plugin_end
 
Quote:

Originally Posted by Bugsy (Post 2754258)
I didn't read your code thoroughly, but loading at authorized, saving at disconnect, and closing at plugin_end() is the ideal way for storing data, IMO. It doesn't matter where you place the function in your code.

I actually did this but when the server get shut down the data doesn't get saved, I added code for saving the data every 30 second for that reason.

Full code:
Spoiler

fysiks 08-01-2021 06:48

Re: save nvault on plugin_end
 
What does it mean when you say "the server get shut down"?

Supremache 08-01-2021 08:13

Re: save nvault on plugin_end
 
Quote:

Originally Posted by fysiks (Post 2754285)
What does it mean when you say "the server get shut down"?

I mean if I have stopped the server using host or the server has shutdown the data doesn't get saved


All times are GMT -4. The time now is 22:02.

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