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 iPlayers[ 32 ] , iNum , id; new szKey[ 37 ] , szData[ 256 ];
get_players( iPlayers , iNum , "ch" );
for ( new i = 0 ; i < iNum ; i++ ) { id = iPlayers[ i ];
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.
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 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!!
public client_authorized(id) { get_user_authid( id , g_iPlayerData[ id ][ AuthID ] , charsmax( g_iPlayerData[ ][ AuthID ] ) ); get_user_name( id , g_iPlayerData[ id ][ Name ] , charsmax( g_iPlayerData[ ][ Name ] ) ); get_user_ip( id, g_iPlayerData[ id ][ IP ] , charsmax(g_iPlayerData[ ][ IP ]), 1 );
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 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.
/* Save the data using ( SteamID, Name, IP ) * SteamID = 1 - Name = 2 - IP = 3 */ g_iCvars[SAVE_DATA] = register_cvar( "save_type", "1"); g_iCvars[LIMIT] = register_cvar( "limit_cash", "1"); //Change to 0 if u want to be able to withdraw / deposit more than 16k$ g_iCvars[MAX_CASH] = register_cvar( "max_cash", "16000"); // Maximum cash withdraw / deposit from/to the bank g_iCvars[MAX_CASH_SAVE] = register_cvar( "max_cash", "100000000"); // Maximum cash saving in the bank
public plugin_cfg() { set_task(AUTO_SAVE, "AutoSave", _, _, _, "b") }
public AutoSave() { for( new i ; i < g_iMaxPlayers ; i++ ) { if( is_user_connected(i) ) ReadData(i, SAVE); } }
public client_authorized(id) { get_user_authid( id , g_iPlayerData[ id ][ AuthID ] , charsmax( g_iPlayerData[ ][ AuthID ] ) ); get_user_name( id , g_iPlayerData[ id ][ Name ] , charsmax( g_iPlayerData[ ][ Name ] ) ); get_user_ip( id, g_iPlayerData[ id ][ IP ] , charsmax(g_iPlayerData[ ][ IP ]), 1 );
new const iData[][] = { "Deposit", "Deposit All^n", "Withdraw", "Withdraw All^n", "Check Your Cash", "Donate", "Reset Bank" }
for( new i ; i < sizeof ( iData ) ; i++ ) { formatex(szData, charsmax(szData), "%s", iData[i]); menu_additem(iMenu, szData, ""); }
menu_setprop(iMenu, MPROP_EXITNAME, "\rClose")
menu_display(id, iMenu) return PLUGIN_HANDLED }
public Handler(id, iMenu, iItem) { if(iItem != MENU_EXIT) { switch(iItem) { case 0: { client_cmd(id, "messagemode DepositCash"); set_hudmessage(255, 255, 85, 0.01, 0.18, 2, 0.5, 6.0, 0.05, 0.05, -1); show_hudmessage(id, "Type how much you want to deposit."); } case 1: DepositAllCash(id); case 2: { client_cmd(id, "messagemode TakeCash"); set_hudmessage(255, 255, 85, 0.01, 0.18, 2, 0.5, 6.0, 0.05, 0.05, -1); show_hudmessage(id, "Type how much you want to take."); } case 3: WithdrawAllCash(id); case 4: CC_SendMessage(id,"Your Cash is:^4 %d", g_iPlayerData[ id ][ Cash ]); case 5: DonateMenu(id) case 6: ResetMenu(id) } } menu_destroy(iMenu); return PLUGIN_HANDLED }
/* 1. UserID 2. Menu Access 3. Menu Title 4. Menu Handler 5. Player Flags - P.s: 's' = do not include self client */ public DonateMenu(id) { PlayerMenu ( id, " ", "\yChoose a player: \r[Donate]", "Donate_Handler", "chs" ) }
public ResetMenu(id) { PlayerMenu ( id, "a", "\yChoose a player: \r[Reset Bank]", "Reset_Handler", "chs" ) }
public DepositAllCash(id) { new iCash = get_user_cash(id);
if( iCash <= 0) { CC_SendMessage(id,"You do not have enough money or invalid value."); return PLUGIN_CONTINUE; }
if( g_iPlayerData[ id ][ Cash ] > get_pcvar_num(g_iCvars[MAX_CASH_SAVE]) ) { CC_SendMessage(id,"Your bank is full."); return PLUGIN_CONTINUE }
CC_SendMessage(id,"You have deposit^4 %i.", iCash); g_iPlayerData[ id ][ Cash ] += iCash; set_user_cash(id, iCash - iCash); ReadData(id, SAVE);
return PLUGIN_HANDLED; }
public WithdrawAllCash(id) { new iCash = get_user_cash(id); new iBankCash;
if( g_iPlayerData[ id ][ Cash ] <= 0) { CC_SendMessage(id,"You do not have enough money or invalid value."); return PLUGIN_CONTINUE }
if( get_pcvar_num(g_iCvars[LIMIT]) != 1) { CC_SendMessage(id,"You have withdraw^4 %i.", g_iPlayerData[ id ][ Cash ]); g_iPlayerData[ id ][ Cash ] -= g_iPlayerData[ id ][ Cash ] set_user_cash(id, iCash + g_iPlayerData[ id ][ Cash ]); } else { iBankCash = get_pcvar_num(g_iCvars[MAX_CASH]) - iCash;
if(g_iPlayerData[ id ][ Cash ] < iBankCash) { CC_SendMessage(id,"You have withdraw^4 %i.", g_iPlayerData[ id ][ Cash ]); set_user_cash(id, iCash + g_iPlayerData[ id ][ Cash ]); g_iPlayerData[ id ][ Cash ] -= g_iPlayerData[ id ][ Cash ]; } else { CC_SendMessage(id,"You have withdraw^4 %i.", g_iPlayerData[ id ][ Cash ]); set_user_cash(id, iCash + iBankCash); g_iPlayerData[ id ][ Cash ] -= iBankCash; } }
if( g_iPlayerData[ id ][ Cash ] < iValue || iValue <= 0) { CC_SendMessage(id,"You do not have enough money or invalid value."); return PLUGIN_CONTINUE }