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 Help Help getting music to play in map
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#1
Help getting music to play in map

I've been away from Custom Story'ing a while and just got back to it. I would like music to play in my map when i enter an area. Music that's in the "music" folder in amnesia. I've tried scripting it several times but it's not working. I've allso looked around for a solution but without success. If any of you would please take a look at my script and see were the music code should be put it would be very appreciated! Scripting is hard for the lesser talented...

So this is my script:

void OnStart()
{

AddEntityCollideCallback("Player", "Rabarber", "PlaySound", true, 1);
AddEntityCollideCallback("Player", "Stopp", "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", 0.0f, false);
}

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


All i know is that "void PlaySoundAtEntity(string& asSoundName, string& asSoundFile, string& asEntity, float afFadeTime, bool abSaveSound);" is to be placed in there in order to work, but i can't figure it out. Sad Anyone care to give some pointers? Smile
02-01-2015, 01:49 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#2
RE: Help getting music to play in map

If you want music to play, then you need to use PlayMusic script.

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.

But what exactly do you want to be played?

Derp.
02-01-2015, 01:57 PM
Find
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#3
RE: Help getting music to play in map

(02-01-2015, 01:57 PM)Neelke Wrote: If you want music to play, then you need to use PlayMusic script.

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.

But what exactly do you want to be played?

That's not really important right now, i will find something i feel fits, i just don't know how to place the script within my script. :/ I see now i pasted the void PlaySoundAtEntity wich is wrong ofcourse, i meant to say i've tried with the void PlayMusic script. Its just the scripting itself and placements etc that confuces me.
(This post was last modified: 02-01-2015, 02:03 PM by LDOriginal.)
02-01-2015, 02:01 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#4
RE: Help getting music to play in map

Well, judging from what I see in the script, it should work. Have you checked if all the names are correct?

Derp.
02-01-2015, 02:05 PM
Find
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#5
RE: Help getting music to play in map

(02-01-2015, 02:05 PM)Neelke Wrote: Well, judging from what I see in the script, it should work. Have you checked if all the names are correct?

The script as shown there does work. My problem is how and were to apply the void PlayMusic to actually make it work in the map. Perhaps i'm not explaining this to well, sorry.
02-01-2015, 02:08 PM
Find
Darkfire Offline
Senior Member

Posts: 371
Threads: 22
Joined: May 2014
Reputation: 15
#6
RE: Help getting music to play in map

You can also try placing the music file in Custom_Story_Name/music/file.ogg
(the format is important, nothing else wil work!)

Ps. I wouldn't recommend using native letters like ó, ę, ą ł, or these ones you used. They may work, but they as well might not.

02-01-2015, 02:12 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#7
RE: Help getting music to play in map

Your music file needs to be an .ogg format for it to work. There should be some converters online somewhere.

Derp.
02-01-2015, 02:18 PM
Find
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#8
RE: Help getting music to play in map

(02-01-2015, 02:18 PM)Neelke Wrote: Your music file needs to be an .ogg format for it to work. There should be some converters online somewhere.

Yes i know. My problem is simply how to apply the actual music script within the script. I've tried putting it at the top and bottom but it crashes upon start.
02-01-2015, 02:22 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#9
RE: Help getting music to play in map

Grabbing one of your functions here. This is how it's meant to be if you want the music to start when colliding with an area. (I hope I understand you properly.)

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 0.0f, false);
PlayMusic("YOUR_MUSIC_FILE_NAME", true, 1.0f, 0, 0, true);
}

If you want it to play every time you enter the map:

void OnEnter()
{
       PlayMusic("YOUR_MUSIC_FILE_NAME", true, 1.0f, 0, 0, true);
}

Derp.
(This post was last modified: 02-01-2015, 02:50 PM by Neelke.)
02-01-2015, 02:49 PM
Find
LDOriginal Offline
Junior Member

Posts: 35
Threads: 7
Joined: Oct 2014
Reputation: 0
#10
RE: Help getting music to play in map

(02-01-2015, 02:49 PM)Neelke Wrote: Grabbing one of your functions here. This is how it's meant to be if you want the music to start when colliding with an area. (I hope I understand you properly.)

void start(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("", "general_piano01.snt", "Player", 0.0f, false);
PlayMusic("YOUR_MUSIC_FILE_NAME", true, 1.0f, 0, 0, true);
}

If you want it to play every time you enter the map:

void OnEnter()
{
       PlayMusic("YOUR_MUSIC_FILE_NAME", true, 1.0f, 0, 0, true);
}

Will try this as soon as i get back home. Thank's for giving the time to help. Smile
02-01-2015, 02:52 PM
Find




Users browsing this thread: 2 Guest(s)