56k Beware; there are a few pictures.
So first I am already going to go ahead and assume you know how to make a correct pk3 file. If not then do not try this tutorial, you will probably not understand much.
Preparing on the map
So first before we are going to go into any scripting, we shall first prepare the "speaker" in the map.
To spawn a "speaker" just right click over your 2d grid and select script/model
This should appear:
Just click cancel on the model selector but leave the entity editor open.
Now just enter the things below:
Key:targetname
Value:sound_tut_speaker
Remember that you can choose any name you want for the value but
Note:Always put your map name in front of the value, this prevents conflicting problems.
Ok, so now that the speaker has been added I am just going to go ahead and make a trigger to activate the sound.
Adding a trigger
To add a trigger is pretty simple, I have already explained it in my other tutorial but I will go ahead and do it again.
First: Go to your common texture and choose the trigger texture, for this I am going to make a "use" trigger meaning you will have to press F to activate.
Then: Once you have put your trigger in the selected spot right click it (with the trigger still being selected) and select trigger/use.
The outline of that trigger should become blue.
Now with it still selected press n to bring up the entity editor so we can add some values.
Key:targetname
Value:sound_tut_trig
So now that we are done with the preparing it is time to go into the scripting.
Note:I am going to assume you know how to add a skybox a spawn and know how to compile a map.
Folders and CSV
Ok, so I have the pk3 set up with the maps/mp and the mp folder, but there are now some more folders to add.
So now you will have to add two more folders
Make one named sound and another named soundaliases
Note: You can put another folder inside the sound folder, this is not a required task but it helps prevent conflicting.
The folder named sound will contain the custom sound you have to put in.
Soundaliases will give the sound a type of targetname for the script to look for when in game.
Note: Only use a .wav file for a triggered or non-ambient sound, and use the mp3 format for ambient
(I have no idea why they made it like that but that’s just the way it is.)
Do not forget you can also already use sounds from the game, you will need to look at pak1.pk3 for the sound names to use.
But because we want to use our own sound we might as well just go ahead.
So remember my note above, because we are using a trigger this sound must be in .wav format.
I just quickly got a sound effect from Google. (You can find some very nice ones with some good amount of searching.)
So I will now add the .wav file in my sound/sound_tut. (remember my note above)
Now comes the tricky part, and this is adding the csv file, this can be edited using either notepad or Window's Excel.
I am going to make mine using notepad.
Code: Select all
,name,name of the alias that is used to play this sound (required)
,sequence,"used to uniquely identify alias entries when more than one sound goes to an alias, used only to catch unwanted duplicates (default = 0)"
,file,the name of the file that contains the sound data (required)
,vol_min,"0 is silent, 1 is full volume (default = 1)"
,vol_max,"0 is silent, 1 is full volume (default = same as vol_min)"
,pitch_min,"1 is normal playback, 2 is twice as fast, 0.5 is half as fast (default = 1)"
,pitch_max,"1 is normal playback, 2 is twice as fast, 0.5 is half as fast (default = same as pitch_min)"
,dist_min,"within this distance in inches, the sound is always full volume (default = 120)"
,dist_max,"outside this distance in inches, the sound is not started. If left blank or set to 0, the sound will play from any distance. This does not affect sound volume falloff."
,channel,"auto, menu, weapon, voice, item, body, local, music, announcer (default = auto)"
,type,streamed / loaded (default = loaded)
,probability,weight to use for the weighted probability of playing this sound instead of another sound (default = 1)
,loop,"whether this sound is ""looping"" or ""nonlooping"" (default = ""nonlooping"")"
,masterslave,"if ""master"", this is a master sound. If a number, then this sound won't exceed this volume whenever any master sound is playing. If blank, then neither master nor slave."
,loadspec,"space-separated list of which maps should use this alias; eg, ""burnville dawnville"". If blank, the alias is used on all maps."
name,sequence,file,vol_min,vol_max,pitch_min,pitch_max,dist_min,dist_max,channel,type,probability,loop,masterslave,loadspec,subtitle
null,1,null.wav,,,,,,,,,,,,,
#Sounds,,,,,,,,,,,,,,,
sound_tut_s,,sound_tut/sound_tut_sound.wav,1,1,,,2000,2000,auto,,,nonlooping,,,
Alright, almost done, now that we have our sound file in place and our csv file naming the sound we can now script it in.
Scripting
To start off make a notepad file in the maps/mp right beside the bsp file.
And now for the simple part:
Code: Select all
main()
{
maps\mp\_load::main();
thread sound_tut();
}
sound_tut()
{
speaker = getent ("sound_tut_speaker","targetname");
trigger = getent ("sound_tut_trig","targetname");
while(1)
{
trigger waittill ("trigger");
speaker playsound("sound_tut_s");
wait(2);
}
}
So save this as a gsc file and make your pk3 with all four folders in them.
Congratulations!
You have made it through and have successfully made a working sound script!
Here is the zip file containing everything, even the .map file
Click Here
Well, I hope this tutorial helped anyone out; I will try to come with some more tutorials later!
Made By Nightmare