EmitSound not Updating

Hi, Facepunch!

I have a system that runs sound emitters on the other end of a portal when it is activated to warn the people on the other side that there is someone coming.

The way that I’ve done this is by using


ent:EmitSound( "sgc_threat_level" )

The problem is that when the player goes to the other portal, they cannot hear the sound. The player can also not hear the sound when they have just loaded in their game at the location of the sounds.

Here’s what I have for the sound code:



sound.Add( {
	name = "sgc_threat_level",
	channel = CHAN_STATIC,
	volume = 1,
	level = 80,
	pitch = 100,
	sound = "sgc/threat_level_foxalpha6.wav"
} )


Help would be appreciated.
Thanks in advance!

[editline]5th August 2017[/editline]

I think it is hardcoded into the engine but I might be wrong. When a player is outside of the range of the sound, and the sound plays, and player comes closer, he will not hear it. Same with joining players. You can only hear sounds that started to play when you were in their range.

Nevermind, I was unable to fix the issue. I tried using CSoundpatch but it has the same effect.

Any ideas?

[editline]5th August 2017[/editline]

I do not believe that this is the case since the sounds work sometimes.

You could make a think function that will run lets say every second to check if the player is in a distance close to the emitter, if he is and the sound isnt playing, play the sound, if he is outside and the sound is playing, stop it. However, this would require to play the sound clientside, not serverside. It is not the best solution, but it could work. Try to wait for more responsed, probably someone will come up with a better idea

Sounds good, I’ll give this a shot.

If anyone else has any more ideas, feel free to comment below.

[editline]5th August 2017[/editline]

EDIT:
I’ll also take a look at the Wiremod sound emitter code; I may be able to rig something like that to work with the sound entities.

UPDATE:
After doing a bit of experimenting, I’m still unable to get the EmitSound to function properly, even with the Wiremod sound emitter.

Use CSoundPatch but change volume/pitch every X amount of time to cause the sound to update

If that works then you are amazing :wink:
I’ll give it a shot!

Unfortunately, this did not work.
I both changed the pitch and the volume every second and yet the sound did not play when I teleported to the position.

[editline]7th August 2017[/editline]

I even made a concommand that changed the pitch/volume manually, and this did not work.

[editline]7th August 2017[/editline]

I FIXED IT!!!

One word: FILTER


local soundFilter = RecipientFilter()
soundFilter:AddAllPlayers()

sound = CreateSound( ent, soundName, soundFilter )

Thanks for everyone’s help! :slight_smile: