Game Development Community

Sound Triggers

by Steven Barrion · in Technical Issues · 09/05/2007 (10:53 am) · 2 replies

Hello out there im trying to create triggers for my sound so when the orge player steps in a certain area where trigger is it will play, but i cant seem to get my script to work so my sound can play. can any one give me some tips on how to create the right script for my triggers to play my sounds it would be helpful.

#1
02/25/2008 (7:48 am)
I have been having the same problem. If anyone has some input, I would greatly appreciate it.
#2
02/25/2008 (1:56 pm)
That's really simple.

Open starter.fps/server/scripts/ and copy triggers.cs to another folder.
Rename it to something you'll remember. (could be "mySoundTrigger.cs")

At the top, find:
datablock TriggerData(DefaultTrigger)

Change the DefaultTrigger name to something else...(could be "mySoundTrigger")

In each and every datablock, change "DefaultTrigger" to the same name as you just did above.

Then, in the onEnterTrigger datablock, change it to read:
function mySoundTrigger::onEnterTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object enters the %trigger
   // area, the object is passed as %obj.  The default onEnterTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,1) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onEnterTrigger(%this,%trigger,%obj);
   alxPlay( "myCoolSound" );
}

Now, all you have to do is to make a datablock for your sound file.

datablock AudioProfile(myCoolSound)
{
   filename = "~/data/sound/mySound.ogg";
   description = "Audio2D";
	preload = false;
};
I place my sound files in audio.cs, but you can also place it at the top of the trigger script.

Now, if you want a different sound to play on exit, you first need to make sure there isn't a sound playing by adding:

function myCoolSoundTrigger::onLeaveTrigger(%this,%trigger,%obj)
{
   // This method is called whenever an object leaves the %trigger
   // area, the object is passed as %obj.  The default onLeaveTrigger
   // method (in the C++ code) invokes the ::onTrigger(%trigger,0) method on
   // every object (whatever it's type) in the same group as the trigger.
   Parent::onLeaveTrigger(%this,%trigger,%obj);
  alxStopAll;
  alxPlay( "myCoolSound2" );
}

And that's all there is too it. Just make sure your sound files are in place, and the datablocks are read prior to the trigger.cs and it should work fine.
Hope that helps you a bit.