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


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Make a sound play when you pick up a note
Iyiyt Offline
Junior Member

Posts: 13
Threads: 5
Joined: Jul 2012
Reputation: 0
#1
Make a sound play when you pick up a note

Hi. I'm kind of new at scripting things for Amnesia, but I've been doing okay so far thanks to the Frictional Wiki. However, I want to have a sound play when the player picks up a note and I can't figure out how to do that. I checked the Wiki and it didn't seem to have anything helpful. Can anyone tell me what to do? I would doubly appreciate it if you could just give me an outline so I can fill in the blanks myself with the sound files and such.

The only thing I could think of was something like "SetEntityPlayerInteractCallback("Note", "PlaySoundfile", true);.", but that didn't work.
(This post was last modified: 07-21-2012, 09:14 AM by Iyiyt.)
07-21-2012, 09:04 AM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#2
RE: Make a sound play when you pick up a note

void OnStart()
{
SetEntityCallbackFunc("NOTE_NAME", "FUNCTION_NAME", true);
}

void FUNCTION_NAME(string &in asEntity, string &in type)
{
PlaySoundAtEntity("", "soundfile.snt", "Player", 0, false);
//or for example
//PlayMusic("17_paper_herbert01.ogg", false, 0.6f, 0.5f, 10, false);
}
This should do the job.

[Image: 18694.png]
(This post was last modified: 07-21-2012, 11:23 AM by Ongka.)
07-21-2012, 11:23 AM
Find
ApeCake Offline
Member

Posts: 116
Threads: 20
Joined: Jun 2012
Reputation: 4
#3
RE: Make a sound play when you pick up a note

Or you can do it this way (I prefer this one):

Go to the "entity" tab of the note (in the level editor), in "PlayerInteractCallback" write something (in this case I will write playnotesound). Put this in your .hps.


void playnotesound(string &in entity)
{
//put your sound here, example below
PlayGuiSound("react_scare", 1.0f);
}

It basically the same as Ongkas one, but I prefer this way because you don't need void OnStart.
(This post was last modified: 07-21-2012, 07:25 PM by ApeCake.)
07-21-2012, 07:24 PM
Find
Ongka Offline
Member

Posts: 225
Threads: 3
Joined: Nov 2010
Reputation: 20
#4
RE: Make a sound play when you pick up a note

But you need void OnStart anyway, for all the other callbacks.
I do it the way you said also, but if someone doesn't know what to do and wants a specific script, it's easier to just write it in the script.

[Image: 18694.png]
07-21-2012, 07:29 PM
Find
Iyiyt Offline
Junior Member

Posts: 13
Threads: 5
Joined: Jul 2012
Reputation: 0
#5
RE: Make a sound play when you pick up a note

Sorry, I probably screwed something up, because it isn't working. Here's what my script says (I just started this);

///////////////////////////
//Run when entering map
void OnStart()
{
SetEntityPlayerInteractCallback("Chris", "SpawnGruntUno", true);
SetEntityCallbackFunc("Chris", "Commie", true);
}

void SpawnGruntUno(string &in asEntity)
{
SetEntityActive("GruntUno", true);
}

void Commie(string &in asEntity, string &in type)
{
PlaySoundAtEntity("", "amb_hunt.snt", "Player", 0, false);
}

Thanks for the speedy response, by the way. "Commie" is the name of the sound file I want to play (in the Level Editor). As you can probably tell, I'm really new to this. When I try to run it, it crashes and the fatal error says
"ERROR! Could not load script file blah blah blah!
main (6,1) :ERR : No matching signatures to 'SetEntitiyCallbackFunc(string@&, string@&, const bool)'"

On a side note, I tried it the other way too. I got hopeful when it didn't crash, but it just played the sound at the beginning, and not when I interacted with the note. Again, probably my fault. Here's the coding I used;
///////////////////////////
//Run when entering map
void OnStart()
{
SetEntityPlayerInteractCallback("Chris", "SpawnGruntUno", true);
}

void SpawnGruntUno(string &in asEntity)
{
SetEntityActive("GruntUno", true);
}

void playnotesound(string &in entity)
{
PlayGuiSound("Commie", 1.0f);
}
(This post was last modified: 07-22-2012, 06:37 AM by Iyiyt.)
07-22-2012, 04:35 AM
Find
Mackiiboy Offline
Member

Posts: 101
Threads: 7
Joined: Jan 2012
Reputation: 11
#6
RE: Make a sound play when you pick up a note

(07-22-2012, 04:35 AM)Iyiyt Wrote: Sorry, I probably screwed something up, because it isn't working. Here's what my script says (I just started this);

///////////////////////////
//Run when entering map
void OnStart()
{
SetEntityCallbackFunc("Chris", "Commie", true);
}

On a side note, I tried it the other way too. I got hopeful when it didn't crash, but it just played the sound at the beginning, and not when I interacted with the note. Again, probably my fault. Here's the coding I used;

///////////////////////////
//

void playnotesound(string &in entity)
{
PlayGuiSound("Commie", 1.0f);
}
.
I have marked everything red that I think you will have to change. SetEntityCallbackFunc does not have a
bool abRemoveOnInteraction, it just have string& asName and string& asCallback. So use this instead:

SetEntityCallbackFunc("Chris", "Commie");


The function "playnotesound" probably has the wrong callback syntax, as far as I remember, you should use:
(string &in entity, string &in type)
Try:

void playnotesound(string &in entity, string &in type)
{
PlayGuiSound("Commie", 1.0f);
}
(This post was last modified: 07-22-2012, 11:49 AM by Mackiiboy.)
07-22-2012, 11:47 AM
Website Find
Iyiyt Offline
Junior Member

Posts: 13
Threads: 5
Joined: Jul 2012
Reputation: 0
#7
RE: Make a sound play when you pick up a note

That still doesn't work. On the plus side, when I try to run my script it doesn't have a fatal error (hooray!), but it still just plays the sound when you spawn in, and doesn't when you click the note. Here's my current code
///////////////////////////
//Run when entering map
void OnStart()
{
SetEntityPlayerInteractCallback("Chris", "SpawnGruntUno", true);
SetEntityCallbackFunc("Chris", "Commie");
}

void SpawnGruntUno(string &in asEntity)
{
SetEntityActive("GruntUno", true);
}

void Commie(string &in asEntity, string &in type)
{
PlaySoundAtEntity("", "amb_hunt.snt", "Player", 0, false);
}

The other way, with the playnotesound, looks like this;
///////////////////////////
//Run when entering map
void OnStart()
{
SetEntityPlayerInteractCallback("Chris", "SpawnGruntUno", true);
}

void SpawnGruntUno(string &in asEntity)
{
SetEntityActive("GruntUno", true);
}

void playnotesound(string &in Entity, string& in type)
{
PlayGuiSound("Commie", 1.0f);
}
Thanks for all your help guys, but it still just isn't working. By the way, before you ask, yes I'm sure the names are accurate and that I put playnotesound (with no caps) in the function-thing text box.
(This post was last modified: 07-22-2012, 06:55 PM by Iyiyt.)
07-22-2012, 06:54 PM
Find
Cruzore Offline
Senior Member

Posts: 301
Threads: 2
Joined: Jun 2012
Reputation: 37
#8
RE: Make a sound play when you pick up a note

For the second one, make sure you used "CallbackFunc".
and at

void playnotesound(string &in Entity, string& in type)

string& in type is wrong, use this: string &in type

Also, why use 2 callbacks for 2 different functions, when it's the same entity? Doesn't make sense, and is probably why it doesn't work. If you ment to do that, I suggest using CallbackFunc to call a single function which has both the grunt activation and the sound.

And if that still doesn't work, try adding this inside your called function:
if(type == "OnPickup")
{
//stuff to do
}

Think, before you speak Google, before you post
(This post was last modified: 07-23-2012, 09:22 PM by Cruzore.)
07-23-2012, 09:09 PM
Find
Iyiyt Offline
Junior Member

Posts: 13
Threads: 5
Joined: Jul 2012
Reputation: 0
#9
RE: Make a sound play when you pick up a note

(07-23-2012, 09:09 PM)Cruzore Wrote: For the second one, make sure you used "CallbackFunc".
and at

void playnotesound(string &in Entity, string& in type)

string& in type is wrong, use this: string &in type

Also, why use 2 callbacks for 2 different functions, when it's the same entity? Doesn't make sense, and is probably why it doesn't work. If you meant to do that, I suggest using CallbackFunc to call a single function which has both the grunt activation and the sound.

And if that still doesn't work, try adding this inside your called function:
if(type == "OnPickup")
{
//stuff to do
}
I appreciate all of your help, everyone. When I finish my custom story (read as: IF I finish my custom story in the next decade), than I will definitely put you all in my credits. Not that anybody will ever see it or care. But still, it's the thought that counts. Anyway, what you^ said makes a lot of sense and sounds like it would work. But being both new at this and apparently a painfully slow learner, every way I tried it it didn't work. If anyone could just quickly type out the script (from the start) for me, it would be greatly appreciated. Then I can finally move on to the next part of the story, and probably get stuck there, too.

If it helps any, here's the code I got that I think was probably the closest to working. BUT IT STILL PLAYS THE %#$&*@ NOISE AT THE START OF THE LEVEL! Everything else works perfectly. Which reminds me, it might be the way I'm doing it. I have the actual sound file in the level editor, placed at the same coordinates as where the Grunt appears. It's set as inactive. When you click on the note, I'm trying to make it become active and play. If that's what's wrong, could you tell me? Or shout at me for being an idiot. Whatever. And then tell me the way I'm supposed to do it? Thanks. Oh! The code! Here it is;
///////////////////////////
//Run when entering map
void OnStart()
{
SetEntityPlayerInteractCallback("Chris", "play", true);
}

void play(string &in asEntity, string &in asType)
{
SetEntityActive("GruntUno", true);
PlayGuiSound("Commie", 1.0f);
}
(This post was last modified: 07-25-2012, 04:54 AM by Iyiyt.)
07-25-2012, 04:40 AM
Find
Iyiyt Offline
Junior Member

Posts: 13
Threads: 5
Joined: Jul 2012
Reputation: 0
#10
RE: Make a sound play when you pick up a note

Hey everybody! I was messing around with my script a little, and I stumbled upon a script that actually worked! This is what I did;
1. I deleted the sound "Commie" from my .MAP file.
2. I changed the name of the .snt file to "Commie.snt"
3. I had it say "PlayGuiSound("Commie.snt", 1.0f);
4. I turned SetEntityPlayerCallback to false.

And it worked! Now it plays the sound only when you pick up the note! Thanks for all your help. Consider this problem solved.

Oh, and in case you want to see, here is the code;
///////////////////////////
//Run when entering map
void OnStart()
{
SetEntityPlayerInteractCallback("Chris", "play", false);
}

void play(string &in asEntity, string &in asType)
{
SetEntityActive("GruntUno", true);
PlayGuiSound("Commie.snt", 1.0f);
}
(This post was last modified: 07-26-2012, 04:48 AM by Iyiyt.)
07-26-2012, 04:47 AM
Find




Users browsing this thread: 1 Guest(s)