Modme Forums

Starting/Stopping a looping “ambient” sound

Game Modding | Call of Duty: Black Ops 3 | Scripting


ModmeBot:

Thread By: ltschase
I would like to know how to start and stop an "ambient" sound. I was hoping that by using Nate Smith's ambient sounds method with the structs, that I could simply stop and start the sound by hiding and showing the structs, but that didn't work, so I am not sure how to do it. If you don't understand what am I wanting to do exactly, for example, I want to have the sound of a generator running, but the generator isn't always running, so the sound needs to turn on and off.


ModmeBot:

Reply By: ihmiskeho
I don't know how Nate's script works, but you could use PlayLoopSound(<sound>, fadetime) to start the sound and StopLoopSound(fadetime) to stop it.</sound>

There is info about these function (and basically about all BO3 functions) in the scriptapifunctions. That can be found in Black ops 3 root/deffiles/docs_modtools.
<h1> </h1>


ModmeBot:

Reply By: Abnormal202

ltschase
I would like to know how to start and stop an "ambient" sound. I was hoping that by using Nate Smith's ambient sounds method with the structs, that I could simply stop and start the sound by hiding and showing the structs, but that didn't work, so I am not sure how to do it. If you don't understand what am I wanting to do exactly, for example, I want to have the sound of a generator running, but the generator isn't always running, so the sound needs to turn on and off.

In my experience the StopLoopSound function doesn't always work. Instead what I would recommend is spawning in an invisible entity, playing a loop sound on that entity, and deleting that entity when you want to stop the sound.

SoundOrg = util::spawn_model( "tag_origin", &lt;location&gt; );
SoundOrg PlayLoopSound("alias_name");
SoundOrg Delete();&lt;/location&gt;


You will need this #using in order to use the spawn_model function however:
#using scripts\shared\util_shared;


ModmeBot:

Reply By: Symbo
Abnormal you got me curious. StopLoopSound always worked for me. I just found this function in sound_shared.gsc that suggest you can specify the alias you want to stop instead of the fadetime.

function loop_on_tag( alias, tag, bStopSoundOnDeath )
{
	org = Spawn( "script_origin", ( 0, 0, 0 ) );
	org endon( "death" );
	if ( !isdefined( bStopSoundOnDeath ) )
	{
		bStopSoundOnDeath = true;
	}
	if ( bStopSoundOnDeath )
	{
		thread util::delete_on_death( org );
	}
	if( isdefined( tag ) )
	{
		org LinkTo( self, tag, ( 0, 0, 0 ), ( 0, 0, 0 ) );
	}
	else
	{
		org.origin = self.origin;
		org.angles = self.angles;
		org LinkTo( self );
	}
	//	org endon( "death" );
	org PlayLoopSound( alias );
	//	println( "playing loop sound ", alias, " on entity at origin ", self.origin, " at ORIGIN ", org.origin );
	self waittill( "stop sound" + alias );
	org StopLoopSound( alias );
	org Delete();
}
So if anyone wanna use it, you need this using:
#using scripts\shared\sound_shared;
and you can call it just with the alias or also specify a tag if you want to:
entity thread sound::loop_on_tag( "alias_name");
and apparently stop the sound like this:
entity notify( "stop sound" + "alias_name" );


ModmeBot:

Reply By: ltschase
Got it working using StopLoopSound.