Frictional Games Forum (read-only)
Help with sounds! - 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: Help with sounds! (/thread-4438.html)

Pages: 1 2 3


Help with sounds! - Cgturner - 09-16-2010

I have no experience with scripting, but am still curious about how to make a specific sound (let's say, "11_animal_squeal.snt") play once you enter a certain script area. Also, I have a map started, and I want to play the "05_wall_scratch.snt" sound once the lantern is picked up off of a table I have set. Any information on either of these would be greatly appreciated.


RE: Help with sounds! - MulleDK19 - 09-16-2010

In your script in the function called OnStart() you add callbacks.

Example:
Code:
//This function is called the first time the map is loaded
void OnStart()
{
    //Add a collision callback between the Player and the area called MyArea
    AddEntityCollideCallback("Player", "MyArea", "CollideMyArea", true, 1);
    
    //Add a interaction callback for the lantern called lantern_1
    SetEntityPlayerInteractCallback("lantern_1", "LanternTaken", true);
}

/**
* This function is called when the Player collides with the area called MyArea,
* because we added a collision callback.
**/
void CollideMyArea(string &in asParent, string &in asChild, int alState)
{
    //Play sound at player
    PlaySoundAtEntity("", "11_animal_squeal", "Player", 0, false);
}


/**
* This function is called when the Player interacts with the lantern called lantern_1
* because we added an interaction callback.
**/
void LanternTaken(string &in asEntity)
{
    //Play sound at player
    PlaySoundAtEntity("", "05_wall_scratch", "Player", 0, false);
}



RE: Help with sounds! - Armored Cow - 09-16-2010

I actually just did your first request.

Code:
void OnStart()
{
//Add callback for area_squeal (This is the name of your area.  It can be anything you want)
AddEntityCollideCallback("Player", "area_squeal", "CollideSqueal", true, 0);
}

void CollideSqueal(string &in asParent, string &in asChild, int alState);
{
PlaySoundAtEntity("animal_squeal", "11_animal_squeal.snt", "Player", 0, false);
}

This is assuming you've already opened a map_name.hsp.

The first section must go under void OnStart()

The second section must go in any area that is not OnStart, OnEnter or OnLeave.[hr]
I actually just did your first request.

[code]
void OnStart()
{
//Add callback for area_squeal (This is the name of your area.  It can be anything you want)
AddEntityCollideCallback("Player", "area_squeal", "CollideSqueal", true, 0);
}

void CollideSqueal(string &in asParent, string &in asChild, int alState);
{
PlaySoundAtEntity("animal_squeal", "11_animal_squeal.snt", "Player", 0, false);
}
This is assuming you've already opened a map_name.hsp.

The first section must go under void OnStart()

The second section must go in any area that is not OnStart, OnEnter or OnLeave.

EDIT: I was beaten Tongue


RE: Help with sounds! - Cgturner - 09-16-2010

Alright, I entered the functions as you displayed them, but I get an error upon launching Amnesia. Here's my script file:

void OnStart()

{
AddUseItemCallback("useexit", "PrisonKey", "PrisonDoor",
"UseKey", true);
}

void UseKey(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);

RemoveItem(asItem);
}

{
AddEntityCollideCallback("Player", "MyArea", "CollideMyArea", true, 1);

SetEntityPlayerInteractCallback("lantern_1", "LanternTaken", true);
}

void CollideMyArea(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("ScriptArea_1", "11_animal_squeal", "Player", 0, false);
}

void LanternTaken(string &in asEntity)
{
PlaySoundAtEntity("ScriptArea_1", "05_wall_scratch", "Player", 0, false);
}

I get a ""FATAL ERROR" and it shows that at (15,1) there is an "unexpected token'{'". The key script works fine as is, I've tested it, but am I doing something obviously wrong with the scripts you gave?
Sorry, I didn't post the code in a box. :/ I'd like to know how to do that as well.


RE: Help with sounds! - MulleDK19 - 09-16-2010

(09-16-2010, 08:18 PM)Cgturner Wrote: I get a ""FATAL ERROR" and it shows that at (15,1) there is an "unexpected token'{'". The key script works fine as is, I've tested it, but am I doing something obviously wrong with the scripts you gave?
Sorry, I didn't post the code in a box. :/ I'd like to know how to do that as well.

You have some code that isn't in a function

{
AddEntityCollideCallback("Player", "MyArea", "CollideMyArea", true, 1);

SetEntityPlayerInteractCallback("lantern_1", "LanternTaken", true);
}


RE: Help with sounds! - Cgturner - 09-17-2010

MulleDK19, I've added the Callbacks, and the map runs smoothly, and the sound after picking up the lantern works perfectly, but the "animal_squeal.snt" sound only plays every few times I run the map. Here's the script, do you see anything that would cause this to happen?

Code:
void OnStart()

{
    PlaySoundAtEntity("bang", "10_close_door", "Player", 0, false);
    
    AddEntityCollideCallback("Player", "area_squeal", "Collidearea_squeal", true, 1);
    
    SetEntityPlayerInteractCallback("lantern_1", "LanternTaken", true);
    
    AddUseItemCallback("useexit", "PrisonKey", "PrisonDoor", "UseKey", true);
}    

void UseKey(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked(asEntity, false, true);

    RemoveItem(asItem);
}

void Collidearea_squeal(string &in asParent, string &in asChild, int alState)
{
    PlaySoundAtEntity("animal_squeal", "11_animal_squeal.snt", "Player", 0, false);
}

void LanternTaken(string &in asEntity)
{
    PlaySoundAtEntity("scratch", "05_wall_scratch", "Player", 0, false);
}



RE: Help with sounds! - MulleDK19 - 09-17-2010

(09-17-2010, 01:00 AM)Cgturner Wrote: MulleDK19, I've added the Callbacks, and the map runs smoothly, and the sound after picking up the lantern works perfectly, but the "animal_squeal.snt" sound only plays every few times I run the map.

That is because 11_animal_squeal.snt has Random set to 0.1

Use this instead: scare_animal_squeal.snt


RE: Help with sounds! - Cgturner - 09-17-2010

(09-17-2010, 01:07 AM)MulleDK19 Wrote:
(09-17-2010, 01:00 AM)Cgturner Wrote: MulleDK19, I've added the Callbacks, and the map runs smoothly, and the sound after picking up the lantern works perfectly, but the "animal_squeal.snt" sound only plays every few times I run the map.

That is because 11_animal_squeal.snt has Random set to 0.1

Use this instead: scare_animal_squeal.snt

You, my friend, are a genius. This works flawlessly. I do have one more question at the moment. Would it be possible to edit the 11_animal_squeal.snt file and change the Random to 0.0?

P.S. Thanks for the great advice.
EDIT: I discovered that you CAN edit it so that there is no randomness, but will that cause one sound out of the pool of sounds to be played everytime, or will it just go in order, then loop?


RE: Help with sounds! - MulleDK19 - 09-17-2010

(09-17-2010, 01:18 AM)Cgturner Wrote:
(09-17-2010, 01:07 AM)MulleDK19 Wrote:
(09-17-2010, 01:00 AM)Cgturner Wrote: MulleDK19, I've added the Callbacks, and the map runs smoothly, and the sound after picking up the lantern works perfectly, but the "animal_squeal.snt" sound only plays every few times I run the map.

That is because 11_animal_squeal.snt has Random set to 0.1

Use this instead: scare_animal_squeal.snt

You, my friend, are a genius. This works flawlessly. I do have one more question at the moment. Would it be possible to edit the 11_animal_squeal.snt file and change the Random to 0.0?

P.S. Thanks for the great advice.
EDIT: I discovered that you CAN edit it so that there is no randomness, but will that cause one sound out of the pool of sounds to be played everytime, or will it just go in order, then loop?


Random sounds are always chosen from the pool.

The Random setting is rather "Probability of occurance". 1 means that the sound will always be played when it's triggered using eg. PlaySoundAtEntity, while 0 means it would never be played.

From what I've understood by just looking at the .snt files, at least.


RE: Help with sounds! - Cgturner - 09-17-2010

Ah, that makes sense! Sorry for all of the questions, but this is the first scripting I've ever done. Ever. I just made a custom .snt file with all of the squeals together, and the Random at 1.0 so that a sound always plays when you walk over the script area. Thanks for all of the help! If I have any other script-related problems, I hope it's alright to come back to you. You've helped a lot more that anything else.