AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Save Money (https://forums.alliedmods.net/showthread.php?t=95556)

-Acid- 06-24-2009 17:58

Save Money
 
Will this work?
PHP Code:

#include <amxmodx>
#include <amxmisc>
#include <nvault>
#include <cstrike>

new g_szAuthID[33][33];
new 
g_iBot[33];
new 
g_iMoney[33];
new 
g_pEnabled;
new 
g_iVault;
new const 
g_szVaultFile[] = "Save_Money";

public 
plugin_init()
{
    
register_plugin"Save_money" "1.0" "-Acid-" );
    
g_pEnabled register_cvar"sm_enabled" "1" );
    
    
}

public 
plugin_cfg()
{
    
g_iVault nvault_openg_szVaultFile );
    
    if ( 
g_iVault == INVALID_HANDLE )
        
set_fail_state"Error opening nVault" );
}

public 
plugin_end()
{
    
nvault_closeg_iVault );
}

public 
client_putinserverid )
{
    if ( !
get_pcvar_numg_pEnabled ) )
        return 
PLUGIN_CONTINUE;
    
    
g_iBotid ] = is_user_botid );
    
    if ( !
g_iBotid ] )
    {
        
get_user_authidid g_szAuthIDid ] , 32 );
        
        new 
iMoney nvault_getg_iVault g_szAuthIDid ] );
        
        if ( 
iMoney )
        {
            
g_iMoneyid ] = iMoney;
            
cs_set_user_moneyid iMoney );
        }
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
client_disconnectid )
{
    if ( !
get_pcvar_numg_pEnabled ) )
        return 
PLUGIN_CONTINUE;
    
    if ( !
g_iBotid ] && g_iMoneyid ] )
    {
        new 
szMoney];
        
num_to_strg_iMoney[id] , szMoney );
        
        
nvault_setg_iVault g_szAuthIDid ] , szMoney );
    }
    
    
g_iMoneyid ] = 0;
    
g_iBotid ] = 0;
    
    return 
PLUGIN_CONTINUE;



Save a players money

shadow.hk 06-24-2009 23:38

Re: Save Money
 
I'm sure there's a tutorial that does exactly this, why don't you search for it, nvault by bugsy, if i recall correctly.

http://forums.alliedmods.net/showthread.php?t=91503

Saves score and money.

Bugsy 06-25-2009 00:17

Re: Save Money
 
You never save the players current money so there's no way for a vault entry to ever exist for a player. I would hook the Money event to keep g_iMoney[] updated with the users current money at all times.

PHP Code:

register_event"Money" "fw_EvMoney" "be" );

public 
fw_EvMoneyid )
{
    
g_iMoneyid ] = read_data);


Also, you sometimes may run into issues when you try to set things on players @ putinserver. You may need to set_task the money restore with an interval of 0.1 to 0.4. Try it first though as-is because it may work, I've never tried to set a users money at putinserver.

-Acid- 06-25-2009 01:07

Re: Save Money
 
KK cool bugsy thnx

Exolent[jNr] 06-25-2009 15:03

Re: Save Money
 
Quote:

Originally Posted by -Acid- (Post 856263)
Will this work?

Why would you ask such a question instead of testing it yourself?


All times are GMT -4. The time now is 15:38.

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