Tutorial: ambient_generic Last edited 18 years ago2005-10-27 04:00:00 UTC

You are viewing an older revision of this wiki page. The current revision may be more detailed and up-to-date. Click here to see the current revision of this page.

This article was converted from a previous version of TWHL and may need to be reviewed

  1. The formatting may be incorrect due to differences in the WikiCode processing engine, it needs to be revised and reformatted
  2. Some information may be out of date
  3. After the article is re-formatted and updated, remove this notice and the Review Required category.
  4. Some older tutorials are no longer useful, or they duplicate information from other tutorials and entity guides. In this case, delete the page after merging any relevant information into other pages. Contact an admin to delete a page.
Obviously, there are two main components to a game. There are the visual effects and the audio effects, both equally important. As we map for Half-Life, we usually don't have to add any audio effects, since we are mapping for an already coded game. What if you wanted to add your own music or sound effects into the game? Well, we can do this simply through the ambient_generic entity.

Triggering a Sound

Lets say you have an electric platform. When the player steps on this platform, you want it to make a sound. Well, This is a simple task. The only difficult part is supplying the sound.

The Sound

Half-Life is very specific in its sounds format. The sound must be in .WAV format, which most of them usually are. Make sure that the sound is 8-bit mono, otherwise it will not work properly, or might just not work at all. After you have a sound in the right format, whether you make a custom sound, or find an already made sound, you must put it in the right folder. Refer to the Making Custom Sounds tutorial for more details on that subject. If you are making a map for Half-Life, it must be in the valve/sound/ambiencefolder. If you are making a custom MOD, you must create a sound/ambience folder in order for it to work. Now that you have your sound in the right place, the next step is to use an ambient_generic to trigger it.

Triggering the Sound

Now, you have to create your ambient_generic. Using the entity tool, put your ambient_generic in the exact spot where you want it to play. The player can only hear the sound if he is facing in its direction, so in this case, we would place the ambient_generic right above the electric platform.

Name the entity something like elec_plat_sound so you can easily remember it. Now that it has a name, create a trigger_multiple, or a trigger_once (depending on if you want the sound to play over again if you step on the platform another time). Place the trigger on the platform, where the player must be for the ambient_generic to play. Make the trigger trigger the ambient_generic... obviously...

Setting up the sound to play

Now you must work with the ambient_generic itself. Go into its properties and select WAV name. This next step is usually what causes most people errors: avoid using the browse tool. You should already have put your sound file in the correct folder, and you should already know its name. Instead, type in the path relative to the mod directory sound folder. When Hammer looks for the .WAV file, it assumes you are already in the sound folder. Merely type in ambience/blah.wav (with a forward slash). This should locate the correct file. Now your sound should play when triggered, but there are some more attributes that you should look at first.

Properties and Flags

Generally, I leave all the properties at their default state, although you may want to mess around with them sometime. The flags are very important though, and you should make sure they are all correct before compiling. Play Everywhere pretty much does what it says... it plays everywhere. Beware: this does not mean that the sound will play equally loudly through each speaker (as if you were just listening to an audio file) it only means that the distance you are from the sound does not matter. We will cover how do counter this directional effect. The Small Radius, Medium Radius, and Large Radius checks control how far you can be away and still hear the sound.

Start Silent obviously does what it says as well. If you do not click this flag, the sound will play as soon as the map has loaded. This probably is only effective when doing music, which we will cover next. In our specific example using the electric platform, you must click this flag, or the file will not start when you touch the trigger.

Music

Lets say you want some background music in your map. You will still use an ambient_generic, and a .WAV file, but there is a different technique to doing this effectively.

As we covered before, the player will hear the ambient_generic as if the sound was being emitted from its position. For background sound, this is highly undesirable, and easily countered. Obviously, the Play Everywhere flag must be pressed, and the Start Silent flag must be unchecked.

Create the ambient_generic that will play the music. Do not name it anything. Create hollowed out brush boxes on each side of your map: one for north; one for east, etc. Copy your ambient_generic and place one in each of the boxes. Make sure that you do not use too many ambient_generics, but just enough so that you can always hear the music without noticing the variations in volume.

5 Comments

Commented 16 years ago2008-02-27 23:24:41 UTC Comment #100724
I'm making a HLDM map that I want to put some music in. The music is about 1 minute 25 seconds. I've set it up with four ambient_generics, each set to play the WAV file, which IS 8 bit mono, and they all have Play Everywhere checked. No other flags are set. It looks right according to this tutorial, but the music won't repeat! Does anyone know what's going on?
Commented 15 years ago2008-07-13 05:55:29 UTC Comment #100725
i see that cscz can play music whit mp3 sound track each levels. How to make that?
Commented 13 years ago2010-10-10 03:08:08 UTC Comment #100726
computergod666, what you COULD do is make a multi-manager that repeats itself so that the wad files plays on and on and on.
Commented 7 years ago2016-05-29 05:00:36 UTC Comment #100728
im trying to trigger elevmove2.wav when im starting my level in the elevator, it plays the sound but it keeps looping forever, im using trigger_once and multi_manager in order to do so. how do i fix that?
Commented 6 years ago2017-10-21 18:29:42 UTC Comment #100729
You can use trigger_relay

You must log in to post a comment. You can login or register a new account.