Ham_PrimaryAttack is not a good way to do this because if you hold down attack, you hear the sound repeat itself before the sound completes and it even does it when you are not actually shooting. I don't think there's a simple way to do this because the sound is produced on the client side.
Using code written by VEN to detect weapon fire, you can play a sound over the normal fire sound. In this example, I used the M4A1 fire sound for all weapons. This can be modified to use a different fire sound for each weapon.
Not thoroughly tested:
PHP Code:
#include <amxmodx>
#include <fakemeta>
new const FireSound[] = "weapons/m4a1-1.wav";
new const g_guns_events[][] =
{
"events/awp.sc",
"events/g3sg1.sc",
"events/ak47.sc",
"events/scout.sc",
"events/m249.sc",
"events/m4a1.sc",
"events/sg552.sc",
"events/aug.sc",
"events/sg550.sc",
"events/m3.sc",
"events/xm1014.sc",
"events/usp.sc",
"events/mac10.sc",
"events/ump45.sc",
"events/fiveseven.sc",
"events/p90.sc",
"events/deagle.sc",
"events/p228.sc",
"events/glock18.sc",
"events/mp5n.sc",
"events/tmp.sc",
"events/elite_left.sc",
"events/elite_right.sc",
"events/galil.sc",
"events/famas.sc"
};
new g_guns_eventids_bitsum , g_fwid , g_max_clients;
public plugin_precache()
{
precache_sound( FireSound );
g_fwid = register_forward( FM_PrecacheEvent , "fwPrecacheEvent" , 1 );
}
public fwPrecacheEvent( type , const name[] )
{
for (new i = 0; i < sizeof g_guns_events; ++i)
{
if ( equal( g_guns_events[ i ] , name ) )
{
g_guns_eventids_bitsum |= ( 1 << get_orig_retval() );
return FMRES_HANDLED;
}
}
return FMRES_IGNORED;
}
public plugin_init()
{
unregister_forward( FM_PrecacheEvent , g_fwid , 1 );
register_forward( FM_PlaybackEvent , "fwPlaybackEvent" );
g_max_clients = global_get(glb_maxClients);
}
public fwPlaybackEvent( flags , invoker , eventid )
{
if ( !( g_guns_eventids_bitsum & ( 1 << eventid ) ) || !( 1 <= invoker <= g_max_clients ) )
return FMRES_IGNORED;
emit_sound( invoker , CHAN_WEAPON , FireSound , VOL_NORM , ATTN_NORM , 0 , PITCH_NORM );
return FMRES_HANDLED;
}
__________________