Raised This Month: $ Target: $400
 0% 

Get Players Money at Disconnect throws error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-13-2013 , 09:52   Re: Get Players Money at Disconnect throws error
Reply With Quote #1

The problem is that this only happens sometimes and there is no error in log.

PHP Code:
public save_user_money(id)
{  
    new 
AuthID[35
    
get_user_authid(id,AuthID,34
    new 
vaultkey[64],vaultdata[256
    
    
format(vaultkey,63,"%s-SVB",AuthID
    
format(vaultdata,255,"%i",g_iMoney[id]) 
    
    
nvault_set(g_Vault,vaultkey,vaultdata
    return 
PLUGIN_CONTINUE 
}  

public 
load_user_money(id)

    new 
AuthID[35]
    
get_user_authid(id,AuthID,34
    
    new 
vaultkey[64],vaultdata[256]  
    
format(vaultkey,63,"%s-SVB",AuthID
    
format(vaultdata,255,"%i",g_iMoney[id]) 
    
    
nvault_get(g_Vault,vaultkey,vaultdata,255
    new 
iMoney[32]
    
parse(vaultdataiMoney31
    
g_iMoney[id] = str_to_num(iMoney)
    return 
PLUGIN_CONTINUE 

__________________

Last edited by Kia; 05-13-2013 at 09:53.
Kia is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2013 , 10:02   Re: Get Players Money at Disconnect throws error
Reply With Quote #2

Where are you calling load_user_money()?
__________________
Bugsy is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-13-2013 , 10:06   Re: Get Players Money at Disconnect throws error
Reply With Quote #3

PHP Code:
public client_authorized(id)
{
    
g_iMoney[id] = 0
    g_bHasLoaded
[id] = false
    
    load_user_money
(id)
}

public 
playerSpawn(id)
{
    new 
money cs_get_user_money(id)
    if(
money == g_iStartmoney || !g_bHasLoaded[id])
    {
        
set_task(1.0,"set_user_saved_money",id)
        
g_bHasLoaded[id] = true
    
}
    else
    {
        
g_iMoney[id] = money
        set_task
(1.0,"set_user_saved_money",id)
    }
}
public 
set_user_saved_money(id)
{
    
cs_set_user_money(id,g_iMoney[id])

__________________

Last edited by Kia; 05-13-2013 at 10:06.
Kia is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2013 , 11:29   Re: Get Players Money at Disconnect throws error
Reply With Quote #4

Try this

*Edited*
PHP Code:

#include <amxmodx>
#include <cstrike>
#include <nvault>
#include <fakemeta>
#include <hamsandwich>

const OFFSET_CSMONEY 115;

new 
g_szAuthID33 ][ 35 ];
new 
g_iMoney33 ];
new 
g_Vault;
new 
g_pStartMoney;
new 
bool:g_bRestored33 ];

public 
plugin_init()
{
    
register_plugin"Restore Money" "0.1" "bugsy" );
    
    
RegisterHamHam_Spawn "player" "fw_HamSpawn_Post" );
    
    
g_pStartMoney get_cvar_pointer"MP_STARTMONEY" );
    
    
g_Vault nvault_open"LoadMoney" );
}

public 
plugin_end()
{
    
nvault_closeg_Vault );
}

public 
client_authorizedid )
{
    
get_user_authidid g_szAuthIDid ] , charsmaxg_szAuthID[] ) );
}

public 
client_putinserverid )
{
    if ( 
g_szAuthIDid ][ ] )
    {
        
g_bRestoredid ] = true;
        
set_task1.0 "LoadMoney" id );
    }
}

public 
client_disconnectid )
{
    
remove_taskid );
    
SaveMoneyid );
    
g_szAuthIDid ][ ] = EOS;
}

public 
fw_HamSpawn_Postid )
{
    if( ( 
g_szAuthIDid ][ ] && !g_bRestoredid ] ) && is_user_aliveid ) )
    {
        
g_bRestoredid ] = true;
        
LoadMoneyid );
    }
}

public 
SaveMoneyid )
{  
    new 
szKey39 ] , szData];
    
formatexszKey charsmaxszKey ) , "%s-SVB" g_szAuthIDid ] );
    
num_to_strget_pdata_intid OFFSET_CSMONEY ) , szData charsmaxszData ) );
    
g_bRestoredid ] = false;

    
nvault_setg_Vault szKey szData );
}  

public 
LoadMoneyid )

    new 
szKey39 ];
    
    
formatexszKey charsmaxszKey ) , "%s-SVB" g_szAuthIDid ] );

    if ( ( 
g_iMoneyid ] = nvault_getg_Vault ,szKey ) ) && ( g_iMoneyid ] != get_pcvar_numg_pStartMoney ) ) )
    {
        
cs_set_user_moneyid g_iMoneyid ] );
        
client_printid print_chat "* Your money has been restored from a previous session: $%d" g_iMoneyid ] );
    }

__________________

Last edited by Bugsy; 05-17-2013 at 10:04. Reason: Edited
Bugsy is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-16-2013 , 08:25   Re: Get Players Money at Disconnect throws error
Reply With Quote #5

Still having problems, sometimes in the chat stands "$x loaded", but I don't get any money.
__________________
Kia is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-17-2013 , 09:36   Re: Get Players Money at Disconnect throws error
Reply With Quote #6

Try that
__________________
Bugsy is offline
Kia
AlliedModders Donor
Join Date: Apr 2010
Location: In a world of madness
Old 05-17-2013 , 09:49   Re: Get Players Money at Disconnect throws error
Reply With Quote #7

Try what? I tried your code.
__________________

Last edited by Kia; 05-17-2013 at 09:49.
Kia is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-17-2013 , 10:04   Re: Get Players Money at Disconnect throws error
Reply With Quote #8

Quote:
Originally Posted by Kia View Post
Try what? I tried your code.
I edited my code
__________________
Bugsy is offline
Reply



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:52.


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