Looks good, I changed the following:
- Added an else above cs_set_user_bpammo() since this is not needed for C4.
- Added showbombicon=1 so the green c4 icon appears in the HUD.
- Added code to conditionally call cs_set_weapon_ammo() and cs_set_user_bpammo() only if a value is specified.
This is up to you, but you could also add the ability to optionally get the weapons name, this could eliminate the need for the scripter to use another get_weaponname() call if this is needed.
PHP Code:
#include <amxmodx>
#include <fun>
#include <engine>
#include <cstrike>
public plugin_init()
{
register_clcmd( "say test" , "GiveWeapon" )
}
public GiveWeapon( id )
{
new szWeapon[ 20 ];
give_user_weapon(id , CSW_M4A1 , 12 , 14 , szWeapon , charsmax( szWeapon ) );
client_print( id , print_chat , "You were given a %s" , szWeapon[ 7 ] );
}
give_user_weapon( index , iWeaponTypeID , iClip=0 , iBPAmmo=0 , szWeapon[]="" , maxchars=0 )
{
if ( !( CSW_P228 <= iWeaponTypeID <= CSW_P90 ) || ( iClip < 0 ) || ( iBPAmmo < 0 ) || !is_user_alive( index ) )
return -1;
new szWeaponName[ 20 ] , iWeaponEntity , GrenadeBits;
GrenadeBits = ( ( 1 << CSW_HEGRENADE ) | ( 1 << CSW_FLASHBANG ) | ( 1 << CSW_SMOKEGRENADE ) | ( 1 << CSW_C4 ) );
get_weaponname( iWeaponTypeID , szWeaponName , charsmax( szWeaponName ) );
if ( ( iWeaponEntity = user_has_weapon( index , iWeaponTypeID ) ? find_ent_by_owner( -1 , szWeaponName , index ) : give_item( index , szWeaponName ) ) > 0 )
{
if ( iClip && !( GrenadeBits & ( 1 << iWeaponTypeID ) ) )
cs_set_weapon_ammo( iWeaponEntity , iClip );
if ( iWeaponTypeID == CSW_C4 )
cs_set_user_plant( index , 1 , 1 );
else if ( iBPAmmo )
cs_set_user_bpammo( index , iWeaponTypeID , iBPAmmo );
if ( maxchars )
copy( szWeapon , maxchars , szWeaponName );
}
return iWeaponEntity;
}
__________________