I also fixed the logic being used for AK. It would previously allow a player to buy an AK on round 4, and then again on round 5 when the round counter was reset. It will now ensure 5 rounds between each get AK and cash.
Untested
PHP Code:
#include <amxmodx>
#include <cstrike>
#include <fun>
#include <cash>
new const Version[] = "0.2";
new g_RoundCountAK[ MAX_PLAYERS + 1 ];
new g_RoundCountCash[ MAX_PLAYERS + 1 ];
new g_BoughtDeagle , g_BoughtAK47 , g_GotCash;
new g_pResetRounds;
public plugin_init()
{
register_plugin( "Free Weapons" , Version , "bugsy" );
register_concmd( "say /freewpn" , "ShowMenu" );
register_clcmd( "say /getcash" , "GetCash" );
register_event( "HLTV" , "NewRound" , "a" , "1=0" , "2=0" );
g_pResetRounds = register_cvar( "freeweapon_rounds" , "5" );
}
public client_connect( id )
{
g_RoundCountAK[ id ] = 0;
g_RoundCountCash[ id ] = 0;
g_BoughtDeagle &= ~( 1 << ( id & 31 ) );
g_BoughtAK47 &= ~( 1 << ( id & 31 ) );
g_GotCash &= ~( 1 << ( id & 31 ) );
}
public NewRound()
{
new iPlayers[ 32 ] , iNum , iPlayer;
new iResetRounds = get_pcvar_num( g_pResetRounds );
g_BoughtDeagle = 0;
get_players( iPlayers , iNum , "ch" );
for ( new i = 0 ; i < iNum ; i++ )
{
iPlayer = iPlayers[ i ];
if ( ++g_RoundCountAK[ iPlayer ] >= iResetRounds )
g_BoughtAK47 &= ~( 1 << ( iPlayer & 31 ) );
if ( ++g_RoundCountCash[ iPlayer ] >= iResetRounds )
g_GotCash &= ~( 1 << ( iPlayer & 31 ) );
}
}
public GetCash( id )
{
if ( !( g_GotCash & ( 1 << ( id & 31 ) ) ) )
{
set_user_cash( id , get_user_cash( id ) + 100 );
client_print( id , print_chat , " Get User 100 Cash" );
g_GotCash |= ( 1 << ( id & 31 ) );
g_RoundCountCash[ id ] = 0;
}
else
{
client_print( id , print_chat , " This command can only be used every 5 rounds." );
}
return PLUGIN_HANDLED;
}
public ShowMenu( id )
{
new iMenu = menu_create( "Free Weapon" , "MenuHandler" );
new iCallBack = menu_makecallback( "MenuCallBack" );
new szAKMenu[ 40 ] , szRoundsLeft[ 10 ];
new iResetRounds = get_pcvar_num( g_pResetRounds );
if ( g_BoughtAK47 & ( 1 << ( id & 31 ) ) )
formatex( szRoundsLeft , charsmax( szRoundsLeft ) , " - %d left" , iResetRounds - g_RoundCountAK[ id ] );
formatex( szAKMenu , charsmax( szAKMenu ) , "AK47 [ 1 every %d round%s ]%s" , iResetRounds , ( iResetRounds == 1 ) ? "" : "s" , szRoundsLeft );
menu_additem( iMenu , "Deagle [ 1 every round ]" , .callback = iCallBack );
menu_additem( iMenu , szAKMenu , .callback = iCallBack );
menu_setprop( iMenu, MPROP_EXIT, MEXIT_ALL );
menu_display( id , iMenu );
return PLUGIN_HANDLED;
}
public MenuCallBack( id , iMenu , iItem )
{
new iRetVal;
switch ( iItem )
{
case 0: iRetVal = ( user_has_weapon( id , CSW_DEAGLE ) || ( g_BoughtDeagle & ( 1 << ( id & 31 ) ) ) ) ? ITEM_DISABLED : ITEM_ENABLED;
case 1: iRetVal = ( user_has_weapon( id , CSW_AK47 ) || ( g_BoughtAK47 & ( 1 << ( id & 31 ) ) ) ) ? ITEM_DISABLED : ITEM_ENABLED;
}
return iRetVal;
}
public MenuHandler( id , menu , item )
{
if ( item == MENU_EXIT )
{
menu_destroy( menu );
return PLUGIN_HANDLED;
}
if ( !is_user_alive( id ) )
return PLUGIN_HANDLED;
strip_user_weapons( id );
give_item( id , "weapon_knife" );
switch( item )
{
case 0:
{
give_item( id , "weapon_deagle" );
cs_set_user_bpammo( id , CSW_DEAGLE , 30 );
g_BoughtDeagle |= ( 1 << ( id & 31 ) );
}
case 1:
{
give_item( id , "weapon_ak47" );
cs_set_user_bpammo( id , CSW_AK47 , 90 );
g_BoughtAK47 |= ( 1 << ( id & 31 ) );
g_RoundCountAK[ id ] = 0;
}
}
return PLUGIN_CONTINUE;
}
__________________