Frictional Games Forum (read-only)

Full Version: How do I let a sound play ONLY inside an area?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I've been looking for an answer around the internet, but unfortunately without any succes.

So this is what I want to do:
You hear a sound playing (ambience) and when you walk into an abondoned looking house, the ambience suddenly changes. then when you walk out of the house, the ambience changes back to the ambience that it was before.

I've tried setting an area with StopSound(''Soundfile'', 0); at the entrance of the house. But it doesn't seem to work. I'll post the script here. (This is a map that I just started.)




////////////////////////////
// Run first time starting map
void OnStart()
{
}


void OnEnter()
{
PlaySoundAtEntity("", "07_amb_breath.snt", "Player", 1, true);
AddEntityCollideCallback("Player", "HouseAmbience", "Kaas", false, 1);
AddEntityCollideCallback("Player", "stopmusicamb", "stophammertime", true, 0);
}

void Kaas(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "00_loop.snt", "Player", 1, true);
}


void stophammertime(string &in asParent, string &in asChild, int alState)
{
StopSound("00_loop.snt", 0);
}



How do I do this?
AddEntityCollideCallback("Player", "AmbienceArea", "MyFunc", false, 0);

void MyFunc(string &in asParent, string &in asChild, int alState)
{
{
if (alState == 1)
{

}
if(alState == -1)
{


}
}
}

When he enters, 1, one type of sounds played and when he leaves, -1 another sound is played.

EDIT: This however does require that you cover the entire area with a single script area.
Try this:

Code:
void OnStart()
{
    PlaySoundAtEntity("", "07_amb_breath.snt", "Player", 1, true);
    AddEntityCollideCallback("Player", "HouseAmbience", "Kaas", false, 0);
}

void Kaas(string &in asParent, string &in asChild, int alState)
{
    if(alState == 1) //entering the house ScriptArea
    {
        PlaySoundAtEntity("houseamb", "00_loop.snt", "Player", 1, true);
    }
    if(alState == -1) //leaving the house ScriptArea
    {
        StopSound("houseamb", 0.5f);
//Add a line in here to add the music outside the house to play again
    }
}

Note: this is completely untested
(09-24-2012, 08:20 PM)Statyk Wrote: [ -> ]Try this:

Code:
void OnStart()
{
    PlaySoundAtEntity("", "07_amb_breath.snt", "Player", 1, true);
    AddEntityCollideCallback("Player", "HouseAmbience", "Kaas", false, 0);
}

void Kaas(string &in asParent, string &in asChild, int alState)
{
    if(alState == 1) //entering the house
    {
        PlaySoundAtEntity("houseamb", "00_loop.snt", "Player", 1, true);
    }
    if(alState == -1) //leaving the house
    {
        StopSound("houseamb", 0.5f);
//Add a line in here to add the music outside the house to play again
    }
}

Note: this is completely untested
I've done this a couple, three times and works like a charm.
FYI: The issue is that you didn't provide an internal name for the sound. Without it, you can't stop the sound. Notice how statyk's code has "houseamb" for the internal name.
Wow, guys I couldn't thank you enough!
You helped me with the script AND you helped me understanding it.


Reminds me why I love this forum, thanks.

(edited a typo)