Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ambient Music/Sound Fix
RaideX Offline
Member

Posts: 212
Threads: 33
Joined: May 2013
Reputation: 7
#1
Ambient Music/Sound Fix

So, why hello there dear Amnesia Community. Up ahead will probably be a somewhat long post for a probably not so huge problem. Though i want to be sure let you guys know what i'm doing and how i'm doing it.

So basically i'm using an ambient music technique where i have different script areas that play different types of music depending on the surrounding architecture. The code looks, in short, something likes this:

PHP Code: (Select All)
//AMBIENCE COLLIDE CALLBACKS
AddEntityCollideCallback("Player""AmbientScriptArea""AmbienceHandler"false0)

//HANDLER
void AmbienceHandler (string &in asParentstring &in asChildint alState) {
   if (
asChild == "AmbientScriptArea") {
      if (
alState == 1) {
         
PlaySoundAtEntity("Ambience01""amb_xx_xx.snt""Player"1.0ftrue) }
      if (
alState == 1) {
         
StopSound("Ambience01"1.0f) }
   }


With this method the ambient sound can easily be changed with different script areas. Though i ran into problems when it comes to shaped rooms that are not quadrangular. The way I've done it was that i just set one script area up so that it covers the blank areas (because the music would stop otherwise) and let it play the same sound/music again. I've put together a little picture to demonstrate it a little better.

The point marked with an X is the problem zone. If the player switches or passes this point the ambient music changes and starts over from the start again. It's either a whole other setup of code or i'm just being too fussy about this because it is easily overheard. Though i'd like to discuss it here and see if someone is willing to help me out here Smile. Thanks in advance.

If you don't draw first, you don't get to draw at all... -The False Shepherd
(This post was last modified: 02-05-2014, 06:11 PM by RaideX.)
02-05-2014, 06:08 PM
Find
DreamScripters Offline
Junior Member

Posts: 25
Threads: 4
Joined: Dec 2013
Reputation: 0
#2
RE: Ambient Music/Sound Fix

Ok, so what I got from your post (correct me if i'm wrong) is that there are two script areas that will play the same ambience but when you enter said one of them while the same music is playing it will start over? If this is the case all I beleive you would have to do is set up a conditional statement that will check if the same ambeince is already playing. Sinse there is no way to be able to get the music playing you will have to get creative and use intigers.

So, how we could accomplish this is that we would take all of the script areas that have your problem and make it so it adds 1 to a intiger (considering it isn't already 1) that you would have already defined. And then when walking into an area that plays the same ambeince that is already playing you could make it so that if your intiger is equal to one it won't start the ambeince. And then just make it so when you go into any other script area it will set it back to 0.

Sorry if my reply looks like gibberish to you. Tongue I am very tired. But if this doesn't make sense I can explain it more with the actual script as a reference. Good luck!

[Image: header.png]
02-06-2014, 05:27 AM
Website Find
RaideX Offline
Member

Posts: 212
Threads: 33
Joined: May 2013
Reputation: 7
#3
RE: Ambient Music/Sound Fix

(02-06-2014, 05:27 AM)DreamScripters Wrote: Ok, so what I got from your post (correct me if i'm wrong) is that there are two script areas that will play the same ambience but when you enter said one of them while the same music is playing it will start over? If this is the case all I beleive you would have to do is set up a conditional statement that will check if the same ambeince is already playing. Sinse there is no way to be able to get the music playing you will have to get creative and use intigers.

So, how we could accomplish this is that we would take all of the script areas that have your problem and make it so it adds 1 to a intiger (considering it isn't already 1) that you would have already defined. And then when walking into an area that plays the same ambeince that is already playing you could make it so that if your intiger is equal to one it won't start the ambeince. And then just make it so when you go into any other script area it will set it back to 0.

Sorry if my reply looks like gibberish to you. Tongue I am very tired. But if this doesn't make sense I can explain it more with the actual script as a reference. Good luck!

alright, you got my point.

I'll try to work on it when i have some time and get back to you when i run into any problems or when i finish it. Thanks for the answer Smile

If you don't draw first, you don't get to draw at all... -The False Shepherd
(This post was last modified: 02-06-2014, 07:38 AM by RaideX.)
02-06-2014, 07:38 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#4
RE: Ambient Music/Sound Fix

If you call a song that it's currently playing, it ignores the call and keeps playing the song.
So in your case of two areas that the player may go from one to the other, the song wouldn't stop cause he entered one of the areas, it finds it's the same and keeps playing.

This only applies to music, so you should use PlayMusic function instead of PlaySound:
PlayMusic( "my_theme_001.ogg", false, 0.1f, 1.0f, 0, true );
Spoiler below!
PlayMusic( file, loop?, volume, fade, priority, resume? );

If a given set of areas play a different theme each, when the player steps into one, it's gonna stop the current song and start another.

In your function AmbienceHandler you can have this:
Spoiler below!

PHP Code: (Select All)
void AmbienceHandler string &in pstring &in asAreaint s )
{
 
string myTheme "";

     if ( 
asArea == "AmbientScriptKitchen" ) { myTheme == "theme_kitchen.ogg"; }
     if ( 
asArea == "AmbientScriptOutside" ) { myTheme == "theme_outside.ogg"; }
     if ( 
asArea == "AmbientScriptGallery" ) { myTheme == "theme_gallery.ogg"; }

PlayMusicmyThemefalse0.1f1.0f0true ); 



This way you can point all your ambient callbacks to the same function AmbienceHandler and just add a condition to change the name of the file.

02-06-2014, 08:16 PM
Find
RaideX Offline
Member

Posts: 212
Threads: 33
Joined: May 2013
Reputation: 7
#5
RE: Ambient Music/Sound Fix

(02-06-2014, 08:16 PM)Amn Wrote: If you call a song that it's currently playing, it ignores the call and keeps playing the song.
So in your case of two areas that the player may go from one to the other, the song wouldn't stop cause he entered one of the areas, it finds it's the same and keeps playing.

This only applies to music, so you should use PlayMusic function instead of PlaySound:
PlayMusic( "my_theme_001.ogg", false, 0.1f, 1.0f, 0, true );
Spoiler below!
PlayMusic( file, loop?, volume, fade, priority, resume? );

If a given set of areas play a different theme each, when the player steps into one, it's gonna stop the current song and start another.

In your function AmbienceHandler you can have this:
Spoiler below!

PHP Code: (Select All)
void AmbienceHandler string &in pstring &in asAreaint s )
{
 
string myTheme "";

     if ( 
asArea == "AmbientScriptKitchen" ) { myTheme == "theme_kitchen.ogg"; }
     if ( 
asArea == "AmbientScriptOutside" ) { myTheme == "theme_outside.ogg"; }
     if ( 
asArea == "AmbientScriptGallery" ) { myTheme == "theme_gallery.ogg"; }

PlayMusicmyThemefalse0.1f1.0f0true ); 



This way you can point all your ambient callbacks to the same function AmbienceHandler and just add a condition to change the name of the file.

Very nice explanation. Though this solution implies that i don't use anything else Music wise. I'll see what i'm gonna use in the final script file. Thanks anyway Smile Appreciate it.

If you don't draw first, you don't get to draw at all... -The False Shepherd
02-06-2014, 09:45 PM
Find
MyRedNeptune Offline
Senior Member

Posts: 553
Threads: 3
Joined: May 2012
Reputation: 33
#6
RE: Ambient Music/Sound Fix

(02-05-2014, 06:08 PM)RaideX Wrote:
PHP Code: (Select All)
if (alState == 1) {
         
StopSound("Ambience01"1.0f) }
   } 

I'm sure this is supposed to be:

PHP Code: (Select All)
if (alState == -1) {
         
StopSound("Ambience01"1.0f) }
   } 

?


Anyway, if I understood correctly every script area calls the same AmbienceHandler function?

If yes, you can try giving a number value to each area depending on what music it needs to trigger. It'll be assigned to a variable when an area is entered. The sound functions will not be called if the value of the int matches the value assigned to the area. The two areas that play the same ambience will have the same value.

PHP Code: (Select All)
int ambienceType 0;

AddEntityCollideCallback("Player""AmbientScriptAreaBlue1""AmbienceHandler"false0);

void AmbienceHandler (string &in asParentstring &in asChildint alState) {
   if (
asChild == "AmbientScriptAreaBlue1") {
      if (
ambienceType == 1) {
         return;
      }
      else {
         if (
alState == 1) {
            
ambienceType 1;
            
PlaySoundAtEntity("Ambience01""amb_xx_xx.snt""Player"1.0ftrue
         }
         if (
alState == -1) {
            
StopSound("Ambience01"1.0f
         }
      }
   }


^(;,;)^
02-06-2014, 09:59 PM
Find
RaideX Offline
Member

Posts: 212
Threads: 33
Joined: May 2013
Reputation: 7
#7
RE: Ambient Music/Sound Fix

(02-06-2014, 09:59 PM)MyRedNeptune Wrote:
(02-05-2014, 06:08 PM)RaideX Wrote:
PHP Code: (Select All)
if (alState == 1) {
         
StopSound("Ambience01"1.0f) }
   } 

I'm sure this is supposed to be:

PHP Code: (Select All)
if (alState == -1) {
         
StopSound("Ambience01"1.0f) }
   } 

?


Anyway, if I understood correctly every script area calls the same AmbienceHandler function?

If yes, you can try giving a number value to each area depending on what music it needs to trigger. It'll be assigned to a variable when an area is entered. The sound functions will not be called if the value of the int matches the value assigned to the area. The two areas that play the same ambience will have the same value.

PHP Code: (Select All)
int ambienceType 0;

AddEntityCollideCallback("Player""AmbientScriptAreaBlue1""AmbienceHandler"false0);

void AmbienceHandler (string &in asParentstring &in asChildint alState) {
   if (
asChild == "AmbientScriptAreaBlue1") {
      if (
ambienceType == 1) {
         return;
      }
      else {
         if (
alState == 1) {
            
ambienceType 1;
            
PlaySoundAtEntity("Ambience01""amb_xx_xx.snt""Player"1.0ftrue
         }
         if (
alState == -1) {
            
StopSound("Ambience01"1.0f
         }
      }
   }


Yes it's suppost to be -1, my bad. I've implemented the version you described, works pretty good. I still need to test it out a bit, will get back to it once i'm concerned that it doesnt work anymore Tongue Thanks.

If you don't draw first, you don't get to draw at all... -The False Shepherd
02-07-2014, 01:41 PM
Find




Users browsing this thread: 1 Guest(s)