Advertisement
rouyen

Untitled

Aug 15th, 2016
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.16 KB | None | 0 0
  1. --[[
  2. |----------------------------------------------|
  3. | %% %% %%%%%%%%%% |
  4. | %%%% %%%% %% |
  5. | MAD %% %%% %% %% %%%%% STUDIO |
  6. | %% %% %% %% |
  7. | %% %% %%%%%%%%%% 2015 |
  8. |-------------------Mad Games------------------|
  9.  
  10. -Type: radio appearance (Client)
  11. -Name: MG_RadioAppearance
  12. -Description: Manages the radio appearance on the character
  13. -Author: Laimonas Mileska (xxrouyenxx)
  14. -Date of creation: May 18th, 2015
  15. --]]
  16.  
  17. local Settings = {
  18. DefaultRadioTexture = "Default",
  19. DefaultRadioParticles = "Default",
  20.  
  21. RadioBouncePerc = 0.03,
  22. }
  23.  
  24. --Getting client data manager variables
  25. while not _G.ClientDataReady do wait() end
  26. local CLIENT_DATA = _G.CLIENT_DATA
  27.  
  28. --Common variables
  29. local player = game.Players.LocalPlayer
  30. local RenderStepped = game:GetService("RunService").RenderStepped
  31.  
  32. local game_content = game.ReplicatedStorage.GameContent
  33. local radio_items = game_content:FindFirstChild("Radio")
  34. local radio_textures = radio_items:FindFirstChild("Textures")
  35. local radio_particles = radio_items:FindFirstChild("Particles")
  36. local function FindObject(holder, key_element, sk_name)
  37. for _, obj in pairs(holder:GetChildren()) do
  38. if obj.Name == sk_name then
  39. if obj:FindFirstChild(key_element) ~= nil then
  40. return obj
  41. end
  42. end
  43. for _, obj2 in pairs(obj:GetChildren()) do
  44. if obj2.Name == sk_name then
  45. if obj2:FindFirstChild(key_element) ~= nil then
  46. return obj2
  47. end
  48. end
  49. end
  50. end
  51. return nil
  52. end
  53. local function GetAllObjects(holder, key_element)
  54. local result = {}
  55. for _, obj in pairs(holder:GetChildren()) do
  56. if obj:FindFirstChild(key_element) ~= nil then
  57. table.insert(result, obj)
  58. end
  59. for _, obj2 in pairs(obj:GetChildren()) do
  60. if obj2:FindFirstChild(key_element) ~= nil then
  61. table.insert(result, obj2)
  62. end
  63. end
  64. end
  65. return result
  66. end
  67.  
  68. --common functions
  69.  
  70. local function GetRadioTexture(tex_name)
  71. local get_tex = FindObject(radio_textures, "TextureShopData", tex_name)
  72. if get_tex == nil then
  73. get_tex = FindObject(radio_textures, "TextureShopData", Settings.DefaultRadioTexture)
  74. end
  75. return require(get_tex:FindFirstChild("TextureStyle"))
  76. end
  77.  
  78. local function GetRadioParticles(part_name)
  79. local get_part = FindObject(radio_particles, "ParticleShopData", part_name)
  80. if get_part == nil then
  81. get_part = FindObject(radio_particles, "ParticleShopData", Settings.DefaultRadioParticles)
  82. end
  83. return require(get_part:FindFirstChild("ParticleStyle"))
  84. end
  85.  
  86. local function CheckIfPlayingSound()
  87. local get_sounds = CLIENT_DATA.GetRadioSounds()
  88. for pnm, snd_dat in pairs(get_sounds) do
  89. if pnm == player.Name and snd_dat[2] then
  90. return true
  91. end
  92. end
  93. return false
  94. end
  95.  
  96. local function OwnsRadio()
  97. return CLIENT_DATA.OwnsGamePass("RadioPass")
  98. end
  99.  
  100. local function GenPart()
  101. local np = Instance.new("Part")
  102. np.TopSurface = 0; np.BottomSurface = 0;
  103. np.FormFactor = "Custom"; np.Size = Vector3.new(0.2, 0.2, 0.2);
  104. np.CanCollide = false;
  105. return np
  106. end
  107.  
  108. local function GenRadio(radio_dat)
  109. local npart = GenPart()
  110. npart.Material = radio_dat.Material
  111. npart.Transparency = radio_dat.Transparency
  112. npart.Reflectance = radio_dat.Reflectance
  113. npart.BrickColor = radio_dat.BrickColor
  114.  
  115. local nmesh = Instance.new("SpecialMesh")
  116. nmesh.MeshType = "FileMesh"
  117. nmesh.Scale = radio_dat.Scale
  118. nmesh.MeshId = radio_dat.Mesh
  119. nmesh.TextureId = radio_dat.Texture
  120. nmesh.Parent = npart
  121.  
  122. return npart, nmesh
  123. end
  124.  
  125. local function RadioBounce()
  126. local loop = (tick() * 2) - math.floor((tick() * 2))
  127. if loop < 0.3 then
  128. return math.sin(math.rad(180 * (loop / 0.3)))
  129. else
  130. return 0
  131. end
  132. end
  133.  
  134. --Radio updating
  135.  
  136. while true do --waiting till player buys the radio. yep. may take a while.
  137. if OwnsRadio() then break end
  138. wait(1)
  139. end
  140.  
  141. local CurrentTexture, CurrentParticle = "", ""
  142. local LastTexture, LastParticle = "", ""
  143.  
  144. local ParticleObject = nil
  145. local ParticlesRunning = false
  146. local RadioMesh = nil
  147. local InitialScale = nil
  148.  
  149. local CurrentCharacter, CurrentTorso = nil, nil
  150. local rad_p, part_p = nil, nil
  151. local CharacterDied = true
  152.  
  153. local function SetupRadio()
  154. if CurrentCharacter == nil or CurrentTorso == nil then return end
  155. if rad_p ~= nil then
  156. pcall(function()
  157. rad_p:destroy()
  158. end)
  159. end
  160. if part_p ~= nil then
  161. pcall(function()
  162. part_p:destroy()
  163. end)
  164. end
  165. local tex_obj = GetRadioTexture(CurrentTexture)
  166. local part_obj = GetRadioParticles(CurrentParticle)
  167.  
  168. rad_p, RadioMesh = GenRadio(tex_obj)
  169. InitialScale = RadioMesh.Scale
  170. local rad_w = Instance.new("Weld")
  171. rad_w.Name = "RadioWeld"
  172. rad_w.Part0 = CurrentTorso
  173. rad_w.Part1 = rad_p
  174. rad_w.C0 = tex_obj.Offset
  175.  
  176. rad_p.Parent = CurrentCharacter
  177. rad_w.Parent = CurrentTorso
  178.  
  179.  
  180. part_p = GenPart()
  181. part_p.Transparency = 1
  182. local part_w = Instance.new("Weld")
  183. part_w.Part0 = CurrentTorso
  184. part_w.Part1 = part_p
  185. part_w.C0 = CFrame.new(tex_obj.Offset.p) * CFrame.Angles(math.rad(90), 0, 0)
  186.  
  187. part_p.Parent = CurrentCharacter
  188. part_w.Parent = CurrentTorso
  189.  
  190.  
  191. ParticleObject = part_obj(part_p)
  192. end
  193.  
  194. local function UpdateRadioSelections()
  195. CurrentTexture = CLIENT_DATA.GetSelectedItem("radio_textures")
  196. CurrentParticle = CLIENT_DATA.GetSelectedItem("radio_particles")
  197. if LastTexture ~= CurrentTexture or LastParticle ~= CurrentParticle then
  198. if not CharacterDied then
  199. SetupRadio()
  200. end
  201. end
  202. LastTexture = CurrentTexture
  203. LastParticle = CurrentParticle
  204. end
  205. CLIENT_DATA.PlayerProfileChanged.Event:connect(UpdateRadioSelections)
  206. UpdateRadioSelections()
  207.  
  208. local g_char = player.Character
  209. if g_char ~= nil then
  210. local hum = g_char:FindFirstChild("Humanoid")
  211. local t = g_char:FindFirstChild("Torso")
  212. if hum ~= nil and t ~= nil then
  213. if hum.Health > 0 then
  214. CurrentCharacter = g_char
  215. CurrentTorso = t
  216. CharacterDied = false
  217. SetupRadio()
  218. end
  219. end
  220. end
  221. player.CharacterAdded:connect(function(char)
  222. local hum, t
  223. local start_wait = tick()
  224. while true do
  225. if tick() - start_wait > 10 then return end
  226. hum = char:FindFirstChild("Humanoid")
  227. t = char:FindFirstChild("Torso")
  228. if hum ~= nil and t ~= nil then
  229. break
  230. end
  231. wait()
  232. end
  233. if hum ~= nil and t ~= nil then
  234. if hum.Health > 0 then
  235. CurrentCharacter = char
  236. CurrentTorso = t
  237. CharacterDied = false
  238. SetupRadio()
  239. hum.Died:connect(function()
  240. CharacterDied = true
  241. if ParticlesRunning then
  242. ParticleObject.Stop()
  243. end
  244. end)
  245. end
  246. end
  247. end)
  248.  
  249. RenderStepped:connect(function()
  250. if not CharacterDied then
  251. if ParticleObject ~= nil then
  252. local is_playing = CheckIfPlayingSound()
  253. if is_playing and not ParticlesRunning then
  254. ParticleObject.Start()
  255. ParticlesRunning = true
  256. elseif not is_playing and ParticlesRunning then
  257. ParticleObject.Stop()
  258. ParticlesRunning = false
  259. end
  260. if is_playing then
  261. ParticleObject.Update()
  262. if RadioMesh ~= nil and InitialScale ~= nil then
  263. RadioMesh.Scale = InitialScale + InitialScale * Settings.RadioBouncePerc * RadioBounce()
  264. end
  265. else
  266. if RadioMesh ~= nil and InitialScale ~= nil then
  267. RadioMesh.Scale = InitialScale
  268. end
  269. end
  270. end
  271. end
  272. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement