Raised This Month: $51 Target: $400
 12% 

How to stop a sound?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-06-2008 , 12:01   How to stop a sound?
Reply With Quote #1

So I was checking out the sound flags for EmitSountToAll, one of the flags is: SND_STOP.

Code:
 * Sound flags for the sound emitter system.
 */
enum
{
	SND_NOFLAGS= 0,			/**< Nothing */
	SND_CHANGEVOL = 1,		/**< Change sound volume */
	SND_CHANGEPITCH = 2,	/**< Change sound pitch */
	SND_STOP = 3,			/**< Stop the sound */
	SND_SPAWNING = 4,		/**< Used in some cases for ambients */
	SND_DELAY = 5,			/**< Sound has an initial delay */
	SND_STOPLOOPING = 6,	/**< Stop looping all sounds on the entity */
	SND_SPEAKER = 7,		/**< Being played by a mic through a speaker */
	SND_SHOULDPAUSE = 8,	/**< Pause if game is paused */
};
My question is, lets say that I want to EmitSoundToAll, but then have it stop at a certain point. I assume the SND_STOP flag is intended for that. But I'm confused on the usage.

Do you:

1) Call EmitSoundToAll(soundfile); and then
2) Call EmitSoundToAll(soundfile, _, _, _, SND_STOP);

I figure you would have to have some sort of identifier of WHICH sound to stop, so you pass the same sound string?

X
XARIUS is offline
SAMURAI16
BANNED
Join Date: Sep 2006
Old 10-06-2008 , 13:09   Re: How to stop a sound?
Reply With Quote #2

catch sound with EmitSound hook and then block with return Plugin_Stop
SAMURAI16 is offline
Send a message via MSN to SAMURAI16
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-06-2008 , 14:01   Re: How to stop a sound?
Reply With Quote #3

So you're saying that SND_STOP is not used for stopping a sound?
XARIUS is offline
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-06-2008 , 14:29   Re: How to stop a sound?
Reply With Quote #4

I tested using AddNormalSoundHook, but it only triggers when a sound is played. I don't want to block the sound, I want to cancel a specific sound at some period of time based on a boolean conditional statement of some sort.

while <something is true> do nothing.. otherwise, cancel the sound.
XARIUS is offline
L. Duke
Veteran Member
Join Date: Apr 2005
Location: Walla Walla
Old 10-06-2008 , 14:34   Re: How to stop a sound?
Reply With Quote #5

SND_STOP should stop the sound. You may have to use the same info (such as channel, etc), but I would try with the SNDCHAN_AUTO default first and see if it works.

I have used this to start/stop a looping sound that's played from a specific entity. I would think that it would work on a sound playing to everyone with no attenuation also.
__________________
"Good grammar is essential, Robin."
- Batman
L. Duke is offline
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-06-2008 , 14:42   Re: How to stop a sound?
Reply With Quote #6

Quote:
Originally Posted by L. Duke View Post
SND_STOP should stop the sound. You may have to use the same info (such as channel, etc), but I would try with the SNDCHAN_AUTO default first and see if it works.

I have used this to start/stop a looping sound that's played from a specific entity. I would think that it would work on a sound playing to everyone with no attenuation also.
Okay, I'll take another stab at SND_STOP. It may not work because I'm not looping it. It's a semi long (60 second) mp3 file, and I'm attempting to stop the sound at a certain point.

I've been using SNDCHAN_AUTO, so maybe I have to specify a specific channel.

X
XARIUS is offline
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-06-2008 , 15:05   Re: How to stop a sound?
Reply With Quote #7

Yeah, no luck. I guess because it's a large file, once it's started, there's no way to stop it. Thanks anyway. =)
XARIUS is offline
paegus
Senior Member
Join Date: Nov 2004
Location: Extreme low earth orbit
Old 10-07-2008 , 07:04   Re: How to stop a sound?
Reply With Quote #8

i also tried SND_STOP without success but this works reliably...
Code:
...

		EmitSoundToClient(
			iClient,
			sAlarmSample,
			entity,
			SNDCHAN_AUTO,
			SNDLEVEL_MINIBIKE,
			SND_NOFLAGS,
			SNDVOL_NORMAL,
			SNDPITCH_NORMAL,
			entity,
			vAlarmPos,
			NULL_VECTOR,
			true,
			0.0
		); // Emit sound from alarm's origin.

...

CreateTimer(2.5, tSilence, entity); // Kill the sound, if any.

...

public Action:tSilence(Handle:timer, any:entity)
{
	EmitSoundToAll(
		sAlarmSample,
		entity,
		SNDCHAN_AUTO,
		SNDLEVEL_NORMAL,
		SND_STOPLOOPING,
		SNDVOL_NORMAL,
		SNDPITCH_NORMAL,
		entity,
		NULL_VECTOR,
		NULL_VECTOR,
		true,
		0.0
	); // Kill the sound
}

...
...as it doesn't stop the looping itself, it stops the entire sound. even if it's not a looping one.
__________________
Live and learn or die and teach by example.
Plugins Mine | Hidden:SourceMod

Last edited by paegus; 10-07-2008 at 08:35.
paegus is offline
XARIUS
SourceMod Donor
Join Date: May 2008
Location: Atlanta, GA
Old 10-07-2008 , 08:18   Re: How to stop a sound?
Reply With Quote #9

Interesting! I just woke up and saw this, I need some coffee so I can see what the difference actually is between the two besides just a timer.

Thanks for the assist!
__________________
XARIUS is offline
Lebson506th
Veteran Member
Join Date: Jul 2008
Old 10-07-2008 , 08:29   Re: How to stop a sound?
Reply With Quote #10

See what he attempted to highlight in red.

(Look for [color=red])
__________________
My Plugins
Spray Tracer by Nican, maintained by me
Simple TK Manager
DoD:S Admin Weapons

Links
Resistance and Liberation (A HL2 Multiplayer Modification)
Lebson506th is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 23:32.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode