In-game level background music [Help Thread]

Ask questions, discuss ideas, get answers
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

In-game level background music [Help Thread]

Post by Swaffy »

Once I fugure this out, I can make a highly detailed tutorial for anyone to look at.

There is a tutorial already existing for adding music to objects such as Simple Objects and vehicles, but this is not what I'm trying to do. In what I am trying to do, the music plays just like it is in the main menu and the map loading screen. So that tutorial is over a different subject.

If you know of an already-existing tutorial, I'll be happy to remove this if the tutorial helps me fix the issue at hand.

--------------------------------------------------------------------------------------------------------------------------------------

I have been trying, for that past week, to add music to play on a map during a game. A wonderful example of this is a mod called "Wasteland 2042."

This is what I tried:

- Converted a ".wav" sound file to a ".bik" sound file using RAD Video Tools named "Low" and placed it in the Music folder [Mods\Swaffy'sMod\Music]

- added this line in my El Alamein RFA file [bf1942\levels\El_Alamein\Menu\init.con]:
game.setBackgroundMusic "Music/Low.bik"

- Added that line to both El_Alamein.rfa and El_Alamein_003.rfa.

In short, I tried to copy what I saw in Wasteland 2042. Unfortunately, it didn't work.

PICTURES:

RFA File Image of "init.con"
Image

Music folder with "Low" sound file
Image
Last edited by Swaffy on Wed May 11, 2011 4:54 pm, edited 1 time in total.
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Re: In-game level background music [Help Thread]

Post by Apache Thunder »

I use this code in my Mario kart mod. Here is an example:

Code: Select all

game.setBackgroundMusic ../../mods/GCN_Mario_Kart/music/baby1.bik
Notice the addition of ../../ then the full path to your music folder. (including the mod folder and mod folder in path).

Also you may need to experiment with encoding the BIK in a different sampleing rate if it still fails as I believe sometimes it's a bit picky with the format. Also note the music's volume is effected by the music volume setting in the game settings and not sound volume, so keep that in mind as well.

So for the music file you attempted, the path should look like this:

Code: Select all

game.setBackgroundMusic ../../mods/Swaffy'sMod/Music/low.bik
Also try removing the apostrophe from "Swaffy" so it reads "SwaffisMod" instead. Since I think it could pose a problem for the game engine if you use spaces or other symbles in your mod folder name.

Please note the music will not start playing until after you leave the ready screen once ingame. It won't play during the load screen or during the ready screen. ;)
ImageImageImage
I have cameras in your head!
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Re: In-game level background music [Help Thread]

Post by Swaffy »

Code: Select all

game.setBackgroundMusic "Music/Low.bik"
game.setBackgroundMusic ../../mods/Swaffy'sMod/Music/low.bik
game.setBackgroundMusic ../../mods/SwaffysMod/Music/low.bik
I tried all three of these. Still ... no dice.
I even copied and pasted the exact sound file [Low.bik] from Wasteland 2042, and it still didn't work.

Yes, "Low.bik" is in the folder [mods\Swaffy'sMod\Music].
And yes, the script is in [bf1942\levels\El_Alamein\Menu\init.con].

Should I set up a download of my mod for you to play around with? If you had a hands-on look at it, you'd most likely find the problem.
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Re: In-game level background music [Help Thread]

Post by Apache Thunder »

Have you tried reencoding the BIK to a different frequency/sampling rate? The game seems real picky to the format the BIKs are in. The DC music files for example didn't work for me. So if that BIK was used as menu music originally, then it may not have been encoded right for the ingame music command to work.
ImageImageImage
I have cameras in your head!
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Re: In-game level background music [Help Thread]

Post by Swaffy »

It was used for the level background music. That's why I copied it over from to my mod, so that I can try having background music using a sound file that works in a different mod. What are the steps you took in doing this? Did you only do the two steps I mentioned above [1: Add the .bik to "mods\Swaffy'sMod\Music" and 2: add those lines tho the map's init.con]? Is that all you need to do?
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
User avatar
Apache Thunder
Posts: 1210
Joined: Mon Oct 19, 2009 2:48 am
Location: Levelland Texas, USA
Contact:

Re: In-game level background music [Help Thread]

Post by Apache Thunder »

Yes. I put mine in the menu's init.con file. It was the last line in the file in terms of loading order.

Also check that mod name in your path matches the mod folder name excactly. If you removed the apostrophe in the path, you need to do the same to the folder name afterwords. That's pretty much all I did.
ImageImageImage
I have cameras in your head!
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Re: In-game level background music [Help Thread]

Post by Swaffy »

I'll give it a try. I hope renaming my mod's folder won't break any other load paths I set before in my mod.

[Edit:] Still ... nothing. What sucks is that I had to change all of my maps from [game.setMapId "Swaffy'sMod"] to [game.setMapId "SwaffysMod"]. I also changed to path of the sound file in the map's init.con file.
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
freddy
Posts: 1267
Joined: Sun Oct 18, 2009 4:58 pm

Post by freddy »

try to get it running per map basis first maybe? when you know the file plays ok you can concentrate on getting the pathway right to run it from the modfolder.
User avatar
Swaffy
Posts: 1715
Joined: Sun Aug 29, 2010 9:25 pm
Location: Cibolo, Texas

Re: In-game level background music [Help Thread]

Post by Swaffy »

Download the mod in my signature. Maybe you should check it for yourself.
I'm going to change the music file to different music later on, but I just want to get it working first.
The sound file is named "Low.bik"
(Forum Thread|Download) Swaffy'sMod v0.34 | Download link to come Soon™
User avatar
fo0k
Posts: 1433
Joined: Fri Oct 16, 2009 4:21 pm
Location: UK

Re: In-game level background music [Help Thread]

Post by fo0k »

I've used different wavs before and encoded with radtools with varied success. Even two wavs which appear to have the same bitrate, frequency etc can differ depending on which software encoded the file.
Post Reply