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


Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with sounds!
Cgturner Offline
Junior Member

Posts: 28
Threads: 7
Joined: Sep 2010
Reputation: 0
#1
Help with sounds!

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.
09-16-2010, 07:42 PM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#2
RE: Help with sounds!

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

Example:
//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);
}

[Image: 16455.png]
09-16-2010, 07:54 PM
Find
Armored Cow Offline
Member

Posts: 72
Threads: 3
Joined: Sep 2010
Reputation: 0
#3
RE: Help with sounds!

I actually just did your first request.

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
(This post was last modified: 09-16-2010, 08:01 PM by Armored Cow.)
09-16-2010, 08:01 PM
Find
Cgturner Offline
Junior Member

Posts: 28
Threads: 7
Joined: Sep 2010
Reputation: 0
#4
RE: Help with sounds!

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.
(This post was last modified: 09-16-2010, 08:18 PM by Cgturner.)
09-16-2010, 08:18 PM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#5
RE: Help with sounds!

(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);
}

[Image: 16455.png]
09-16-2010, 08:19 PM
Find
Cgturner Offline
Junior Member

Posts: 28
Threads: 7
Joined: Sep 2010
Reputation: 0
#6
RE: Help with sounds!

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?

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);
}
09-17-2010, 01:00 AM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#7
RE: Help with sounds!

(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

[Image: 16455.png]
09-17-2010, 01:07 AM
Find
Cgturner Offline
Junior Member

Posts: 28
Threads: 7
Joined: Sep 2010
Reputation: 0
#8
RE: Help with sounds!

(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?
09-17-2010, 01:18 AM
Find
MulleDK19 Offline
Senior Member

Posts: 545
Threads: 21
Joined: Jun 2009
Reputation: 10
#9
RE: Help with sounds!

(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.

[Image: 16455.png]
09-17-2010, 01:31 AM
Find
Cgturner Offline
Junior Member

Posts: 28
Threads: 7
Joined: Sep 2010
Reputation: 0
#10
RE: Help with sounds!

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.
09-17-2010, 01:45 AM
Find




Users browsing this thread: 1 Guest(s)