Frictional Games Forum (read-only)

Full Version: Help getting music to play in map
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Yes, put the PlayMusic line in either OnEnter or OnStart if you want it to play as soon as you appear in the map. If you put it in OnStart it will only start once (if you enter several times), but the music will keep playing throughout levels if you don't stop or change it.
Code:
void OnStart()
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 0.0f, false);
PlayMusic("02_amb_safe.ogg", true, 1.0f, 0, 0, true);
AddEntityCollideCallback("Player", "Flaska", "PlaySound", true, 1);
AddEntityCollideCallback("Player", "Ljud", "start", true, 1);
AddUseItemCallback("", "Key", "Door", "UseKeyOnDoor", true);
AddUseItemCallback("", "Nyckel", "Rumpa", "UseKeyOnDoor", true);
AddUseItemCallback("", "Tillskåp", "Skåp", "UseKeyOnDoor", true);

}

void UseKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "Unlock_door.snt", asEntity, 10, false);
RemoveItem(asItem);
}

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
}

void PlaySound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "21_intro_scream.snt", "Player", 1, false);
}

I was able to load the map but now when i enter an area general_piano01.snt, 02_amb_safe.ogg, 21_intro_scream.snt plays at the same time, lol. How does one separate these to play in their respective areas? I know you're suppose to name the area but i don't really see the solution in the script.
It's because you're starting "general_piano01" and "02_amb_safe" right as you start the map. When do you want these sounds/musics to start?
(02-01-2015, 09:02 PM)Neelke Wrote: [ -> ]It's because you're starting "general_piano01" and "02_amb_safe" right as you start the map. When do you want these sounds/musics to start?

Yeah i figured that out and managed to separate "21_intro_scream.snt" and "general_piano01.snt" to play in separately placed areas when i enter them. I guess i'm back to square one right now. I can't figure out how to write in the script so that music will start playing when i enter a certain area given on the map.

Using this one now:
Code:
void OnStart()
{

AddEntityCollideCallback("Player", "Flaska", "PlaySound", true, 1);
AddEntityCollideCallback("Player", "Ljud", "start", true, 1);
AddUseItemCallback("", "Key", "Door", "UseKeyOnDoor", true);
AddUseItemCallback("", "Nyckel", "Rumpa", "UseKeyOnDoor", true);
AddUseItemCallback("", "Tillskåp", "Skåp", "UseKeyOnDoor", true);

}

void UseKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "Unlock_door.snt", asEntity, 10, false);
RemoveItem(asItem);
}

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
}

void PlaySound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "21_intro_scream.snt", "Player", 1, false);
}
Maybe you need to add another collide function? (Another area to collide with). Or just put the music script in one of the functions.

Code:
void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
PlayMusic("02_amb_safe.ogg", true, 1.0f, 0, 0, true);
}

Or a new function:

Code:
void OnStart()
{
     AddEntityCollideCallback("Player", "AreaStartMusic", "CollideStartMusic", true, 1);
}

void CollideStartMusic(string &in asParent, string &in asChild, int alState)
{
     PlayMusic("02_amb_safe.ogg", true, 1.0f, 0, 0, true);
}
I would strongly advice against using nordic characters in your script. Try to make it as clean as possible. Using Æ Ø Å can mess with your script because the game doesn't know how to parse it.
(02-01-2015, 10:39 PM)Neelke Wrote: [ -> ]Maybe you need to add another collide function? (Another area to collide with). Or just put the music script in one of the functions.

Code:
void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
PlayMusic("02_amb_safe.ogg", true, 1.0f, 0, 0, true);
}

Or a new function:

Code:
void OnStart()
{
     AddEntityCollideCallback("Player", "AreaStartMusic", "CollideStartMusic", true, 1);
}

void CollideStartMusic(string &in asParent, string &in asChild, int alState)
{
     PlayMusic("02_amb_safe.ogg", true, 1.0f, 0, 0, true);
}

I honestly have no idea how to apply that to the existing script. Where would i put it? Thanks

(02-02-2015, 12:55 AM)Mudbill Wrote: [ -> ]I would strongly advice against using nordic characters in your script. Try to make it as clean as possible. Using Æ Ø Å can mess with your script because the game doesn't know how to parse it.

Ok i will fix that, thank you.

Ok, got it working. Thanks guys! Smile

Code:
void OnStart()
{
AddEntityCollideCallback("Player", "Musik", "CollideStartMusic", true, 1);
AddEntityCollideCallback("Player", "Flaska", "PlaySound", true, 1);
AddEntityCollideCallback("Player", "Ljud", "start", true, 1);
AddUseItemCallback("", "Key", "Door", "UseKeyOnDoor", true);
AddUseItemCallback("", "Nyckel", "Rumpa", "UseKeyOnDoor", true);
AddUseItemCallback("", "Tillskap", "Skap", "UseKeyOnDoor", true);

}

void UseKeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked(asEntity, false, true);
PlaySoundAtEntity("", "Unlock_door.snt", asEntity, 10, false);
RemoveItem(asItem);
}

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 1, false);
}

void PlaySound(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "21_intro_scream.snt", "Player", 1, false);
}

void CollideStartMusic(string &in asParent, string &in asChild, int alState)
{
     PlayMusic("02_amb_safe.ogg", false, 1.0f, 0, 0, true);
}
Pages: 1 2