Advertisement
Walterin0

Untitled

Mar 11th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.34 KB | None | 0 0
  1. --SynapseX Decompiler
  2.  
  3. local plr = game.Players.LocalPlayer
  4. local char, torso
  5. local container = game.ReplicatedStorage:WaitForChild("CinderingBGM")
  6. local settings = require(container:WaitForChild("Settings"))
  7. local musicfolder = container:WaitForChild("MusicFolder")
  8. local globalfolder = musicfolder:WaitForChild("GlobalMusic")
  9. local zonesfolder = musicfolder:WaitForChild("MusicZones")
  10. local servercount = container:WaitForChild("ObjectCount").Value
  11. function GetMatchingCount()
  12. local count = 0
  13. local function recurse(instance)
  14. for _, v in pairs(instance:GetChildren()) do
  15. count = count + 1
  16. recurse(v)
  17. end
  18. end
  19. recurse(musicfolder)
  20. if count == servercount then
  21. return true
  22. end
  23. end
  24. while not GetMatchingCount() do
  25. wait(0.5)
  26. end
  27. function IsCleanRotation(v3values)
  28. for _, v in pairs(v3values) do
  29. if not (v % 90 <= 0.01) and not (v % 90 >= 89.99) then
  30. return false
  31. end
  32. end
  33. return true
  34. end
  35. local zones = {}
  36. local music = {}
  37. local globali
  38. if settings.UseMusicZones == true then
  39. for i, zone in pairs(zonesfolder:GetChildren()) do
  40. if zone:IsA("Model") and zone:FindFirstChild("Music") then
  41. music[i] = {}
  42. for _, sound in pairs(zone.Music:GetChildren()) do
  43. if sound:IsA("Sound") then
  44. table.insert(music[i], {
  45. Name = zone.Name,
  46. SoundId = sound.SoundId,
  47. Volume = sound.Volume,
  48. Pitch = sound.Pitch
  49. })
  50. end
  51. end
  52. zones[i] = {
  53. Priority = zone:FindFirstChild("Priority") and zone.Priority.Value or 1,
  54. Parts = {},
  55. Music = music[i]
  56. }
  57. for _, part in pairs(zone:GetChildren()) do
  58. if part:IsA("Part") then
  59. if IsCleanRotation({
  60. part.Rotation.X,
  61. part.Rotation.Y,
  62. part.Rotation.Z
  63. }) == true then
  64. do
  65. local lx, ly, lz = math.huge, math.huge, math.huge
  66. local mx, my, mz = -math.huge, -math.huge, -math.huge
  67. local function ApplyValues(p)
  68. if p.x < lx then
  69. lx = p.x
  70. end
  71. if p.x > mx then
  72. mx = p.x
  73. end
  74. if p.y < ly then
  75. ly = p.y
  76. end
  77. if p.y > my then
  78. my = p.y
  79. end
  80. if p.z < lz then
  81. lz = p.z
  82. end
  83. if p.z > mz then
  84. mz = p.z
  85. end
  86. end
  87. local points = {}
  88. local cf1 = part.CFrame
  89. local cf2 = part.CFrame * CFrame.Angles(0, math.pi / 2, 0)
  90. local cf3 = part.CFrame * CFrame.Angles(math.pi / 2, 0, 0)
  91. local lvz = cf1.lookVector * (part.Size.Z / 2)
  92. local lvx = cf2.lookVector * (part.Size.X / 2)
  93. local lvy = cf3.lookVector * (part.Size.Y / 2)
  94. points[1] = cf1 + lvz
  95. points[2] = cf1 - lvz
  96. points[3] = cf2 + lvx
  97. points[4] = cf2 - lvx
  98. points[5] = cf3 + lvy
  99. points[6] = cf3 - lvy
  100. for _, p in pairs(points) do
  101. ApplyValues(p)
  102. end
  103. table.insert(zones[i].Parts, {
  104. Coordinates = {
  105. lx = lx,
  106. ly = ly,
  107. lz = lz,
  108. mx = mx,
  109. my = my,
  110. mz = mz
  111. }
  112. })
  113. end
  114. else
  115. table.insert(zones[i].Parts, {Part = part})
  116. end
  117. end
  118. end
  119. end
  120. end
  121. end
  122. if settings.UseGlobalBackgroundMusic == true then
  123. globali = #music + 1
  124. music[globali] = {}
  125. for _, sound in pairs(globalfolder:GetChildren()) do
  126. if sound:IsA("Sound") then
  127. table.insert(music[globali], {
  128. SoundId = sound.SoundId,
  129. Volume = sound.Volume,
  130. Pitch = sound.Pitch
  131. })
  132. end
  133. end
  134. end
  135. local canmute = settings.DisplayMuteButton
  136. local clonegui
  137. if canmute then
  138. clonegui = script.MuteButtonGui:clone()
  139. end
  140. local musicon = true
  141. function SetButtonStyle(button)
  142. button.Text = "Music: " .. (musicon and "ON" or "OFF")
  143. button.Style = musicon and Enum.ButtonStyle.RobloxRoundDefaultButton or Enum.ButtonStyle.RobloxRoundDropdownButton
  144. button.TextColor3 = musicon and Color3.new(1, 1, 1) or Color3.new(0.2, 0.2, 0.23)
  145. end
  146. function CreateButton()
  147. local gui = clonegui:clone()
  148. local button = gui.Button
  149. button.Visible = true
  150. SetButtonStyle(button)
  151. button.MouseButton1Click:connect(function()
  152. musicon = not musicon
  153. local bgm = script:FindFirstChild("BGM")
  154. if bgm then
  155. bgm.Volume = musicon and bgm.OriginalVolume.Value or 0
  156. end
  157. SetButtonStyle(button)
  158. end)
  159. gui.Parent = plr:WaitForChild("PlayerGui")
  160. end
  161. function CharInit()
  162. char = plr.Character
  163. torso = char:WaitForChild("Torso")
  164. if canmute then
  165. CreateButton()
  166. end
  167. end
  168. if plr.Character and plr.Character.Parent ~= nil then
  169. CharInit()
  170. end
  171. plr.CharacterAdded:connect(function()
  172. CharInit()
  173. end)
  174. local FadeoutTime = settings.MusicFadeoutTime
  175. local replicatedstorage = game:GetService("ReplicatedStorage")
  176. function PlaySound(sounddata)
  177. if sounddata == nil then
  178. return
  179. end
  180. local sound = Instance.new("Sound")
  181. sound.Looped = true
  182. local zone = sounddata.Name
  183. sound.SoundId = zonesfolder:WaitForChild(zone):WaitForChild("Music"):WaitForChild("Sound").SoundId
  184. sound.TimePosition = workspace:WaitForChild("DJ_SOUND_TIMEPOS").TimePosition
  185. sound.Volume = musicon and sounddata.Volume or 0
  186. local v = Instance.new("NumberValue", sound)
  187. v.Name = "OriginalVolume"
  188. v.Value = sounddata.Volume
  189. sound.Pitch = sounddata.Pitch
  190. sound.Name = "BGM"
  191. sound.Parent = script
  192. sound:Play()
  193. end
  194. function FadeOutSound(sound)
  195. local basevol = sound.Volume
  196. local count = math.ceil(30 * FadeoutTime)
  197. if count < 1 then
  198. count = 1
  199. end
  200. for i = 1, count do
  201. if sound then
  202. sound.Volume = sound.Volume - basevol / count
  203. wait(0.03333333333333333)
  204. end
  205. end
  206. if sound then
  207. sound:Stop()
  208. sound:Destroy()
  209. end
  210. end
  211. if settings.UseGlobalBackgroundMusic == true and settings.UseMusicZones == false then
  212. if #music[globali] == 1 then
  213. PlaySound(music[1][1])
  214. return
  215. elseif #music[globali] == 0 then
  216. return
  217. end
  218. end
  219. local recentindices = {}
  220. math.randomseed(tick())
  221. local currentzone, zoneplayingmusic
  222. function CheckIfRecent(i)
  223. for _, v in pairs(recentindices) do
  224. if v == i then
  225. return true
  226. end
  227. end
  228. return false
  229. end
  230. function SelectRandomMusic(musiclist)
  231. if musiclist == nil or #musiclist == 0 then
  232. return
  233. end
  234. local possiblenumbers = {}
  235. local selectedindex
  236. for i = 1, #musiclist do
  237. if not CheckIfRecent(i) then
  238. table.insert(possiblenumbers, i)
  239. end
  240. end
  241. local selectedindex = possiblenumbers[math.random(1, #possiblenumbers)]
  242. table.insert(recentindices, selectedindex)
  243. if #recentindices > math.ceil(#musiclist / 2) then
  244. table.remove(recentindices, 1)
  245. end
  246. return musiclist[selectedindex]
  247. end
  248. function IsInZone(zonedata)
  249. if torso and torso.Parent ~= nil then
  250. local p = torso.Position
  251. for _, data in pairs(zonedata.Parts) do
  252. if data.Coordinates then
  253. local t = data.Coordinates
  254. if p.x > t.lx and p.x < t.mx and p.y > t.ly and p.y < t.my and p.z > t.lz and p.z < t.mz then
  255. return true
  256. end
  257. elseif data.Part then
  258. local part = data.Part:clone()
  259. part.Anchored = true
  260. part.Parent = workspace.CurrentCamera or workspace
  261. part.CanCollide = true
  262. local touching = part:GetTouchingParts()
  263. part:Destroy()
  264. for _, v in pairs(touching) do
  265. if v == torso then
  266. return true
  267. end
  268. end
  269. end
  270. end
  271. return false
  272. end
  273. end
  274. function CalculateCurrentZone()
  275. local priority = -math.huge
  276. local oldzone = currentzone
  277. local selectedzone
  278. if currentzone and IsInZone(currentzone) then
  279. selectedzone = currentzone
  280. priority = currentzone.Priority
  281. end
  282. for _, zone in pairs(zones) do
  283. if priority < zone.Priority and IsInZone(zone) then
  284. priority = zone.Priority
  285. selectedzone = zone
  286. end
  287. end
  288. currentzone = selectedzone
  289. if currentzone ~= oldzone and (currentzone ~= nil or settings.UseGlobalBackgroundMusic == true) then
  290. recentindices = {}
  291. end
  292. return currentzone, oldzone
  293. end
  294. function RunCycle()
  295. local bgm = script:FindFirstChild("BGM")
  296. if settings.UseMusicZones == true then
  297. local zone, oldzone = CalculateCurrentZone()
  298. if zone ~= oldzone and zone ~= zoneplayingmusic and bgm then
  299. if zone == nil and (settings.UseGlobalBackgroundMusic == true or settings.MusicOnlyPlaysWithinZones == true) or zone ~= nil then
  300. FadeOutSound(bgm)
  301. return
  302. end
  303. elseif zone and bgm == nil then
  304. PlaySound(SelectRandomMusic(zone.Music))
  305. zoneplayingmusic = zone
  306. return
  307. elseif zone == nil and oldzone and settings.MusicOnlyPlaysWithinZones == false and settings.UseGlobalBackgroundMusic == false and bgm == nil then
  308. PlaySound(SelectRandomMusic(oldzone.Music))
  309. zoneplayingmusic = oldzone
  310. return
  311. elseif zoneplayingmusic and settings.MusicOnlyPlaysWithinZones == false and settings.UseGlobalBackgroundMusic == false and bgm == nil then
  312. PlaySound(SelectRandomMusic(zoneplayingmusic.Music))
  313. return
  314. elseif settings.UseGlobalBackgroundMusic == true and bgm == nil then
  315. PlaySound(SelectRandomMusic(music[globali]))
  316. zoneplayingmusic = nil
  317. return
  318. end
  319. elseif bgm == nil and settings.UseGlobalBackgroundMusic == true then
  320. PlaySound(SelectRandomMusic(music[globali]))
  321. return
  322. end
  323. if bgm and settings.UseGlobalBackgroundMusic == true and zoneplayingmusic == nil and #music[globali] > 1 or zoneplayingmusic and #zoneplayingmusic.Music > 1 then
  324. local length = bgm.TimeLength
  325. local pos = bgm.TimePosition
  326. if length ~= 0 and length - pos < FadeoutTime + 0.5 then
  327. FadeOutSound(bgm)
  328. end
  329. end
  330. end
  331. while wait(0.5) do
  332. RunCycle()
  333. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement