Easiest fix. Not tested.
Code:
#include <amxmodx>
#include <cstrike>
#include <nvault>
#include <fakemeta>
#include <hamsandwich>
const OFFSET_CSMONEY = 115;
new g_szAuthID[33][35];
new g_iMoney[33];
new g_Vault;
new g_pStartMoney;
new bool:g_bRestored[33];
public plugin_init()
{
register_plugin("Restore Money" , "0.1" , "bugsy/blizzard");
RegisterHam(Ham_Spawn , "player" , "fw_HamSpawn_Post" , 1);
register_logevent("GameCommencing", 2, "1=Game_Commencing");
g_pStartMoney = get_cvar_pointer("MP_STARTMONEY");
g_Vault = nvault_open("LoadMoney");
}
public plugin_end()
{
nvault_close(g_Vault);
}
public client_authorized(id)
{
get_user_authid( id , g_szAuthID[id] , charsmax( g_szAuthID[] ) );
}
public client_putinserver(id)
{
if ( g_szAuthID[id][0] )
{
g_bRestored[id] = true;
set_task( 1.0 , "LoadMoney" , id );
}
}
public client_disconnect(id)
{
remove_task(id);
SaveMoney(id);
g_szAuthID[id][0] = EOS;
}
public fw_HamSpawn_Post(id)
{
if( ( g_szAuthID[id][0] && !g_bRestored[id] ) && is_user_alive(id) )
{
g_bRestored[id] = true;
LoadMoney(id);
}
}
public GameCommencing( ) {
new iPlayers[32], iNum, i, Players;
get_players( iPlayers, iNum, "h");
for( i = 0; i < iNum; i++ ) {
Players = iPlayers[i];
if ( g_bRestored[Players] ) {
SaveMoney(Players);
g_bRestored[Players] = false;
}
}
}
public SaveMoney(id)
{
new szKey[39] , szData[9];
formatex( szKey , charsmax(szKey) , "%s-SVB" , g_szAuthID[id] );
num_to_str( get_pdata_int(id , OFFSET_CSMONEY) , szData , charsmax(szData) );
g_bRestored[id] = false;
nvault_set( g_Vault , szKey , szData );
}
public LoadMoney(id)
{
new szKey[39];
formatex( szKey , charsmax(szKey) , "%s-SVB" , g_szAuthID[id] );
if ( (g_iMoney[id] = nvault_get( g_Vault ,szKey) ) && ( g_iMoney[id] != get_pcvar_num(g_pStartMoney) ) )
{
cs_set_user_money( id , g_iMoney[id] );
client_print( id , print_chat , "* Your money has been restored from a previous session: $%d" , g_iMoney[id] );
}
}