Adding custom sounds with a trigger
Posted: 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:
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
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;
}
}
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
