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 - Piano Music
Abihishi Offline
Junior Member

Posts: 44
Threads: 8
Joined: Feb 2016
Reputation: 0
#1
Script - Piano Music

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.
02-26-2016, 02:47 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#2
RE: Script - Piano Music

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

PHP Code: (Select All)
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
(This post was last modified: 02-26-2016, 03:33 PM by Spelos.)
02-26-2016, 03:09 PM
Find
Abihishi Offline
Junior Member

Posts: 44
Threads: 8
Joined: Feb 2016
Reputation: 0
#3
RE: Script - Piano Music

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.
02-26-2016, 04:47 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#4
RE: Script - Piano Music

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.
(This post was last modified: 02-26-2016, 05:53 PM by Spelos.)
02-26-2016, 05:51 PM
Find
Abihishi Offline
Junior Member

Posts: 44
Threads: 8
Joined: Feb 2016
Reputation: 0
#5
RE: Script - Piano Music

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 ';'
02-27-2016, 10:32 AM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#6
RE: Script - Piano Music

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: (Select All)
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.
(This post was last modified: 02-27-2016, 11:04 AM by Spelos.)
02-27-2016, 11:03 AM
Find
Abihishi Offline
Junior Member

Posts: 44
Threads: 8
Joined: Feb 2016
Reputation: 0
#7
RE: Script - Piano Music

Thanks
(This post was last modified: 02-27-2016, 11:56 AM by Abihishi.)
02-27-2016, 11:55 AM
Find
Abihishi Offline
Junior Member

Posts: 44
Threads: 8
Joined: Feb 2016
Reputation: 0
#8
RE: Script - Piano Music

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
02-27-2016, 01:19 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#9
RE: Script - Piano Music

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: (Select All)
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: (Select All)
void OnStart() // <-- This is a function, no ";" here.
{
    
Command(); // <-- This is a command, ";" has to be here!


Try to keep it in mind.
(This post was last modified: 02-27-2016, 03:59 PM by Spelos.)
02-27-2016, 01:32 PM
Find
Abihishi Offline
Junior Member

Posts: 44
Threads: 8
Joined: Feb 2016
Reputation: 0
#10
RE: Script - Piano Music

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

not work, and piano music too ;P
02-27-2016, 02:54 PM
Find




Users browsing this thread: 1 Guest(s)