Abihishi
Junior Member
Posts: 44
Threads: 8
Joined: Feb 2016
Reputation:
0
|
Script - Piano Music
Hi Guys!
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 |
|
Spelos
Banned
Posts: 231
Threads: 19
Joined: Sep 2014
|
RE: Script - Piano Music
All you will actually need is a Script Area.
Remember the name of that Script Area.
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.5f, false); }
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 |
|
Abihishi
Junior Member
Posts: 44
Threads: 8
Joined: Feb 2016
Reputation:
0
|
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 |
|
Spelos
Banned
Posts: 231
Threads: 19
Joined: Sep 2014
|
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 |
|
Abihishi
Junior Member
Posts: 44
Threads: 8
Joined: Feb 2016
Reputation:
0
|
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 |
|
Spelos
Banned
Posts: 231
Threads: 19
Joined: Sep 2014
|
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.
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 |
|
Abihishi
Junior Member
Posts: 44
Threads: 8
Joined: Feb 2016
Reputation:
0
|
RE: Script - Piano Music
Thanks
(This post was last modified: 02-27-2016, 11:56 AM by Abihishi.)
|
|
02-27-2016, 11:55 AM |
|
Abihishi
Junior Member
Posts: 44
Threads: 8
Joined: Feb 2016
Reputation:
0
|
RE: Script - Piano Music
But how stop music in intro?
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 |
|
Spelos
Banned
Posts: 231
Threads: 19
Joined: Sep 2014
|
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:
void OnStart() { StopMusic(1.0f, 10); // 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.
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 |
|
Abihishi
Junior Member
Posts: 44
Threads: 8
Joined: Feb 2016
Reputation:
0
|
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 |
|
|