Advertisement
KBM-Quine

jukebox.lua v0.2

Oct 5th, 2021
860
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. -------------------------------------------------
  2. --[[      jukebox.lua v0.2 by KBM-Quine      ]]--
  3. --[[    "custom" overworld music library     ]]--
  4. -------------------------------------------------
  5.  
  6. local jukebox = {}
  7.  
  8. local curMusicID = mem(0x00B2C5D8, FIELD_WORD)
  9. local curTrack = -1
  10.  
  11. local function resolveTrack(string) -- to make default tracks easier to replace
  12.     local returnString = Misc.resolveSoundFile(string) or Misc.resolveSoundFile("music\\" .. string)
  13.     return returnString
  14. end
  15.  
  16. local tracks = {
  17.     [0] = nil,
  18.     [1] = resolveTrack("smb3-world1"),
  19.     [2] = resolveTrack("smb3-world4"),
  20.     [3] = resolveTrack("smb3-world7"),
  21.     [4] = resolveTrack("smw-worldmap"),
  22.     [5] = resolveTrack("nsmb-world"),
  23.     [6] = resolveTrack("smb3-world2"),
  24.     [7] = resolveTrack("smw-forestofillusion"),
  25.     [8] = resolveTrack("smb3-world3"),
  26.     [9] = resolveTrack("smb3-world8"),
  27.     [10] = resolveTrack("smb3-world6"),
  28.     [11] = resolveTrack("smb3-world5"),
  29.     [12] = resolveTrack("smw-special"),
  30.     [13] = resolveTrack("smw-bowserscastle"),
  31.     [14] = resolveTrack("smw-starroad"),
  32.     [15] = resolveTrack("smw-yoshisisland"),
  33.     [16] = resolveTrack("smw-vanilladome"),
  34. }
  35.  
  36. function jukebox.setTrack(id, filepath)
  37.     tracks[id] = filepath
  38. end
  39.  
  40. function jukebox.getTrack(id)
  41.     return tracks[id]
  42. end
  43.  
  44. function jukebox.getPlayingTrack()
  45.     return tracks[curTrack]
  46. end
  47.  
  48. function jukebox.getPlayingTrackID()
  49.     return curTrack
  50. end
  51.  
  52. function jukebox.setMusicBox(id, x, y)
  53.     if not isOverworld then return end
  54.     local m = Musicbox.getIntersecting(x, y, x+32, y+32)[1]
  55.     m.id = id
  56. end
  57.  
  58. function jukebox.playTrack(trackID)
  59.     Audio.MusicStop()
  60.     if trackID > 0 then -- use 0 to allow making the music stop
  61.         Audio.MusicOpen(tracks[trackID])
  62.         Audio.MusicPlay()
  63.         curMusicID = trackID
  64.         curTrack = trackID
  65.     else
  66.         curTrack = 0
  67.     end
  68. end
  69.  
  70. function jukebox.onInitAPI()
  71.     registerEvent(jukebox, "onStart")
  72.     registerEvent(jukebox, "onTick")
  73.     registerEvent(jukebox, "onExit")
  74. end
  75.  
  76. function jukebox.onStart()
  77.     if not isOverworld then return end
  78.     Audio.SeizeStream(-1)
  79. end
  80.  
  81. function jukebox.onTick()
  82.     if not isOverworld then return end
  83.     curMusicID = mem(0x00B2C5D8, FIELD_WORD) -- to allow the var to update
  84.     Text.printWP(curTrack, 0,20, 6)
  85.     Text.printWP(curMusicID, 0,0, 6)
  86.     if not (curTrack == curMusicID) then
  87.         jukebox.playTrack(curMusicID)
  88.     end
  89. end
  90.  
  91. function jukebox.onExit()
  92.     if not isOverworld then return end
  93.     curTrack = -1
  94.     Audio.MusicStop()
  95.     Audio.ReleaseStream(-1)
  96. end
  97.  
  98. return jukebox
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement