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


Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do I let a sound play ONLY inside an area?
Melvin Offline
Member

Posts: 245
Threads: 38
Joined: Jun 2012
Reputation: 5
#1
How do I let a sound play ONLY inside an area?

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?

[Image: 25F7U37.png]
(This post was last modified: 09-24-2012, 09:56 PM by Melvin.)
09-24-2012, 08:01 PM
Website Find
i3670 Offline
Posting Freak

Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation: 36
#2
RE: How do I let a sound play ONLY inside an area?

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.

"What you think is irrelevant" - A character of our time

A Christmas Hunt
(This post was last modified: 09-24-2012, 08:20 PM by i3670.)
09-24-2012, 08:18 PM
Find
Statyk Offline
Schrödinger's Mod

Posts: 4,390
Threads: 72
Joined: Sep 2011
Reputation: 241
#3
RE: How do I let a sound play ONLY inside an area?

Try this:

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
(This post was last modified: 09-24-2012, 08:20 PM by Statyk.)
09-24-2012, 08:20 PM
Find
i3670 Offline
Posting Freak

Posts: 1,308
Threads: 74
Joined: Oct 2011
Reputation: 36
#4
RE: How do I let a sound play ONLY inside an area?

(09-24-2012, 08:20 PM)Statyk Wrote: Try this:

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.

"What you think is irrelevant" - A character of our time

A Christmas Hunt
09-24-2012, 08:21 PM
Find
Your Computer Offline
SCAN ME!

Posts: 3,456
Threads: 32
Joined: Jul 2011
Reputation: 235
#5
RE: How do I let a sound play ONLY inside an area?

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.

Tutorials: From Noob to Pro
09-24-2012, 08:26 PM
Website Find
Melvin Offline
Member

Posts: 245
Threads: 38
Joined: Jun 2012
Reputation: 5
#6
RE: How do I let a sound play ONLY inside an area?

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)

[Image: 25F7U37.png]
(This post was last modified: 09-24-2012, 08:36 PM by Melvin.)
09-24-2012, 08:35 PM
Website Find




Users browsing this thread: 3 Guest(s)