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

Need help with Frag_save


Post New Thread Reply   
 
Thread Tools Display Modes
-Acid-
Senior Member
Join Date: Feb 2009
Old 05-09-2009 , 23:35   Re: Need help with Frag_save
Reply With Quote #11

When ever a player disconnect, map change your Frags (Kills) saves. When you use your Frag to buy a award u lose the amount of frag that the awards cost. So its like a Frag Bank.
__________________
-Acid- is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-10-2009 , 08:44   Re: Need help with Frag_save
Reply With Quote #12

This code will save a users frags between connections (disconnect\map-change) and allow them to purchase a reward using frags as the currency. Use the /buyreward chat command to purchase the reward.

PHP Code:
#include <amxmodx>
#include <amxmisc>
#include <fun>
#include <nvault>

new g_szAuthID[33][33];
new 
g_iBot[33];
new 
g_iFrags[33];

new 
g_pEnabled;
new 
g_pRewardPrice;
new 
g_iVault;
new 
g_iMsgScoreInfo;
new const 
g_szVaultFile[] = "frag_save";

public 
plugin_init()
{
    
register_plugin"Frag_Save" "2.0" "-Acid-" );
    
    
register_clcmd"say /buyreward" "cmdBuyReward" );
    
register_clcmd"say_team /buyreward" "cmdBuyReward" );
    
register_event"ScoreInfo" "fwEvScoreInfo" "a" );
    
    
g_pEnabled register_cvar"fs_enabled" "1" );
    
g_pRewardPrice register_cvar"fs_rewardprice" "2" );
    
g_iMsgScoreInfo get_user_msgid"ScoreInfo" );
    
    
register_dictionary"Frag_Save.txt" );
}

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 
iFrags nvault_getg_iVault g_szAuthIDid ] );
        
        if ( 
iFrags )
        {
            
g_iFragsid ] = iFrags;
            
set_user_fragsid iFrags );
        }
    }
    
    return 
PLUGIN_CONTINUE;
}

public 
client_disconnectid )
{
    if ( !
get_pcvar_numg_pEnabled ) )
        return 
PLUGIN_CONTINUE;
        
    if ( !
g_iBotid ] && g_iFragsid ] )
    {
        new 
szFrags];
        
num_to_strg_iFrags[id] , szFrags );
        
        
nvault_setg_iVault g_szAuthIDid ] , szFrags );
    }
    
    
g_iFragsid ] = 0;
    
g_iBotid ] = 0;
    
    return 
PLUGIN_CONTINUE;
}

public 
fwEvScoreInfo()
{
    if ( !
get_pcvar_numg_pEnabled ) )
        return 
PLUGIN_CONTINUE;
        
    new 
id read_data);
    new 
iFrags read_data);
    
    
//The server resets scores at mapchange so this will set the players score [if g_iFrags[] > 0].
    
if ( !iFrags && g_iFragsid ] )
    {
        
set_user_fragsid g_iFragsid ] );
        return 
PLUGIN_CONTINUE;
    }
    
    
g_iFragsid ] = iFrags;
    
    return 
PLUGIN_CONTINUE;
}

public 
cmdBuyRewardid )
{
    if ( !
get_pcvar_numg_pEnabled ) )
        return 
PLUGIN_HANDLED;
        
    new 
iRewardPrice get_pcvar_numg_pRewardPrice );
    
    if ( 
g_iFragsid ] >= iRewardPrice )
    {
        
//
        //Put your reward code here
        //
        
        
g_iFragsid ] -= iRewardPrice;
        
set_user_fragsid g_iFragsid ] );
        
cmdUpdateScoreBoardid );
        
        
client_printid print_chat "* You have purchased the reward (-%d frags)" iRewardPrice );
    }
    else
    {
        
client_printid print_chat "* You do not have enough frags to buy reward" );
    }
    
    return 
PLUGIN_HANDLED;
}

public 
cmdUpdateScoreBoard(id)
{
    
message_beginMSG_ALL g_iMsgScoreInfo );
    
write_byteid );
    
write_shortget_user_fragsid ) );
    
write_shortget_user_deathsid ) );
    
write_short);
    
write_shortget_user_teamid ) );
    
message_end( );

__________________
Bugsy is offline
-Acid-
Senior Member
Join Date: Feb 2009
Old 05-10-2009 , 11:12   Re: Need help with Frag_save
Reply With Quote #13

okay let me give it a shot.
__________________
-Acid- is offline
-Acid-
Senior Member
Join Date: Feb 2009
Old 05-10-2009 , 14:12   Re: Need help with Frag_save
Reply With Quote #14

Okay thnx alot it works! +k
__________________
-Acid- is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 05-11-2009 , 08:49   Re: Need help with Frag_save
Reply With Quote #15

I'd also recommend my Remember the Score, you can implement it into any other reward plugin.
__________________
In Flames we trust!
Nextra is offline
-Acid-
Senior Member
Join Date: Feb 2009
Old 05-13-2009 , 21:52   Re: Need help with Frag_save
Reply With Quote #16

rts, uses mysql and i tried it and i cant get it to work.
__________________
-Acid- is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2009 , 21:55   Re: Need help with Frag_save
Reply With Quote #17

Does my code work for you?
__________________
Bugsy is offline
-Acid-
Senior Member
Join Date: Feb 2009
Old 05-13-2009 , 23:05   Re: Need help with Frag_save
Reply With Quote #18

yea thnx alot! +k
__________________
-Acid- 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 02:15.


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