New Member
|
06-14-2014
, 10:17
Re: CS Weapons MiniShop
|
#12
|
Quote:
Originally Posted by Kia
Made some suggestions in the code, you might want to check it out.
PHP Code:
/* Plugin generated by AMXX-Studio */
#include < amxmodx >
#include < amxmisc >
#include < cstrike >
#include < fakemeta_util >
// Indented Code
enum _: iSettings
{
iWep[ 32 ],
iWeapon[ 32 ],
iPrice,
iAccess
}
new const szSettings [ ] [ iSettings ] =
{
{ "AK47", "weapon_ak47", 5000, ADMIN_ALL },
{ "Mp5Navy", "weapon_mp5navy", 1250, ADMIN_ALL },
{ "Awp", "weapon_awp", 7500, ADMIN_ALL },
{ "M3", "weapon_m3", 0, ADMIN_KICK }
}
public plugin_init()
{
register_plugin( "CS Shop", "1.0", "Xdoctor" );
register_clcmd( "say /shop", "ClcmdShop" );
}
public ClcmdShop( client )
{
if(!is_user_alive( client ) ) // Removed is_user_connected check, since is_user_alive does that already
return ColorChat( client, "^4%s^1 You need to be^4 alive ^1to use this shop^3!", GetUserName( client ) );
new szText[ 128 ];
formatex( szText, charsmax( szText ), "\d[ \yAMXX\d ] \yCS Weapons Menu \d( \yBy Xdoctor\d )" )
new Menu = menu_create( szText, "CmdShopHandler" );
for( new i = 0; i < sizeof( szSettings ); i++ )
{
formatex( szText, charsmax( szText ), "\rWeapon\w: \y%s \d[ \y%d Money \d ] %s", szSettings[ i ][ iAccess ] == ADMIN_KICK ? "Only Vip" : "" );
menu_additem( Menu, szText, _, get_user_flags(client) & szSettings[i][iAccess] ? 0 : 1<<31 ); // Blocking the Menu Item already here when he has not the required flag
}
menu_display( client, Menu, 0 );
return PLUGIN_HANDLED; // Replaced 1 with PLUGIN_HANDLED, use such consts when we have them
}
public CmdShopHandler( client, Menu, Item )
{
if( Item == MENU_EXIT )
{
menu_destroy( Menu );
return 1;
}
// Removed Flag Check
new iMoney = cs_get_user_money(client) // Saving the money here so we save some calls
if( iMoney < szSettings[ Item ][ iPrice ] )
return ColorChat( client, "^4%s^1 Your money ^4amount^1 isn't^4 enough^1 to purchase^4 %s^3!", GetUserName( client ), szSettings[ Item ][ iWep ] );
else if( iMoney >= szSettings[ Item ][ iPrice ] )
{
cs_set_user_money( client, iMoney - szSettings[ Item ][ iPrice ] );
fm_give_item( client, szSettings[ Item ][ iWeapon ] );
ColorChat( 0, "^4%s^1 just bought ^3the^1 weapon ^4%s^3!", GetUserName( client ), szSettings[ Item ][ iWep ] );
}
return PLUGIN_HANDLED; // Replaced 1 with PLUGIN_HANDLED, use such consts when we have them
}
stock GetUserName( const Index )
{
new szName[ 32 ];
get_user_name( Index, szName, charsmax( szName ) );
return szName;
}
stock ColorChat(const client, const string[], {Float, Sql, Resul,_}:...)
{
new msg[ 191 ], players[ 32 ], count = 1;
static len; len = formatex( msg, charsmax(msg), "^3[^1 AMXX ^3]^1 " );
vformat( msg[ len ], charsmax( msg ) - len, string, 3 );
if( client ) players[ 0 ] = client;
else get_players( players,count, "ch" );
for( new i = 0; i < count; i++ )
{
if( is_user_connected( players[ i ] ) )
{
message_begin( MSG_ONE_UNRELIABLE, get_user_msgid( "SayText" ),_, players[ i ] );
write_byte( players[ i ] );
write_string( msg );
message_end();
}
}
return 1;
}
|
cs_set_user_money( client, iMoney - szSettings[ Item ][ iPrice ] );
-->
iMoney -= szSettings[ Item ][ iPrice ]
---------------------------------------------------------------
If you set a variable to go with him to the end..
Doctor, you're sure that all the variables read in the menu?
|
|