Adding custom sounds with a trigger

Have questions about CoD/UO mapping that aren't covered in the tutorials section? Post here!

Moderator: Core Staff

Post Reply
Luke
Past/Inactive Team Member
Past/Inactive Team Member
Posts: 1774
Joined: May 31st, 2005, 12:42 am
Location: Cornwall, UK

Adding custom sounds with a trigger

Post by Luke » December 21st, 2005, 2:47 am

Heres how you go about adding custom sounds to your map with a trigger.

Mapping:

Lets start by adding a trigger. Create a brush with the trigger texture (common/trigger) in the spot that you want the sound to be started when the player touches it.
Then right click on it and select trigger > multiple.
Keep the brush selected and press N, now you need to enter the values for the trigger, so for key enter “targetname”, and put in a name you want for it in the value, for my example i’ll call it “mysound”.
Once you’ve entered those values hit enter so the values should appear in the white box above.

That’s your trigger done, and the final part of the mapping is to add a script_model, this will be the origin of where the sound comes from. So to do this, right click and go to script > model, close the open dialog as we don’t want to open an xmodel, just keep the entity box open, as once again you need to give it a targetname, so key: targetname, and for this example i’ll call it origin1, so value: origin1, hit enter, and that’s the mapping part done.

Scripting:

Here’s the fun part, making the script…To keep things tidy make your sound script a separate .gsc, in my example map i’ve called it “sounds.gsc”

Based on the values above, here is the script to be used:

Code: Select all

main() 
{ 
   thread sound1();
}

sound1() 
{ 
messagetrig = getent ("mysound","targetname"); //"messagetrig" can be called anything, it simply calls the entity which you created in your map

alert = getent ("origin1", "targetname"); 

while(1) 
{ 
messagetrig waittill ("trigger");//"messagetrig" calls the entity above

alert playsound("example");  // “example” is the name of the alias used to play the sound which is in the csv file

wait 3; 
} 
}
Anything after // is just notes and isn't part of the script. Try to use unique targetnames, and entity calls to avoid conflicts with other maps.

You will need to add a line to your mapname.gsc to run the sound script, so in this case you would add: maps\mp\sounds::main();

CSV file:

The csv file controls how the sound is played, i.e. the distance it can be heard from, looping, volume ect. If you open the csv included in the pk3, you'll see a list at the top describing what each thing does. You can edit this file with microsoft excel.

I'm including a .map and working pk3 for you, download here: http://www.aufa87.dsl.pipex.com/soundtest.zip so you should have everything you need :wink:
Last edited by Luke on January 1st, 2006, 3:00 am, edited 2 times in total.

User avatar
Drofder2004
Core Staff
Core Staff
Posts: 13315
Joined: April 13th, 2005, 8:22 pm
Location: UK, London

Post by Drofder2004 » December 21st, 2005, 4:57 pm

Also, change the wait time depending on how long your sound file is.
Image
Virgin Media 20Mb Broadband:
"Perfect for families going online at the same time, downloading movies, online gaming and more."
Borked internet since: 22-07-2010

Luke
Past/Inactive Team Member
Past/Inactive Team Member
Posts: 1774
Joined: May 31st, 2005, 12:42 am
Location: Cornwall, UK

Post by Luke » December 22nd, 2005, 10:47 pm

Drofder2004 wrote:Also, change the wait time depending on how long your sound file is.
ahh yes :oops: it should actually be 5 seconds wait time in my example, thanks for that.

Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests