Page 1 of 1

Custom sound(s) by trigger ?

Posted: Tue Jan 25, 2005 9:42 am
by Kalti
Ehrm... i've just implemented a first custom sound in my map by use of Adding Custom Sounds tutorial...

And it's working great :D However I want the sound only to play when a player is near... should I do this with a trigger multiple ?

Also I have more sounds to add and some of them need to play once when triggered, so can I just add a trigger in my map which targets the sound ?

Sorry about the melee of questions, but this scripting/mapping thing is still rather new for me, and I'm really just looking for some confirmation and perhaps some example scripts :wink:

Posted: Tue Jan 25, 2005 10:45 am
by At0miC
Yes it's easy,

(trigger multiple)


$trigger waittill trigger
$speaker playsound my_sound

or for a loopsound:

$trigger waittill trigger
$speaker loopsound my_sound

stop the loopsound using:

$speaker stoploopsound


If you want to play the sound if the player is near the speaker, you don't have to use a trigger,

local.master aliascache snd_river sound/song.wav soundparms 1.0 0.2 1.0 0.2 200 2000 auto loaded maps "obj dm"

The numbers in red is the max distance the sound would be heard in the game (in units)

Posted: Wed Jan 26, 2005 5:33 am
by Grassy
Here is a simple little routine I wrote for one of our maps with a Grandfather clock we wanted to tick and chime, but only if a player was nearby, to save server resources.
Use a trigger_multiple around your script object as big as you need for sound distance to carry.

Code: Select all

//------------------------
tic_toc:
//------------------------
while (1)
{
  $trigger_clock waittill trigger
  local.player = parm.other
  $trigger_clock nottriggerable
  $clock loopsound clock_tick
  while ( local.player isTouching  $trigger_clock )
  {
    wait 1
  }
  $clock stoploopsound clock_tick
  $trigger_clock triggerable
}

Posted: Wed Jan 26, 2005 8:56 am
by Kalti
Okay, I've been toying with the solution AtOmiC mentioned...

And it looks like my sound is triggered because I'm getting a console message somewhere around the lines of "cannot playback stereo wav file" & "Microsoft PCM format only"

So, I take it that shows me my trigger works, but my wav file isn't compatible ?

Posted: Wed Jan 26, 2005 9:52 am
by wacko
Kalti wrote:And it looks like my sound is triggered because I'm getting a console message somewhere around the lines of "cannot playback stereo wav file" & "Microsoft PCM format only"
So, I take it that shows me my trigger works, but my wav file isn't compatible ?
The answer u already got in the console: The wav file must be PCM/mono format.
Most soundcards come with software to edit/convert ur wav file. In fact, even WinAmp can do this: Go Preferences/Output, select Nullsoft Diskwriter, go Configure, Choose 'PCM' as format and Attribute '44kHz, 16bit, mono' and "play" the file. The wav file is then written to the selected output directory.

Posted: Wed Jan 26, 2005 4:31 pm
by Kalti
Thanks Wacko... that worked, although the trigger only seems to work once.

Any Idea what can cause that to happen ?

Posted: Wed Jan 26, 2005 7:41 pm
by Kalti
Okay nevermind, I think I have it solved...

Code: Select all

local.master = spawn ScriptMaster

local.master aliascache snd_chickens sound/amb_stereo/venice_chickens.wav soundparms 1.0 0.2 1.0 0.2 200 2000 auto loaded maps "obj dm"
local.master aliascache snd_flush sound/amb_stereo/venice_flush.wav soundparms 1.0 0.2 1.0 0.2 200 2000 auto loaded maps "obj dm"

	level waittill prespawn

	$trigger_chickens thread trigger1
	$trigger_toilet thread trigger2

	level waittill spawn

trigger1:
while (1)
{
	$trigger_chickens waittill trigger
	$speaker_chickens playsound snd_chickens
}
end

trigger2:
while (1)
{
	$trigger_toilet waittill trigger
	$speaker_toilet playsound snd_flush
}
end
Now, how about preventing one specific sound from being triggered again while it's playing ?

Posted: Wed Jan 26, 2005 8:31 pm
by panTera
Add a 'wait' in the thread the same length as the wav file maybe?

(@ Grassy, thanks for that tip of yours :roll: , exactly what I was looking for.)

Posted: Wed Jan 26, 2005 9:03 pm
by wacko
Combining ur thread with grassy's would be:

Code: Select all

trigger1: 
while (1) 
{ 
	$trigger_chickens waittill trigger 
	local.player = parm.other 
	$trigger_chickens nottriggerable 
	$speaker_chickens loopsound snd_chickens 
  	while ( local.player isTouching  $trigger_chickens ) 
	{ 
		wait 1 
	} 
	$speaker_chickens stoploopsound 
	$trigger_chickens triggerable
} 
end
and that ought to work! It would play the sound again and again in a loop until the player leaves the trigger.

Posted: Wed Jan 26, 2005 9:28 pm
by Kalti
Guys, thank you very much... I'm quite happy with the script for the chickens as it's to be used in a situation where the player scares off some chickens while sneaking through the bushes.

However, I have a location where I would need to have the sound playing for as long as there's a player in the trigger, so just have to get that in the map aswell.

Thanks,

Kalti