View Single Post
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 01-28-2016 , 18:36   Re: [STOCK] give_user_weapon
Reply With Quote #9

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 
GiveWeaponid )
{
    new 
szWeapon20 ];
    
    
give_user_weapon(id CSW_M4A1 12 14 szWeapon charsmaxszWeapon ) );
    
client_printid print_chat "You were given a %s" szWeapon] );
}

give_user_weaponindex iWeaponTypeID iClip=iBPAmmo=szWeapon[]="" maxchars=)
{
    if ( !( 
CSW_P228 <= iWeaponTypeID <= CSW_P90 ) || ( iClip ) || ( iBPAmmo ) || !is_user_aliveindex ) )
        return -
1;
    
    new 
szWeaponName20 ] , iWeaponEntity GrenadeBits;
    
    
GrenadeBits = ( ( << CSW_HEGRENADE ) | ( << CSW_FLASHBANG ) | ( << CSW_SMOKEGRENADE ) | ( << CSW_C4 ) );
    
get_weaponnameiWeaponTypeID szWeaponName charsmaxszWeaponName ) );
    
    if ( ( 
iWeaponEntity user_has_weaponindex iWeaponTypeID ) ? find_ent_by_owner( -szWeaponName index ) : give_itemindex szWeaponName ) ) > )
    {
        if ( 
iClip && !( GrenadeBits & ( << iWeaponTypeID ) ) )
            
cs_set_weapon_ammoiWeaponEntity iClip );

        if ( 
iWeaponTypeID == CSW_C4 
            
cs_set_user_plantindex );
        else if ( 
iBPAmmo )
            
cs_set_user_bpammoindex iWeaponTypeID iBPAmmo ); 
            
        if ( 
maxchars )
            
copyszWeapon maxchars szWeaponName );
    }
    
    return 
iWeaponEntity;

__________________

Last edited by Bugsy; 01-28-2016 at 18:53.
Bugsy is offline