C++, Playing Sounds

Discuss modifications and also recruit team members.

C++, Playing Sounds

Postby WillSmith190 on Thu Aug 26, 2010 11:13 pm

I'm working on a mod, and I made an entity to play a sound when the model is activated. Everything works, but the sound. I used EmitSound to test, but that plays it everywhere, and I think is client-sided. My entity has radius, volume, and soundname options. Now, I'm talking about in C++. First of all, playin the sound. In my script, the file of the sound is represented by m_iszMusic. It is a wav or mp3 file. I want the sound to be played, at the selected volume (m_nVolume) and can only be heard in the radius (m_flSoundradius) of the model. Then, I need the sound to be able to be stopped. The start function is InputTurnOn and checks if the radio is already on (m_nTurnedOn) and if it isn't, it plays the sound. Currently it looks like this:

Code: Select all
void CFunModRadio::InputTurnOn( inputdata_t &inputData )
{
   if(m_nTurnedOn)
   {
      return;
   }
   m_nTurnedOn = true;
   EmitSound( m_iszMusic );

}


Whats missing is it doesn't check if the player is in the radius, and it doesn't set the volume.


Then we have the InputTurnOff. It checks if the radio is off, if it isn't, it turns the sound off. It currently looks like this. Notice the absense of a function to turn off the sound, because I don't know how to do this.

Code: Select all
void CFunModRadio::InputTurnOff( inputdata_t &inputData )
{
   if(m_nTurnedOn == false)
   {
      return;
                }
}


So if you can even understand my confusing explanation of my issue, then please, help me :D
WillSmith190
Member
Member
 
Joined: Sun Aug 22, 2010 4:10 am

Re: C++, Playing Sounds

Postby zombie@computer on Fri Aug 27, 2010 7:46 am

check out the func_door for instance. Its not really checking if a player is in radius, its adjusting the sound using an attenuation function before emitting it.

Code: Select all
//pEdict = handle to ent.

// play 'door locked' sound
         CPASAttenuationFilter filter( pEdict );

         EmitSound_t ep;
         ep.m_nChannel = CHAN_ITEM;
         ep.m_pSoundName = (char*)STRING(pls->sLockedSound);
         ep.m_flVolume = fvol;
         ep.m_SoundLevel = SNDLVL_NORM;

         CBaseEntity::EmitSound( filter, pEdict->entindex(), ep );
         pls->flwaitSound = gpGlobals->curtime + flsoundwait;


to stop sounds i found this in ambient_generic:
Code: Select all
//pSoundSource=handle to entity, flags = SND_STOP (==4)
UTIL_EmitAmbientSound(pSoundSource->GetSoundSourceIndex(), pSoundSource->GetAbsOrigin(), szSoundFile,
                  0, SNDLVL_NONE, flags, 0);



IF for some reason you cant figure out things like this, simply remember what other entities have the functionality you need and take a look at them :)

EDIT: just realised it would be easier for you to look at the playsound code from the ambient_generic as well instead of the door :)
When you are up to your neck in shit, keep your head up high
zombie@computer
Forum Goer Elite™
Forum Goer Elite™
 
Joined: Fri Dec 31, 2004 5:58 pm
Location: Lent, Netherlands

Return to Mod Talk

Who is online

Users browsing this forum: No registered users