UE1 - UT TriggerAmbientSound

  • Two Factor Authentication is now available on BeyondUnreal Forums. To configure it, visit your Profile and look for the "Two Step Verification" option on the left side. We can send codes via email (may be slower) or you can set up any TOTP Authenticator app on your phone (Authy, Google Authenticator, etc) to deliver codes. It is highly recommended that you configure this to keep your account safe.
Status
Not open for further replies.

RoninMastaFX

Unreal/UT Vet from Day 1
Hey everyone! :) You guys are probably not expecting me to write something in here, but for 10 years I have put aside the "non-coding" side of me, and I'm fed up and going to teach myself how to code UScript once and for all! xD

Anyway, my first coding task that I am going to do is a TriggerAmbientSound...however...I don't even know where to begin for extending the AmbientSound code :hmm:

I have read about 3 tuts...and 1 video tut (the UT2k3/4 Coding tuts of Coding), but this still does nto make sense of what exactly I should extend to make an AmbientSound turn on/off by a regular trigger. :hmm: :(

All suggestions would help out! :)
 

RoninMastaFX

Unreal/UT Vet from Day 1
Alright, I think I figured it out. I'll post of the Code that I have written:

Code:
//==================================================================================================================
// TriggerAmbientSound
// This class allows you to make your AmbientSound "triggerable" using the normal trigger method
// Created by Mitchell "[~]RUFX[~]RoninMastaFX" LeBlanc with the help of BlackCheetah
// Code is based from TriggerWaterZone, created by Scott 'Slasher IV' Kircher...couldn't have done it without him :)
//==================================================================================================================

class TriggerAmbientSound extends AmbientSound;

var() bool bStatus;  //Name of the new property: True=On while False=Off.  Will be at the bottom of the properties menu

function PostBeginPlay()

{

 Super.PostBeginPlay();

 

 if(!bStatus)

 {

    SoundRadius=64;
    SoundVolume=190;

 }

}

function Trigger( actor Other, pawn EventInstigator )  //Trigger properties - adds trigger code to make it switch on/off

{

 local Actor A;

 local Pawn P;

 local Decoration D;

 local TriggerAmbientSound oldself;

 oldself=self;

//
//  If the TriggerAmbientSound is set to OFF at the start, the trigger can turn it on, and back to off, and back and forth
//  If the TriggerAmbientSound is set to ON at the start, the trigger will turn it off, and back to on, and back and forth
//

 if(bStatus)

 {

  bStatus=false;  //TriggerAmbientSound is switched off

    SoundRadius=0;
    SoundVolume=0;
    ambientsound=none;
    
   }
else
{

  bStatus=true;  //TriggerAmbientSound is switched on

    SoundRadius=default.soundradius;
    SoundVolume=default.soundvolume;
    ambientsound=default.ambientsound;

   }

    

}

defaultproperties
{
}

Enjoy everyone. I will also upload the .u file for everyone that needs it! :)

P.S. Thank BlackCheetah for helping me! ;) :)


Ok, turns out that something is still not right with the code. :hmm: The sound plays within the ed and ingame no matter if the settings are switched to false (off) and True (on). :S I'm gonna figure this out quickly.
 
Last edited:

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
I don't think "default.AmbientSound" would contain any meaningful value. (None?)
It may be better to save a backup of the AmbientSound variable in (Pre/Post)BeginPlay() and use that instead of default.AmbientSound. And also I don't think you need to touch SoundRadius/Volume at all. If there's no AmbientSound, then the volume and radius doesn't matter.
 

RoninMastaFX

Unreal/UT Vet from Day 1
I don't think "default.AmbientSound" would contain any meaningful value. (None?)
It may be better to save a backup of the AmbientSound variable in (Pre/Post)BeginPlay() and use that instead of default.AmbientSound. And also I don't think you need to touch SoundRadius/Volume at all. If there's no AmbientSound, then the volume and radius doesn't matter.

Alright, I'll see what I can do m8. :)
 

RoninMastaFX

Unreal/UT Vet from Day 1
Alright, I've asked for BlackCheetah for help again, and me and him have come up with this:

Code:
//==================================================================================================================
// TriggerAmbientSound
// This class allows you to make your AmbientSound "triggerable" using the normal trigger method
// Created by Mitchell "[~]RUFX[~]RoninMastaFX" LeBlanc with the help of BlackCheetah
// Code is based from TriggerWaterZone, created by Scott 'Slasher IV' Kircher...couldn't have done it without him :)
//==================================================================================================================

class TriggerAmbientSound extends AmbientSound;

var() bool TriggerStatus;  //Status of the switch: True=On while False=Off
var() sound TriggAmbientSound;  //Import your triggered sound here
var() byte TriggSoundVolume,TriggSoundRadius;  //Change the Sound Volume and Redius of the triggered sound

//
//  NOTE:  The TriggerAmbientSound uses a totally new sound system...however, the old AmbientSound properties
//  are still included, just in case. However, for triggered sounds, use the TriggerAmbientSound menu
//

function PostBeginPlay()

{

 Super.PostBeginPlay();


  if(!TriggerStatus)

   {

    SoundRadius=64;
    SoundVolume=190;

   }

}

function Trigger( actor Other, pawn EventInstigator )  //Trigger properties - adds trigger code to make it switch on/off

{

 local Actor A;

 local Pawn P;

 local Decoration D;

 local TriggerAmbientSound oldself;

 oldself=self;

//
//  If the TriggerAmbientSound is set to OFF at the start, the trigger can turn it on, and back to off, and back and forth
//  If the TriggerAmbientSound is set to ON at the start, the trigger will turn it off, and back to on, and back and forth
//

 if(TriggerStatus)

 {

  TriggerStatus=false;  //TriggerAmbientSound is switched off

    SoundRadius=0;
    SoundVolume=0;
    ambientsound=none;
    
   }
else
{

  TriggerStatus=true;  //TriggerAmbientSound is switched on

    SoundRadius=TriggSoundRadius;  //Radius property
    SoundVolume=TriggSoundVolume;  //Volume property
    AmbientSound=TriggAmbientSound;  //Sound import property

   }

    

}

defaultproperties
{
}

It is currently untested, but I'll see if it works in game and in the ed atm.

@Wormbo If you see something wrong, just pinpoint me what to add/delete/mess around with with the code you have modified. :)

Edit1: I am still not done the code btw, still need to add a few more properties. ;) :)

Edit2: The "PostBeginPlay" with sound pitch and sound volume I forgot to remove. xD Fixed! :)

Edit3: Ok, realizing that I need it for something, I put it back in. xD Seems I need to slow down ;) :(
 
Last edited:

Raven

Member
Jan 17, 2004
147
0
16
40
turniej.unreal.pl
I think it'll be enough to manipulate AmbientSound variable. If AmbientSound is none then sound will not be played. Also you can delete unused local variables. Here's your code after few changes:

Code:
var() bool TriggerStatus;  //Status of the switch: True=On while False=Off
var sound AmbSnd;  //backup

function PostBeginPlay()
{
	Super.PostBeginPlay();
	AmbSnd=AmbientSound;
	//turn it off
	if(!TriggerStatus)
		AmbientSound=none;
}
function Trigger( actor Other, pawn EventInstigator )  //Trigger properties - adds trigger code to make it switch on/off
{
	if(TriggerStatus)
	{
		TriggerStatus=false;  //TriggerAmbientSound is switched off
		AmbientSound=none;
	}
	else
	{
		TriggerStatus=true;  //TriggerAmbientSound is switched on
		AmbientSound=AmbSnd;  //Sound import property
	}
}
 

RoninMastaFX

Unreal/UT Vet from Day 1
@Raven thanks m8! :)

On my own side, I worked up this code. It is almost final, but I would liek to try and "rename" True/False to On/Off.

Here's the code:

Code:
//==============================================================================================================
// TriggerAmbientSound
// This class allows you to make your AmbientSound "triggerable" using the normal trigger method
// Created by Mitchell "[~]RUFX[~]RoninMastaFX" LeBlanc with the help of BlackCheetah
// Code is based from TriggerWaterZone, created by Scott 'Slasher IV' Kircher, couldn't have done it without him
//==============================================================================================================

class TriggerAmbientSound extends AmbientSound;

var(TriggerSound) sound TRAmbientSound;  //Import your triggered sound here
var(TriggerSound) bool PowerStatus;  //Status of the switch: True=On while False=Off
var(TriggerSound) byte TRSoundPitch,TRSoundVolume,TRSoundRadius;  //The main batch of new sound properties
var(TriggerSound) float TRTransientSoundVolume;  //Transient sound volume property
var(TriggerSound) float TRTransientSoundRadius;  //Transient sound radius property

//
//  NOTE:  The TriggerAmbientSound uses a totally new sound system...however, the old AmbientSound properties
//  are still included, just in case. However, for triggered sounds, use the TriggerAmbientSound menu
//

function PostBeginPlay()

{

 Super.PostBeginPlay();


  if(!PowerStatus)  //What the trigger will turn off if false, or on if true

   {

    SoundRadius=64;
    SoundVolume=190;

   }

}

function Trigger( actor Other, pawn EventInstigator )  //Trigger properties - adds trigger code to make it switch on/off

{

 local Actor A;

 local Pawn P;

 local Decoration D;

 local TriggerAmbientSound oldself;

 oldself=self;

//
//  If the TriggerAmbientSound is set to OFF at the start, the trigger can turn it on, and back to off, and back and forth
//  If the TriggerAmbientSound is set to ON at the start, the trigger will turn it off, and back to on, and back and forth
//

 if(PowerStatus)  //Setting the rules for the triggering

 {

  PowerStatus=false;  //TriggerAmbientSound is switched off

    SoundRadius=0;
    SoundVolume=0;
    AmbientSound=none;

   }
else
{

  PowerStatus=true;  //TriggerAmbientSound is switched on

    TransientSoundRadius=TRTransientSoundRadius;  //Transient radius property
    TransientSoundVolume=TRTransientSoundVolume;  //Transient volume property
    SoundPitch=TRSoundPitch;  //Pitch property
    SoundRadius=TRSoundRadius;  //Radius property
    SoundVolume=TRSoundVolume;  //Volume property
    AmbientSound=TRAmbientSound;  //Sound import property

   }

    

}

defaultproperties
{
    TRSoundRadius=64
    TRSoundVolume=190
    TRSoundPitch=64
    TRTransientSoundVolume=1.00
}
 

Zur

surrealistic mad cow
Jul 8, 2002
11,708
8
38
48
How does a trigger work ? I've never messed around with the Actors mappers use.
 

Wormbo

Administrator
Staff member
Jun 4, 2001
5,913
36
48
Germany
www.koehler-homepage.de
A trigger just issues trigger events when touching it. You might wish to make sure the trigger actor doesn't double-trigger the ambient sound actor by adding a short re-trigger delay > 0. Sometimes several touches happen in quick succession even though you just walked into the trigger.
 

RoninMastaFX

Unreal/UT Vet from Day 1
The trigger that I am doing is run by dispatchers, SpecialEvents and Triggers. (For a special map that I'm making :) ) It is completely run by pressing a switch. There shouldn't be any settings upon touching the trigger, but I'll go check it out. ;) :)

Edit1: It does work now. :) There was a problem with a few stuff that prevented it, and all is good now. Turns out that this version by Raven is good enough after all. :D Thanks everyone! :)

Edit2: A download link for the AmbientSoundTrigger can be found in this post. :)
 

Attachments

  • TriggerAmbientSound.zip
    1.3 KB · Views: 14
Last edited:
Status
Not open for further replies.