I have successfully replaced a weapons sounds with another. I have, essentially, made my kar98 sound like a springfield both to those around me and to myself.
The problem is, to myself, the sound is a bit delayed.
Here's what I'm doing:
- Setting CD_flNextAttack to get_gametime() + 0.001
Creating my own recoil (Normal one is blocked with CD setting)
Setting my own animation (Normal one is blocked with CD setting)
Playing my own firing sound
The latter 3 of the above list takes place inside FM_PlaybackEvent, where I also change the event to another weapon - but changing the event only applies to what others around me hear. If I didn't block firing in CD, I'd still hear the original sound of the kar98.
When I actually click fire, everything
happens perfectly. The problem is, it's a little delayed. When I shoot any other weapon, the sound/animation/recoil is instantaneous. With this weapon, it is delayed about half a second. Small, but definitely noticable.
I'm wondering if FM_PlaybackEvent provides any delay from when you actually shoot? I have also tried doing this in FM_CmdStart and hooking when UC_Buttons contains IN_ATTACK, but the delay is the same (also with prethink hook).
Again, my question is why there could possibly be a delay of the sound being played / animation being played, and if there is a better method of doing it so-as to avoid the delay?
Code:
public hook_PlaybackEvent( flags, id, eventindex, delay, origin, angles, fparam1, fparam2, iparam1, iparam2, bparam1, bparam2 ) {
if( !get_pcvar_num( g_cvarEnabled ) || !is_user_alive( id ) ) return FMRES_IGNORED;
// Make sure he's holding the right weapon, the event is the right one, and it's not a bayonet event
if( g_curweapon[id] == DODW_KAR && has_unscoped_spring( id )
&& eventindex == EVENT_KAR && !iparam1 )
{
// Create the anim, sound and recoil that is blocked in ClientData hook
client_cmd( id, "spk %s", g_szSpringShoot );
set_animation( id, SEQ_FIRE );
create_recoil( id, RECOIL_KAR );
// Send the event so that it plays a springfield for everyone else
engfunc( EngFunc_PlaybackEvent, flags, id, EVENT_SPRING, delay, origin, angles, fparam1, fparam2, iparam1, iparam2, bparam1, bparam2 );
return FMRES_SUPERCEDE;
}
return FMRES_IGNORED;
}
When I enter in the console, "spk weapons/spring_shoot.wav", it is instant, unlike this.
Thanks for the help guys.
__________________