Frictional Games Forum (read-only)
Script - Piano Music - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Script - Piano Music (/thread-40661.html)

Pages: 1 2 3


Script - Piano Music - Abihishi - 02-26-2016

Hi Guys! Big Grin

How make script, when my character touch scriptarea, it music start play, and
will come from the piano.

Bye, and thanks for all help tips.


RE: Script - Piano Music - Spelos - 02-26-2016

All you will actually need is a Script Area.
Remember the name of that Script Area.

PHP Code:
void OnStart()
{
    
// It is a good practice to pre-load your .snt sounds before you use it.
    
PreloadSound("general_piano01.snt");
    
    
SetEntityPlayerInteractCallback("NameOfArea""PianoFunc"false);
}

void PianoFunc(string &in asEntity)
{
    
StopSound("PianoSound"0.5f); //Prevents it from playing twice when spamming.
    
PlaySoundAtEntity("PianoSound""general_piano01.snt""NameOfArea"0.5ffalse);


But don't forget to edit it to fit your situation.
NameOfArea should be the name of your area (and there are 2 of them in the script)
The music is from Amnesia and has this fade effect. To remove that use your own music.
If using your own music you will have to create your own .snt file.
Just open an existing .snt file in notepad and copy its content and edit it to apply to your music file.

If something is not clear you could check the
Amnesia Bible


RE: Script - Piano Music - Abihishi - 02-26-2016

I see error when i start my CS. With read i see, that problem is 11 ruler:

SetEntityPlayerInteractCallback("ScriptArea_011", "PianoFunc", false);


ScriptArea name is same in file and editor.


RE: Script - Piano Music - Spelos - 02-26-2016

I just tried the script and the problem is not in my script, it must be your implementation.

Keep in mind that:
  • Only one void OnStart() can be in your file
  • void PianoFunc(string &in asEntity) needs to be OUT of OnStart()
  • All functions need to be enclosed with { and }
  • SetEntityPlayerInteractCallback needs to be within a function, preferably OnStart

Be careful when merging my code with your own.

And post the full error message if possible.


RE: Script - Piano Music - Abihishi - 02-27-2016

All points checked and not found error.

FATAL ERROR: Could not load script file 'custom_stories/TheWitness/maps/00_witness.hps'!
main (11,2) :ERR : Expected ';'


RE: Script - Piano Music - Spelos - 02-27-2016

That error means that you are missing a ";" on your 11th line or near it. (might be a line before it)

Remember that every command in every function needs to end with semicolon.
PHP Code:
void OnStart() // <-- This is a function, no ";" here.
{
    
Command(); 
    
Command();
    
Command();
    
Command(); // <-- This is a command, ";" has to be here!
    
Command();


If you don't find the missing semicolon, you can copy the code from my previous answer and paste it into your .hps file. Then you can add all your functions, but be careful about their syntax, since the same rules apply.


RE: Script - Piano Music - Abihishi - 02-27-2016

Thanks


RE: Script - Piano Music - Abihishi - 02-27-2016

But how stop music in intro? Big Grin

I have this in OnStart:
PlayMusic("00_event_gallery.snt", true, 1, 0.1, 10, false);

and this:
void StopMusic(15, int alPrio);
{

}
But i dont know what type


RE: Script - Piano Music - Spelos - 02-27-2016

Spelos Wrote:
Oh no!

While StopMusic is a function, YOU do not create that function. It is already declared in Amnesia.

You should just call the function instead.
Calling a function is a command.
You put the name of the function and fill its parameters.

For void StopMusic(float afFadeTime, int alPrio); the call command would be:
PHP Code:
void OnStart()
{
    
StopMusic(1.0f10); // And you do this command in a function that happens at the time you want the music to stop.


the "1.0f" in the example is the time (in seconds) it takes to fade out the music.

And the "10" in the example is the priority of the music that will stop. You set the priority in the PlayMusic command:
Abihishi Wrote:PlayMusic("00_event_gallery.snt", true, 1, 0.1, 10, false);



And again... Even if you were to declare it as a function... (Which won't do anything, since it's not called & has nothing in it)

void StopMusic(15, int alPrio); <-- WHAT IS THIS, MAN?!
{

}

again, that is function. Functions DO NOT have semicolons!
Commands DO have semicolons.

PHP Code:
void OnStart() // <-- This is a function, no ";" here.
{
    
Command(); // <-- This is a command, ";" has to be here!


Try to keep it in mind.


RE: Script - Piano Music - Abihishi - 02-27-2016

void OnStart()
{
PlayMusic("00_event_gallery", true, 1, 0.1, 10, false);
StopMusic(1.0f, 1);
}

not work, and piano music too ;P