.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
  Posts  
Sounds on a map? (Groups : qc : Forum : discuss() : Sounds on a map?) Locked
Thread Options
numbersix
numbersix quake-c coder++
Oct 30 2011 Anchor

>Hello,can you tell me how i can make a sound on the map in worldcraft? (trigger)

There are 3 basic ways to play sounds on maps:

1. Maps "sounds" number - put in worldspawn, attempts to play a cd track for a map.
-- you either need a cd in a drive wired to the soundcard, or a "darkplaces" type cdtracks file.

2. Ambient sound - either the fire crackle from flames, sky woosh, water flow, or one of the ambient_* sounds.

3. A sound generated by quake-c code.

You'll note none of these are triggered. Vanilla quake does not have trigger sounds. You cant play a looped sound unless its one of the ambient_* sounds.

To play a specific sound, either by trigger or otherwise you will have to use custom code.

The hipnotic code base does this:

play_sound
play_sound_triggered

You could add this to any mod, the quake-c follows at the end of this text.
(You should at this point have basic know-how about map editing, such as manipulating brushes, adding entities and triggers in your map editor of choice.)

In the map editor:

1. update entities definition (by getting a file for your editor with hipnotic support or - ) with:

/*QUAKED play_sound_triggered (0.3 0.1 0.6) (-8 -8 -8) (8 8 8 ) toggle
-------- HIPN --------
Hipnotic/Zerstorer Special Effect
-----------------------
play a sound when it is used

toggle determines whether
sound should be stopped when
triggered again

"volume" how loud
(1 default full volume)

"noise" sound to play

"impulse" channel on which
to play sound (0-7)
(0 automatic is default)

"speed" attenuation factor
-1 - no attenuation
1 - normal
2 - idle
3 - static
*/

/*QUAKED play_sound (0.3 0.1 0.6) (-8 -8 -8) (8 8 8 )
-------- HIPN --------
Hipnotic/Zerstorer Special Effect
-----------------------
play a sound on a periodic basis

"volume" how loud
(1 default full volume)

"noise" sound to play

"wait" random time between sounds
(default 20)

"delay" minimum delay between sounds
(default 2)

"impulse" channel on which to play sound
(0-7)
(0 automatic is default)

"speed" attenuation factor
-1 - no attenuation
1 - normal
2 - idle
3 - static
*/

2. Follow the instructions above and add your "play_sound_triggered". The fields specified need filled out correctly.

At a minimum you need:
"noise"
"targetname"

Now, add a "trigger" entity. This can be touch or shootable or whatever. The minimum is:

A map brush made into a trigger (trigger texture recommended even though its never seen - just for editing purposes) the
player can touch in his travels with a "target" field equal to "play_sound_trigger"'s "targetname". Fancy triggers that happen automatically can be set up as well. All kinds of things can be done once you have play_sound entities.

Your map editor 3D view might look something like this:

The player walks along the stone texture brush and hits the (non-visible) trigger. The sound plays from the purple box the trigger targets. The box location is *where* the sound originates when played.

After you build and compile the map and put it in quake/id1/maps, you could:

get progs.dat from the hipnotic quake-c code package - Moddb.com
Put this in a new subdirectory of quake:
quake/playsnd

Run it:
quake -game playsnd +map mymap

or if you like painkeep, 2.2 supports play_sound - main: Moddb.com - 2.2 update: Moddb.com - install the main pack and the update.

Run it:
quake -game painkeep +map mymap

Now test your sound trigger.

The reason I include painkeep is that it is a (free) and complete package, even though the install is bigger. Everything will (should at least) work. With the hipnotic quake-c there are many functions that require hipnotic models, sounds and support. Since you are just using play_sound this should not have an impact.

This quake-c could be added to any mod - (you should give credit to hipnotic if you do this.)
You might also want to look up the license for hipnotic quake-c. It could be GPL, or it might have restrictions. (Usually commercial use is forbidden in these cases.)
Place this in sound.qc and add that at the end of progs.src, compile with qc compiler or choice (frikqcc is very good) and place progs.dat as indicated above:

/* Miscelanneous QuickC program
Copyright (c)1996 Hipnotic Interactive, Inc.
All rights reserved.
Distributed (unsupported) on 3.12.97
*/

void() play_sound_use =
{
if (self.spawnflags & 1)
{
if (self.state == 0)
{
self.state = 1;
sound (self, self.impulse, self.noise, self.volume, self.speed);
}
else
{
self.state = 0;
sound (self, self.impulse, "misc/null.wav", self.volume, self.speed);
}
}
else
{
sound (self, self.impulse, self.noise, self.volume, self.speed);
}
};

void() PlaySoundThink =
{
local float t;
t = self.wait * random();
if (t < self.delay)
t = self.delay;
self.nextthink = time + t;
play_sound_use();
};

/*QUAKED play_sound_triggered (0.3 0.1 0.6) (-8 -8 -8) (8 8 8 ) toggle
play a sound when it is used
"toggle" determines whether sound should be stopped when triggered again
"volume" how loud (1 default full volume)
"noise" sound to play
"impulse" channel on which to play sound (0-7) (0 automatic is default)
"speed" attenuation factor
-1 - no attenuation
1 - normal
2 - idle
3 - static
*/
void() play_sound_triggered =
{
precache_sound (self.noise);
precache_sound ("misc/null.wav");
if (self.volume == 0)
self.volume = 1;
if (self.speed == 0)
self.speed = 1;
if (self.speed == -1)
self.speed = 0;
if (self.spawnflags & 1)
if (self.impulse == 0)
self.impulse = 7;
self.use = play_sound_use;
};

/*QUAKED play_sound (0.3 0.1 0.6) (-8 -8 -8) (8 8 8 )
play a sound on a periodic basis
"volume" how loud (1 default full volume)
"noise" sound to play
"wait" random time between sounds (default 20)
"delay" minimum delay between sounds (default 2)
"impulse" channel on which to play sound (0-7) (0 automatic is default)
"speed" attenuation factor
-1 - no attenuation
1 - normal
2 - idle
3 - static
*/
void() play_sound =
{
local float t;

play_sound_triggered();
if (self.wait == 0)
self.wait = 20;
if (self.delay == 0)
self.delay = 2;
self.think = PlaySoundThink;
t = self.wait * random();
if (t < self.delay)
t = self.delay;
self.nextthink = time + t;
};

------------
Addendum:
------------

Note about where quake keeps / looks for sounds and sample map ents.

Quake expects to find the sound in "quake/id1/sound/" or "quake/mymod/sound" - so the sample wav file is in "quake/id1/sound/items/protect.wav".
For new sounds, if you have a mod, the sounds should be under sound in the "mymod" (name of your mod) directory. Unless you need to access them from different mods, in which case they need to be under "quake/id1/sound/mymodsnd" where "mymodsnd" is some description of your sound repository.

Sample ents from radiant:

// entity 25
{
"wait" "3"
"target" "snd1"
"classname" "trigger_multiple"
// brush 0
{
( -1080 -240 65536 ) ( -968 -240 65536 ) ( -968 -240 -65536 ) q1tex/trigger 0 0 0 0.500000 0.500000 0 0 0
( -968 -240 65536 ) ( -968 -112 65536 ) ( -968 -112 -65536 ) q1tex/trigger 0 0 0 0.500000 0.500000 0 0 0
( -960 -72 65536 ) ( -1072 -72 65536 ) ( -1072 -72 -65536 ) q1tex/trigger 0 0 0 0.500000 0.500000 0 0 0
( -1096 -104 65536 ) ( -1096 -232 65536 ) ( -1096 -232 -65536 ) q1tex/trigger 0 0 0 0.500000 0.500000 0 0 0
( -1000 -104 -48 ) ( -1056 -104 -48 ) ( -1056 -232 -48 ) q1tex/trigger 0 0 0 0.500000 0.500000 0 0 0
( -1192 -112 -32 ) ( -1048 -112 -32 ) ( -1192 -240 -32 ) q1tex/trigger 0 0 0 0.500000 0.500000 0 0 0
}
}
// entity 26
{
"noise" "items/protect.wav"
"targetname" "snd1"
"origin" "-1136 -96 -40"
"classname" "play_sound_triggered"
}

When the player ent is standing in the trigger brush, "quake/id1/sound/items/protect.wav" is played every 3 seconds.

------------
Addendum:
------------

There was another problem with the sound looping even when the trigger's "wait" "3" was changed to "wait" "-1".
This was solved by opening the sound sample in an editor, then cut & paste into a "new" sample and saving /using that.

I suspect the unwanted looping issue has something to do with the data in the wav file and what the engine code sees.

--

\|/
-*- Support free code: Patreon.com
/|\

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.