Here is one way you could do it. I made this example for usp but you can make it work with any gun by replacing the classname. There is a cvar [bsa_forceprimary] that if enabled [1] will force primary attack if secondary attack is clicked; when disabled the secondary attack will just be blocked.
With this method, when primary attack is forced you will not see the weapon animation when it occurs but it will still occur. Compile\install this code and use secondary attack with usp to see what I mean. Your ammo will go down with each attack but you will not see the weapon fire.
PHP Code:
#include <amxmodx>
#include <fakemeta>
#define m_pActiveItem 373
new g_pForcePrimaryAttack;
public plugin_init()
{
register_plugin( "Block\Hook Secondary Attack" , "1.0" , "bugsy" )
register_forward( FM_CmdStart , "fw_FM_CmdStart" );
g_pForcePrimaryAttack = register_cvar( "bsa_forceprimary" , "1" );
}
public fw_FM_CmdStart( id , Handle )
{
static iButtons; iButtons = get_uc( Handle , UC_Buttons );
static iOldButtons; iOldButtons = pev( id , pev_oldbuttons );
static szWeaponClassName[ 33 ];
if ( ( iButtons & IN_ATTACK2 ) && !( iOldButtons & IN_ATTACK2 ) )
{
pev( get_pdata_cbase( id , m_pActiveItem ) , pev_classname , szWeaponClassName , 32 );
if ( equal( szWeaponClassName , "weapon_usp" ) )
{
if ( get_pcvar_num( g_pForcePrimaryAttack ) )
iButtons |= IN_ATTACK;
set_uc( Handle , UC_Buttons , iButtons & ~IN_ATTACK2 );
//Issue punishment here if desired.
}
}
}
__________________