Custom sound(s) by trigger ?

Post your scripting questions / solutions here

Moderator: Moderators

Post Reply
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Custom sound(s) by trigger ?

Post 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:
Image
User avatar
At0miC
General
Posts: 1164
Joined: Fri Feb 27, 2004 11:29 pm
Location: The Netherlands

Post 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)
Grassy
First Lieutenant
Posts: 221
Joined: Sun Aug 22, 2004 11:36 am

Post 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
}
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post 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 ?
Image
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post 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.
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post by Kalti »

Thanks Wacko... that worked, although the trigger only seems to work once.

Any Idea what can cause that to happen ?
Image
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post 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 ?
Image
panTera
Brigadier General
Posts: 573
Joined: Wed Jan 29, 2003 11:46 pm
Location: The Netherlands
Contact:

Post 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.)
User avatar
wacko
Field Marshal
Posts: 2085
Joined: Fri Jul 05, 2002 8:42 pm
Location: Germany

Post 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.
User avatar
Kalti
Major
Posts: 325
Joined: Sun Mar 16, 2003 11:46 am
Contact:

Post 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
Image
Post Reply