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

save nvault on plugin_end


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SoccerjamTR
Member
Join Date: May 2021
Old 07-30-2021 , 17:22   save nvault on plugin_end
Reply With Quote #1

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)
}
}    
    

SoccerjamTR is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-30-2021 , 20:56   Re: save nvault on plugin_end
Reply With Quote #2

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 );

__________________

Last edited by Bugsy; 07-30-2021 at 20:58.
Bugsy is offline
SoccerjamTR
Member
Join Date: May 2021
Old 07-31-2021 , 05:51   Re: save nvault on plugin_end
Reply With Quote #3

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.
SoccerjamTR is offline
Natsheh
Veteran Member
Join Date: Sep 2012
Old 07-31-2021 , 06:28   Re: save nvault on plugin_end
Reply With Quote #4

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.
__________________
@Jailbreak Main Mod v2.7.0 100%
@User Tag Prefix 100% done !
@Mystery Box 100% done !
@VIP System 100% done !

Natsheh is offline
Send a message via MSN to Natsheh Send a message via Skype™ to Natsheh
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 07-31-2021 , 13:10   Re: save nvault on plugin_end
Reply With Quote #5

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.
__________________

Last edited by Bugsy; 07-31-2021 at 16:14.
Bugsy is offline
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
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 08-01-2021 , 00:00   Re: save nvault on plugin_end
Reply With Quote #7

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.
__________________
Bugsy is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 08-01-2021 , 02:05   Re: save nvault on plugin_end
Reply With Quote #8

Quote:
Originally Posted by Bugsy View Post
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
__________________
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; 08-01-2021 at 08:14.
Supremache is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-01-2021 , 06:48   Re: save nvault on plugin_end
Reply With Quote #9

What does it mean when you say "the server get shut down"?
__________________
fysiks is offline
Supremache
Veteran Member
Join Date: Sep 2019
Location: Egypt
Old 08-01-2021 , 08:13   Re: save nvault on plugin_end
Reply With Quote #10

Quote:
Originally Posted by fysiks View Post
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
__________________
Youtube.com/Supremache

Bank System [Nvault - SQL Support]
VIP System
  • If you think it's that simple, then do it yourself.
Supremache 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 10:16.


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