Start/Loop/Stop sounds

From The DarkMod Wiki
Jump to navigationJump to search

written by Flanders

Introduction

This tutorial explains how to set up a triggering system with three sounds: a starting sound, a looping sound and a stopping sound. This can be used for machines that can be turned on/off or for other sound systems that behave in a similar way. There is more than one way to do this but here we use a simple trigger system with a custom made sound shader.

What to do

You’ll have to find some sounds that fit your machine, here I’ll use these:

sound/machinery/generators/generator_start_01.ogg

sound/machinery/generators/generator_loop_01.ogg

sound/machinery/generators/generator_stop_01.ogg

The start and loop sound can be combined into a soundshader like this:

machine_on
{
   looping
   leadin
   sound/machinery/generators/generator_start_01.ogg
   sound/machinery/generators/generator_loop_01.ogg
}

After the first sound is played, the second sound will start looping. Save this soundshader in your Doom 3/darkmod/sound folder as machine_on.sndshd.

Open your map in Darkradiant and import the machine_sounds_system prefab from the prefab/mechanical folder.

For speaker_machine_stop set “s_shader” to sound/machinery/generators/generator_stop_01.ogg. For speaker_machine_start set “s_shader” to machine_on. That’s all there is.

How the prefab works

When machine_lever is used it triggers speaker_machine_start, playing the sounds in the machine_on soundshader. The lever also triggers OnOffCount, this trigger counts the times it has been triggered itself. Because the “count” property of OnOffCount has been set to 2 it will only fire its target, speaker_machine_stop, the second time it is triggered. The second time the lever is used it triggers speaker_machine_start, turning it off. OnOffCount triggers speaker_machine_stop. With “repeat” set to 1 OnOffCount will start counting all over again if it’s triggered the amount of times set with “count”. OnOffCount acts as a reverse trigger so to say.