Advertisement
TheRobloxPlayer2509

Reason 2 Die: Music Addon

May 22nd, 2022
935
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --[[
  2.     Reason 2 Die music addon
  3.     Enhancing your R2DA experience since 2022.
  4.     Version: PROTOTYPE 1.0.0
  5.  
  6.     Todo:
  7.     Victory music
  8.     Start ambience of Dead Vacation
  9.     Buried Alive exclusive soundtrack
  10.     Boss music
  11.     Bug fixes!
  12. --]]
  13.  
  14. math.randomseed(os.time())
  15. local plr = game.Players.LocalPlayer
  16. local pgui = plr.PlayerGui
  17. local chat = pgui:WaitForChild("Chat")
  18. local musicScript = chat.Code:FindFirstChild("Music")
  19. local normalSound = musicScript:WaitForChild("Sound")
  20. local serverSettings = workspace:FindFirstChild("Settings")
  21. local currentMap = serverSettings.CurrentMap
  22. local reps = game:GetService("ReplicatedStorage")
  23.  
  24. local inmenu = false
  25. local loading = false
  26. local champion = false
  27. local victory = false
  28.  
  29. local musicList = { -- Preload
  30.     ["Victory"] = getsynasset("Victory.mp3"),
  31.     ["Menu"] = getsynasset("Menu.mp3"),
  32.     ["Loading"] = getsynasset("Loading.mp3"),
  33.     ["Universal1"] = getsynasset("Universal1.mp3"),
  34.     ["Universal2"] = getsynasset("Universal2.mp3"),
  35.     ["Universal3"] = getsynasset("Universal3.mp3"),
  36.     ["Universal4"] = getsynasset("LateGame1.mp3"),
  37.     ["Universal5"] = getsynasset("LateGame2.mp3"),
  38.     ["BuriedAlive"] = getsynasset("BuriedAlive.mp3"),
  39.     ["DeadVacationStart"] = getsynasset("DeadVacationStart.mp3"),
  40.     ["Champion"] = getsynasset("Champion.mp3"),
  41.     ["ChronoQuest"] = getsynasset("ChronoQuest.mp3"),
  42.     ["ChronoBoss"] = getsynasset("ChronoBoss.mp3"),
  43.     ["CherryQuest"] = getsynasset("CherryQuest.mp3"),
  44.     ["CherryBoss"] = getsynasset("CherryBoss.mp3"),
  45.     ["CasinoHall"] = getsynasset("CasinoHall.mp3"),
  46.     ["Jackpot"] = getsynasset("Jackpot.mp3"), -- Casino hall boss
  47.     ["DuckyQuest"] = getsynasset("DuckyQuest.mp3")
  48. }
  49. local playingMusic = false
  50. local lastUniversal = 0
  51. local currentMusic = Instance.new("Sound", reps)
  52. currentMusic.Name = "CurrentMusic"
  53. currentMusic.Volume = normalSound.Volume
  54. local menuMusic = Instance.new("Sound", reps)
  55. menuMusic.Name = "MenuMusic"
  56. menuMusic.Volume = 1.5
  57. menuMusic.Looped = true
  58. menuMusic.SoundId = musicList["Menu"]
  59. local loadingMusic = Instance.new("Sound", reps)
  60. loadingMusic.Name = "LoadingMusic"
  61. loadingMusic.Volume = 1.5
  62. loadingMusic.SoundId = musicList["Loading"]
  63.  
  64. local function stopMusic(id)
  65.     if id == "Menu" then
  66.         menuMusic:Stop()
  67.         currentMusic.Volume = 1.5
  68.     elseif id == "Loading" then
  69.         loadingMusic:Stop()
  70.         currentMusic.Volume = 1
  71.     else
  72.         currentMusic:Stop()
  73.         playingMusic = false
  74.     end
  75. end
  76.  
  77. local function playMusic(id)
  78.     print("got play request " ..id)
  79.     if id == "Menu" then
  80.         currentMusic.Volume = 0
  81.         menuMusic:Play()
  82.     elseif id == "Loading" then
  83.         currentMusic.Volume = 0
  84.         loadingMusic:Play()
  85.     else
  86.         stopMusic()
  87.         if not inmenu and not loading then
  88.             currentMusic.SoundId = musicList[id]
  89.             currentMusic.Volume = .75
  90.             currentMusic:Play()
  91.             playingMusic = true
  92.             local cn; cn = currentMusic.Changed:Connect(function()
  93.                 if currentMusic.Playing == false then
  94.                     cn:Disconnect()
  95.                     playingMusic = false
  96.                 end
  97.             end)
  98.         end
  99.     end
  100. end
  101.  
  102. local cn1; cn1 = pgui.ChildAdded:Connect(function(obj)
  103.     if obj.Name == "Menu" then
  104.         -- play menu music!!
  105.         inmenu = true
  106.         playMusic("Menu")
  107.     elseif obj.Name == "LoadMap" then
  108.         -- play loading music!!
  109.         loading = true
  110.         playMusic("Loading")
  111.     end
  112. end)
  113.  
  114. local cn2; cn2 = pgui.ChildRemoved:Connect(function(obj)
  115.     if obj.Name == "Menu" then
  116.         -- stop menu music!!
  117.         stopMusic("Menu")
  118.         inmenu = false
  119.     elseif obj.Name == "LoadMap" then
  120.         -- stop loading music!!
  121.         stopMusic("Loading")
  122.         loading = false
  123.     end
  124. end)
  125.  
  126. local cn3; cn3 = normalSound.Changed:Connect(function()
  127.     if inmenu == false and loading == false then
  128.         currentMusic.Volume = .75
  129.     end
  130.     if (normalSound.SoundId == "4596210702" and normalSound.Playing == true) or (normalSound.SoundId == "rbxassetid://4596210702" and normalSound.Playing == true) then -- Champion!!
  131.         -- play champion music
  132.         champion = true
  133.         playMusic("Champion")
  134.     else
  135.         if champion == true then
  136.             stopMusic()
  137.         end
  138.         champion = false
  139.     end
  140. end)
  141.  
  142. -- initialization
  143. if pgui:FindFirstChild("Menu") then
  144.     inmenu = true
  145.     playMusic("Menu")
  146. end
  147. if pgui:FindFirstChild("LoadMap") then
  148.     loading = true
  149.     -- doesn't play music to avoid complication since loading screen is usually fast
  150. end
  151. print("R2DA music addon loaded")
  152.  
  153. while true do -- each attempt to do music
  154.     if playingMusic == false and champion == false then
  155.         -- can play music
  156.         if currentMap.Gamemode.Value ~= "QUEST" and currentMap.Gamemode.Value ~= "BOSS" then
  157.             -- a normal gamemode
  158.             local rng
  159.             repeat
  160.                 rng = math.random(1, 5)
  161.                 wait(.03)
  162.             until rng ~= lastUniversal
  163.             lastUniversal = rng
  164.         elseif currentMap.Gamemode.Value == "QUEST" then
  165.             if currentMap.Value == "QuestChronos" then
  166.                 -- Chrono quest
  167.                 playMusic("ChronoQuest")
  168.             elseif currentMap.Value == "CasinoHalls" then
  169.                 -- Casino Hall
  170.                 playMusic("CasinoHall")
  171.             elseif currentMap.Value == "QCherry" then
  172.                 -- Cherry quest
  173.                 playMusic("CherryQuest")
  174.             end
  175.         elseif currentMap.Gamemode.Value == "BOSS" then -- boss music not yet properly implemented
  176.             if currentMap.Value == "BossChronos" then
  177.                 -- Chrono boss
  178.                 playMusic("ChronoBoss")
  179.             elseif currentMap.Value == "BossCherrycake" then
  180.                 -- Cherry boss
  181.                 playMusic("CherryBoss")
  182.             else
  183.                 -- Jackpot
  184.                 playMusic("Jackpot")
  185.             end
  186.         end
  187.     end
  188.     repeat wait(5)
  189.     until playingMusic == false
  190.     if currentMap.Gamemode.Value == "QUEST" or currentMusic.Gamemode.Value == "BOSS" then
  191.         wait(5)
  192.     else
  193.         wait(30)
  194.     end
  195. end
Advertisement
RAW Paste Data Copied
Advertisement