This will simulate pressing Q but only to toggle between pistol and knife.
Let me know if you need anything changed, here's how it works:
- Holding pistol, primary, grenade, or C4 (anything other than knife) - Switch to knife
- Holding knife - Switch to pistol
- Holding knife but do not have a pistol - Do nothing
- Holding nothing - Do nothing
PHP Code:
#include <fakemeta>
#include <hamsandwich>
public TogglePistolKnife( iPlayer )
{
static const m_pActiveItem = 373;
static const m_rpgPlayerItems_Slot2 = 369;
static const m_iId = 43;
static iActiveItem;
static szWeapon[ 19 ];
static iEntity;
iActiveItem = get_pdata_cbase( iPlayer , m_pActiveItem , 5 );
if( iActiveItem > 0 )
{
if ( ExecuteHam( Ham_Item_ItemSlot , iActiveItem ) == 3 )
{
iEntity = get_pdata_cbase( iPlayer , m_rpgPlayerItems_Slot2 , 5 );
if ( iEntity > 0 )
{
get_weaponname( get_pdata_int( iEntity , m_iId , 4 ) , szWeapon , charsmax( szWeapon ) );
engclient_cmd( iPlayer , szWeapon );
}
}
else
{
engclient_cmd( iPlayer , "weapon_knife" );
}
}
}
or
PHP Code:
public TogglePistolKnife( iPlayer )
{
static const m_pActiveItem = 373;
static iActiveItem;
iActiveItem = get_pdata_cbase( iPlayer , m_pActiveItem , 5 );
if( iActiveItem > 0 )
client_cmd( iPlayer , ( ExecuteHam( Ham_Item_ItemSlot , iActiveItem ) == 3 ) ? "slot2;wait;wait;wait;+attack;wait;-attack" : "slot3;wait;wait;wait;+attack;wait;-attack" );
}
__________________