jukebox.lua - Custom overworld music, simplified

Share and discuss custom LunaLua code and content packs for SMBX2.
User avatar
KBM-Quine
Dolphin
Dolphin
Posts: 86
Joined: Wed Jan 15, 2014 11:10 am
Flair: Crazy with a K

jukebox.lua - Custom overworld music, simplified

Postby KBM-Quine » Thu Oct 07, 2021 1:39 am

not using smwMap.lua for your overworld? don't want to switch to that because you already made your map but want more music? then this should suit you just fine.

made simply because i've explained it's possible and that no one wanted to do it plenty of times. i've now made this so i can direct people to it instead of re-explaining it.

this system also allows easier default music replacement by loading the music from either the base episode folder or a sub folder titled music. to use that feature, just rename the default overworld music replacement you wish to make with the same name as the default file name it has in data\music.

not really much i can showcase sensibly given it's nature, but i can give a run down of it's basic premise and documentation.
basic use: show
- place the library in the base of your episode. you can place it elsewhere if you know what your doing, but this guide assumes your unfamiliar with this process
- you place down a musicbox and take note of it's coordinates. you can get those by either holding ctrl while placing or right clicking the musicbox an going to - copy preference > position: X, Y (in PGE)
-from there, use this code load, register, and use the system in a map.lua file:

Code: Select all

local jukebox = require("jukebox")

jukebox.setTrack(track ID, "path to music file")
jukebox.setMusicBox(track ID, musicbox X, musicbox Y)
jukebox.setTrack() - this sets the track of the specified track ID to the "path to music file", it only needs to be done once per ID.

track ID - the ID used by the system to determine the track to play. this can technically be anything, but the first 16 are pre-registered to the default musicboxes' tracks. i'd recommend using the custom range (750-1000) when registering just for sake of keeping things in-line with base game systems

"path to music file" - this is a string and does as the name implies. if your unfamiliar with lua, strings need backslashes to be escaped to be properly used. (like "music\\smb3-world1.spc" or something akin to that) i recommend jukebox.resolveMusicFile(string) if you don't know the file extension. certain extensions can use path arguments. this may be necessary for things like .spc, which play very quietly by default. for those you'd do something like "my song.spc|0;g=2.7;". you can find a full list of music path args here. if using in conjunction with jukebox.resolveMusicFile(string), then it'd be like so: jukebox.resolveMusicFile("my song") .. "|0;g=2.7;"

jukebox.setMusicBox - transforms the musicbox at the specified X/Y's ID to the track ID supplied. thus you'd use one of the IDs you used in a setTrack if using a custom one. this needs to be done for as many musicboxes as you want for the custom track ID your using.
documentation: show
here are some additional functions you can use to control the system a bit
jukebox.autoPlayMusic = bool - whether or not the system will auto play music upon start/touching a music box. can be used to call your own music changes
jukebox.getTrack(id) - returns the filename/path of the track of the ID given
jukebox.getPlayingTrack() - returns the filename/path of the track currently playing. will return nil if nothing is playing
jukebox.getPlayingTrackID() - returns the ID of the track currently playing. will return 0 or -1 if nothing is playing
jukebox.playTrack(trackID) - plays the track of the ID supplied. can use 0 to make it not play anything.
jukebox.resolveMusicFile(path) - like Misc.resolveSoundFile(string), but can get any usable music format from this page
feel free to give any feedback or report bugs, have a nice day.
Image
Last edited by KBM-Quine on Mon Oct 18, 2021 7:39 pm, edited 3 times in total.
after some consideration, i've decided against allowing use of my assets to Novaverse based levels and projects. anything accredited to me or my aliases is off-limits to those as such. - KBM-Quine
aliases: krazybluemonkey, Quine, KBM-Quine

Image
Image
Image
Image

User avatar
marioman2007
Spike
Spike
Posts: 262
Joined: Tue Aug 25, 2020 3:19 am
Pronouns: He/Him

Re: jukebox.lua - Custom overworld music, simplified

Postby marioman2007 » Thu Oct 07, 2021 2:44 am

Ooh, really Nice! Finally we can have multiple overworld music.
Just learning Lua and Importing Graphics

The Super Cool Pack:
Image
https://discord.gg/78w3gGAptB

I support:
Image
Image

User avatar
KBM-Quine
Dolphin
Dolphin
Posts: 86
Joined: Wed Jan 15, 2014 11:10 am
Flair: Crazy with a K

Re: jukebox.lua - Custom overworld music, simplified

Postby KBM-Quine » Fri Oct 08, 2021 1:48 pm

seems i accidentally left jukebox.autoPlayMusic on false from my testing, oops! fixed that and put the version number to 1.0 proper. link is updated but a redownload isn't entirely necessary. if you don't want to redownload, just edit line 8 to true. or don't if it being false by default suits you fine.
after some consideration, i've decided against allowing use of my assets to Novaverse based levels and projects. anything accredited to me or my aliases is off-limits to those as such. - KBM-Quine
aliases: krazybluemonkey, Quine, KBM-Quine

Image
Image
Image
Image

User avatar
LennonsFactory
Goomba
Goomba
Posts: 2
Joined: Sun Oct 10, 2021 7:55 pm
Pronouns: he him his
Contact:

Re: jukebox.lua - Custom overworld music, simplified

Postby LennonsFactory » Sun Oct 10, 2021 8:12 pm

:D this is going to be VERY useful
Hey! I'm Lennon, from LennonsFactory!
My YouTube: www.youtube.com/channel/UCdgXthxr0ELMcHa6170fxGQ

User avatar
18SEVERLY
Cheep-Cheep
Cheep-Cheep
Posts: 10
Joined: Tue Jul 22, 2014 5:23 pm
Pronouns: they/them
Contact:

Re: jukebox.lua - Custom overworld music, simplified

Postby 18SEVERLY » Wed Oct 13, 2021 10:59 am

How can I normalize the music playing in the world map? Thinking of using this for my episode.

Working on a game, called Super Mario All-Stars++. Been in development since 2012, and I'm finishing it to get it done for good. Contact me if you have any questions about the project.

User avatar
KBM-Quine
Dolphin
Dolphin
Posts: 86
Joined: Wed Jan 15, 2014 11:10 am
Flair: Crazy with a K

Re: jukebox.lua - Custom overworld music, simplified

Postby KBM-Quine » Thu Oct 14, 2021 2:41 am

18SEVERLY wrote:
Wed Oct 13, 2021 10:59 am
How can I normalize the music playing in the world map? Thinking of using this for my episode.
so looked into it, looks like you have to use the gain arg for .spc's. like "my song.spc|0;g=2.7;". you can read about music path args here

that all said, another update! read the first post for more, as well as the download in it has been updated

edit:small mistake, the gain arg was lower then intended. fixed.
after some consideration, i've decided against allowing use of my assets to Novaverse based levels and projects. anything accredited to me or my aliases is off-limits to those as such. - KBM-Quine
aliases: krazybluemonkey, Quine, KBM-Quine

Image
Image
Image
Image


Return to “LunaLua”

Who is online

Users browsing this forum: Murphmario and 2 guests