Frictional Games Forum (read-only)
[SCRIPT] Changing music mid level - 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] Changing music mid level (/thread-20272.html)



Changing music mid level - serbusfish - 02-10-2013

The scenario; a scream is heard, the normal level music stops and goes silent, then when the player interacts with a script area a monster noise plays and different (tense) music plays, then once the tense music has finished the normal music comes back on.

Now I have already done most of this, the only bit im having trouble with is making the normal music start playing again, here is my current script:

Code:
{
AddEntityCollideCallback("Player", "ScriptArea_1", "LoudNoise", true, 1);
AddEntityCollideCallback("Player", "ScriptArea_5", "SuddenScare", true, 1);
}

void LoudNoise(string &in asParent, string &in asChild, int alState)
    
                         {
                             PlaySoundAtEntity("", "05_event_door_bang", "ScriptArea_3", 0, false);
                             StartPlayerLookAt("ScriptArea_3", 3, 1, "");
                             SetPlayerMoveSpeedMul(0);
                             SetPlayerRunSpeedMul(0);
                             SetPlayerLookSpeedMul(0);
                             AddTimer("Murder", 3, "Murder");
                             StopMusic(1, 1);
                            
                         }
                        
                     void Murder(string &in asTimer)
                        
                         {
                             PlaySoundAtEntity("", "react_scare", "Player", 0.0f, false);
                             StopPlayerLookAt();
                             SetPlayerMoveSpeedMul(1);
                             SetPlayerRunSpeedMul(1);
                             SetPlayerLookSpeedMul(1);
                            
                         }
                        
                     void SuddenScare(string &in asParent, string &in asChild, int alState)
                    
                         {
                             PlaySoundAtEntity("", "04_break", "ScriptArea_4", 0, false);
                             PlaySoundAtEntity("", "04_break02", "ScriptArea_4", 0, false);
                             StartPlayerLookAt("ScriptArea_4", 5, 5, "");
                             SetPlayerMoveSpeedMul(0);
                             SetPlayerRunSpeedMul(0);
                             SetPlayerLookSpeedMul(0);
                             AddTimer("ScarySound", 3, "ScarySound");
                            
                         }
                        
                     void ScarySound(string &in asTimer)
                    
                         {
                             PlayMusic("01_event_dust", false, 2, 4, 0, true);
                             StopPlayerLookAt();
                             SetPlayerMoveSpeedMul(1);
                             SetPlayerRunSpeedMul(1);
                             SetPlayerLookSpeedMul(1);
}

As it stands if I try to add the level music in it will start playing at the same time as the tense music, is there anyway to delay it with a timer or something?


RE: Changing music mid level - serbusfish - 02-11-2013

Anyone? Im sure ive seen this done in other CS so it has to be possible.


RE: Changing music mid level - FlawlessHappiness - 02-11-2013

What you use is:

Code:
void PlayMusic(string& asMusicFile, bool abLoop, float afVolume, float afFadeTime, int alPrio, bool abResume);

Plays music.asMusicFile - the music to play + extension .ogg
abLoop - determines whether a music track should loop
afVolume - volume of the music
afFadeTime - time in seconds until music reaches full volume
alPrio - priority of the music. Note that only the music with the highest priority can be heard! 0 - lowest, 1 - higher, etc.
abResume - if true, playback will be continued from where the track stopped after the call to StopMusic(); if false, the track will be restarted.


And

Code:
void StopMusic(float afFadeTime, int alPrio);

Stops music.afFadeTime - time in seconds until music stops
alPrio - the priority of the music that should stop