Adding woosh

Open hl2_player.cpp
Above "DEFINE_SOUNDPATCH( m_sndLeeches ),"
DEFINE_SOUNDPATCH(m_pWooshSound),
Add this to "hl2_player.h". Define our "m_pWooshSound" in "private:" section
CSoundPatch *m_pWooshSound;
Prepare place for our functions. In "hl2_player.h" ниже "virtual void OnRestore();" add
virtual void CreateSounds(void); void UpdateWoosh(void);
Right above "void CHL2_Player::StopLoopingSounds( void )" add
//----------------------------------------------------------------------------- // Creating Sound //----------------------------------------------------------------------------- void CHL2_Player::CreateSounds() { if (!m_pWooshSound) { CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); CPASAttenuationFilter filter(this); m_pWooshSound = controller.SoundCreate(filter, entindex(), "HL2Player.Woosh"); controller.Play(m_pWooshSound, 0, 100); } }
Now we need to make "CreateSounds" work. In "Spawn(void)" below "BaseClass::Spawn();" add
CreateSounds();
And now we need to add sound precache. In "void CHL2_Player::Precache( void )" add
PrecacheScriptSound("HL2Player.Woosh");
Don't forggot stop our sounds. In "void CHL2_Player::StopLoopingSounds( void )", at the top add
if (m_pWooshSound) { CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); controller.SoundDestroy(m_pWooshSound); m_pWooshSound = NULL; }
Adding volume update function for out sound
void CHL2_Player::UpdateWoosh(void) { if (m_pWooshSound) { CSoundEnvelopeController &controller = CSoundEnvelopeController::GetController(); float fWooshVol = GetAbsVelocity().Length() - MIN_WOOSH_SPEED; if (fWooshVol < 0.0f) { controller.SoundChangeVolume(m_pWooshSound, 0.0f, 0.1f); return; } fWooshVol /= 2000.0f; if (fWooshVol > 1.0f) fWooshVol = 1.0f; controller.SoundChangeVolume(m_pWooshSound, fWooshVol, 0.1f); } }
Now we need to make it work. In "void CHL2_Player::PostThink( void )" add
UpdateWoosh();
Also we need to define "MIN_WOOSH_SPEED". Open "hl2_shareddefs.h" and add
#define MIN_FLING_SPEED 750
So... code part is completed. Compile project and getting started with game.
After compilation, transfer client and server dll's to out mod.
Create "sound" directory and put our file there.
In directory "scripts" creating "game_sounds_mymod.txt" file and enter it into it.
"HL2Player.Woosh" { "channel" "CHAN_STATIC" "volume" "1.00" "soundlevel" "SNDLVL_85dB" "pitch" "100" "wave" "woosh.wav" }
So, you need to take "game_sounds_manifest.txt" from the game that you are developing your mod for. Add precache of our new "sound file" to this file.
"precache_file" "scripts/game_sounds_mymod.txt"
Good job.