Frictional Games Forum (read-only)
Sound Help - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Sound Help (/thread-4865.html)



Sound Help - Stangi - 10-01-2010

Hi, I'm completly new to scripting, and I'm having big troubles to get a sound playing when I enter a specific area. I have created an area in the editor and placed the sound where I want it. What script should I use to get it to work? And yes, I have looked through other threads about sound (and watched and read the tutorials), but after trying several scripts, I get none of them working. Sad

Can I get some help? And please, include as much information as possible.
Thanks Smile


RE: Sound Help - Placeable - 10-01-2010

Hey Stangi

I'll try and post a thorough explanation for you Smile

First if all your Area (Script) must have a name and instead of a sound object placed out you would place out a new Area (Script) and give it a name as well. This is where we want to play our sound from.

I'll call them myTrigger and SoundArea.

Then in your script (.hps) file for your area you would add the following line of code to check for 'collision/collide' with the area.

Code:
AddEntityCollideCallback("Player", "myTrigger", "PlaySound", true, 0);

Put it where you see fit, I'd recommend the OnStart() function for the area, depending on what you really want to do.

As you can see in the function's parameters we have "Player", that is the entity/object that will collide with the trigger; in this case simply the player.

Then we have "myTrigger", that is our trigger area which the object will collide with. Once this happens we will call on a function simply named PlaySound.

You have to define this function and it is here you'll play your sound. I'd do it like this:

Code:
void PlaySound(string &in asParent, string &in asChild, int alState)
{
    PlaySoundAtEntity("someSound", "general_rain_m.snt", "SoundArea", 0, true);    
}

This would give you a rain sound playing at the SoundArea.

Alternatively if you want to have a placed out sound, like you mentioned in your post, we could 'disable' this sound by checking off the 'Active' box in its properties. And when the player is entering the myTrigger area we could simply enable the sound with the following code:

Code:
SetEntityActive("specialSound", true);

In the PlaySound() function instead.

The sound you placed out would be called specialSound.

Hope this helps!


RE: Sound Help - Stangi - 10-01-2010

Thank you very much!

I got the "sound from a script area" working, but I couldn't get the SetEntityActive("specialSound", true); to work. I replaced the "specialsound" with the name of the sound, and set the sound to inactive.

By the way, are there any rules for what I should place in "OnStart()", "OnEnter()" and "OnLeave" and what I shouldn't place there? And what is the specific difference between "OnStart()" and "OnEnter()"?


RE: Sound Help - Placeable - 10-01-2010

Quote:I got the "sound from a script area" working, but I couldn't get the SetEntityActive("specialSound", true); to work. I replaced the "specialsound" with the name of the sound, and set the sound to inactive.

When using placed out sound make sure you have a large enough distance/radius for it so the player can actually hear it. And the sound plays somewhat randomly in different intervals from what I've experienced. This also seem to depend on the sound being used; though not entirely sure about this one.

So naturally the sound would not be heard instantly once you activate it by code.

I've never tried the SetEntityActive(...) for placed out sound objects though, so once again not entirely sure this would work.

Quote:By the way, are there any rules for what I should place in "OnStart()", "OnEnter()" and "OnLeave" and what I shouldn't place there? And what is the specific difference between "OnStart()" and "OnEnter()"

Well, basically its like this:

OnStart() is only called once throughout the whole game, the first time the player enters the area. This is good to setup certain things like one-shot events and whatnot.

OnEnter() is called every time the player enters the area. Say you want a specific music to be played in an area, then you would put this code here.

OnLeave() is the opposite, maybe you want to add something to the area when the player leaves it and when the player returns back later something new would be there. Never used this function since I find it to be somewhat useless; you could achieve whatever the same purpose with OnEnter, just checking a variable or something.

Actually, if anything it would be good to 'clean up' the area when the player leaves. Maybe remaining monsters (if they are not removed by default), particles, or if you want to reset something (doors, levers...).

That's about it.


RE: Sound Help - Stangi - 10-01-2010

Thanks, you're really helpfull Big Grin So, to conclude, it's better to use an area for a sound than the actual sound itself. I think I understand most of the basics now.

However, I've run into another problem. I have one room with no light and a door leading into another room, which is a bit more lit with a tint of green (BoxLight). The problem is, when opening the door to the other room, the door suddenly gets lit by the BoxLight. And it looks horrible. Is there any other way to evade this other than spinning the door so it opens the other way? Huh


RE: Sound Help - Placeable - 10-01-2010

Quote:Thanks, you're really helpfull. So, to conclude, it's better to use an area for a sound than the actual sound itself. I think I understand most of the basics now.

For scripting, yes. Depends on what you want to do. The sounds I place out are merely there for ambience, constant ones.

Quote:I have one room with no light and a door leading into another room, which is a bit more lit with a tint of green (BoxLight). The problem is, when opening the door to the other room, the door suddenly gets lit by the BoxLight. And it looks horrible. Is there any other way to evade this other than spinning the door so it opens the other way?

Nope, you have to live with it. Or fill the other room with the same box. Alternatively you can use Point Light for this to make it 'blend' into the door transition or whatnot. You can change the radius of the point light to fit your needs; if it's a relatively small room it shouldn't be a problem. Bigger maybe use several point lights.

Or if that is no good you could try and place a few box lights that goes through the door transition, each with a different more faded/weaker color than the original box light to give the appearance of a 'fade'.


RE: Sound Help - Stangi - 10-02-2010

Ok, thanks for all your help Big Grin