Snarkpit Articles


Custom Soundscapes



This tutorial will tell you how to add custom soundscapes to your Source maps.

The main property of soundscapes is that they use a .txt file as script, that tells them what to play. This is usefull if you want to change the sounds or control them without having to open hammer. Another thing is that the soundscape will continue playing untill the player triggers another, this can be used to change from outside sounds (wind, birds and that stuff) to inside sounds. They?re really powerfull if you know how to place and edit them. Lets see if I can show you the way...

Lets start with the basics of the soundscapes.txt. To be able to play soundscapes in our custom map, we need to create a soundscapes_mapname.txt in <game dir>/scripts, if there is no scripts directory, you have to create it. This file is a simple key/value pair file with the same format as .VMT or .VMF

"example"

{
"key1" "value1"
"key2" "value2"
"subexample"
{
"key3" "value3"
}
"key4" "value4"
}


In this tutorial I'm gonna build a disco map, so I'm gonna create a file named: soundscapes_disco.txt

// Plays the sounds inside the disco

"disco.playmusic"
{
// Set dps to automatic
"dsp" "1"
// Plays random waves
"playrandom"
{
// Play every 10 seconds (you can set the amount here)
"time" "10"
// At 100% volume (0 = 0ff)
"volume" "1"
// At 100% pitch
"pitch" "100"
// Random wave files
"rndwave"
{
"wave" "disco/song1.wav"
"wave" "disco/song2.wav"
"wave" "disco/song3.wav"
}
}
}
// This will turn off the music
"disco.stopmusic"
{
"dsp" "0"
}


NOTE: The .wav files are located in <game directory>/sounds/disco
For the time value, you can use whatever time you want. I suggest using a little higher timer than the duration of every .wav file. For example, if the above songs are 9secs duration each, I'm setting a 10s timer, so we can get a smooth fade between songs and you wont hear the sound cut.

With this .txt file we can make two soundscapes: one to trigger the disco music and play the 3 .wav files randomly and another to turn off the sound.

Now we can open hammer to start editing our map.

We're gonna make a big square room divided in two rooms and a door between both, so we can have a room with sound and the other without. Refer to other tutorials if you dont know how to build a basic room/door.



Now we're gonna place an env_soundscape in one room. Go to propeties and lets get started...

image

Target name: disco_speaker_on
Start disabled: no
Radius: -1
Soundscape: disco.playmusic

You can set a positive radius if you want. When the player gets in touch with it will hear the sound. If you set to -1, as soon as the player sees it, the sound will play. The soundscape value, refers to the functions we made in the soundscapes_disco.txt file, remember the "disco.playmusic" and "disco.stopmusic"? That name is the reference for the sentences below it, so the soundscape can find what to play and how.

Since we're using an env_soundscape without radius, the ideal position should be above the door, so it can be activated as soon as the player crosses the door.



If we want to use a radius, we should locate the env_soundscape properly, so the player touches it as soon as we want them to hear the music. This would be a good position for this example (using radius)



Ok, we have now sound, we can test the map now, but we wont be able to stop the sound even if we get to the other room. To avoid this we have to set another env_soundscape in the other room with this values:

Target name: disco_speaker_off
Start disabled: no
Radius: -1
Soundscape: disco.stopmusic

Now we can compile and run the map without fear. When a player reaches the disco room it will hear randomly the sound, when he crosses to the other room, sound will stop.

So, as you can see its kinda easy to use custom sounds in our maps, at least the hammer part. Finding and editing sounds its up to you.

Note: You can download the example here


Post ReplyView Topic
Discussion
0 starsPosted by quanta on Thu Jun 14th 2007 at 11:04pm

Two things:

1: The download doesnt work.

2: I followed the tutorial exactly, and the developer console says &quot;cant find soundscape soundscape_test.playtest&quot;. I've created a hl2 map called soundscape_test.bsp, and a script file called soundscapes_soundscape_test.txt. This is what's in the file:

&quot;soundscape_test.playtest&quot;
{
&quot;dsp&quot; &quot;1&quot;
&quot;playlooping&quot;
{
&quot;volume&quot; &quot;1&quot;
&quot;pitch&quot; &quot;100&quot;
&quot;wave&quot; &quot;ambientmachineslab_loop1.wav&quot;
}
}
&quot;soundscape_test.stop&quot;
{
&quot;dsp&quot; &quot;0&quot;
}

In the map, I have an env_soundscape in the center with:

Target Name: soundscape
Radius: -1
Soundscape: soundscape_test.playtest

Any idea on why this doesn't work?
0 starsPosted by Anthony on Wed Jan 25th 2006 at 2:33am

Good, but you should've gone a little into what DSP is (i.e. the various effects you can assign to the sounds) which can help change the atmosphere if used correctly.
[author]
Posted by Silmano on Tue Jan 10th 2006 at 11:16am

Lol, dont really know why I had a black picture... I've changed the link and I think its ok now... Thanks for the rates! Glad you like the tutorial
0 starsPosted by parakeet on Mon Jan 9th 2006 at 11:09pm

I was always wondering how to make my own ^___^ , should be helpful esp for modders. what's up with the completly black picture though... rates a 7
0 starsPosted by Orpheus on Sat Jan 7th 2006 at 3:16am

I will give you half credit because I love disco and you chose to illustrate your example by using a disco wave but, those god awful sized screens have got to be fixed. When a lousy 4 inch picture is 54k something is seriously wrong with your optimization process. You might want to check out a certain tutorial on picture posting.

[edit] Sadly, the stupid site won't allow me to rate you a score so you will have to assume I gave you a 5/10 smiley
Post ReplyView Topic