Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- |----------------------------------------------|
- | %% %% %%%%%%%%%% |
- | %%%% %%%% %% |
- | MAD %% %%% %% %% %%%%% STUDIO |
- | %% %% %% %% |
- | %% %% %%%%%%%%%% 2015 |
- |-------------------Mad Games------------------|
- -Type: radio appearance (Client)
- -Name: MG_RadioAppearance
- -Description: Manages the radio appearance on the character
- -Author: Laimonas Mileska (xxrouyenxx)
- -Date of creation: May 18th, 2015
- --]]
- local Settings = {
- DefaultRadioTexture = "Default",
- DefaultRadioParticles = "Default",
- RadioBouncePerc = 0.03,
- }
- --Getting client data manager variables
- while not _G.ClientDataReady do wait() end
- local CLIENT_DATA = _G.CLIENT_DATA
- --Common variables
- local player = game.Players.LocalPlayer
- local RenderStepped = game:GetService("RunService").RenderStepped
- local game_content = game.ReplicatedStorage.GameContent
- local radio_items = game_content:FindFirstChild("Radio")
- local radio_textures = radio_items:FindFirstChild("Textures")
- local radio_particles = radio_items:FindFirstChild("Particles")
- local function FindObject(holder, key_element, sk_name)
- for _, obj in pairs(holder:GetChildren()) do
- if obj.Name == sk_name then
- if obj:FindFirstChild(key_element) ~= nil then
- return obj
- end
- end
- for _, obj2 in pairs(obj:GetChildren()) do
- if obj2.Name == sk_name then
- if obj2:FindFirstChild(key_element) ~= nil then
- return obj2
- end
- end
- end
- end
- return nil
- end
- local function GetAllObjects(holder, key_element)
- local result = {}
- for _, obj in pairs(holder:GetChildren()) do
- if obj:FindFirstChild(key_element) ~= nil then
- table.insert(result, obj)
- end
- for _, obj2 in pairs(obj:GetChildren()) do
- if obj2:FindFirstChild(key_element) ~= nil then
- table.insert(result, obj2)
- end
- end
- end
- return result
- end
- --common functions
- local function GetRadioTexture(tex_name)
- local get_tex = FindObject(radio_textures, "TextureShopData", tex_name)
- if get_tex == nil then
- get_tex = FindObject(radio_textures, "TextureShopData", Settings.DefaultRadioTexture)
- end
- return require(get_tex:FindFirstChild("TextureStyle"))
- end
- local function GetRadioParticles(part_name)
- local get_part = FindObject(radio_particles, "ParticleShopData", part_name)
- if get_part == nil then
- get_part = FindObject(radio_particles, "ParticleShopData", Settings.DefaultRadioParticles)
- end
- return require(get_part:FindFirstChild("ParticleStyle"))
- end
- local function CheckIfPlayingSound()
- local get_sounds = CLIENT_DATA.GetRadioSounds()
- for pnm, snd_dat in pairs(get_sounds) do
- if pnm == player.Name and snd_dat[2] then
- return true
- end
- end
- return false
- end
- local function OwnsRadio()
- return CLIENT_DATA.OwnsGamePass("RadioPass")
- end
- local function GenPart()
- local np = Instance.new("Part")
- np.TopSurface = 0; np.BottomSurface = 0;
- np.FormFactor = "Custom"; np.Size = Vector3.new(0.2, 0.2, 0.2);
- np.CanCollide = false;
- return np
- end
- local function GenRadio(radio_dat)
- local npart = GenPart()
- npart.Material = radio_dat.Material
- npart.Transparency = radio_dat.Transparency
- npart.Reflectance = radio_dat.Reflectance
- npart.BrickColor = radio_dat.BrickColor
- local nmesh = Instance.new("SpecialMesh")
- nmesh.MeshType = "FileMesh"
- nmesh.Scale = radio_dat.Scale
- nmesh.MeshId = radio_dat.Mesh
- nmesh.TextureId = radio_dat.Texture
- nmesh.Parent = npart
- return npart, nmesh
- end
- local function RadioBounce()
- local loop = (tick() * 2) - math.floor((tick() * 2))
- if loop < 0.3 then
- return math.sin(math.rad(180 * (loop / 0.3)))
- else
- return 0
- end
- end
- --Radio updating
- while true do --waiting till player buys the radio. yep. may take a while.
- if OwnsRadio() then break end
- wait(1)
- end
- local CurrentTexture, CurrentParticle = "", ""
- local LastTexture, LastParticle = "", ""
- local ParticleObject = nil
- local ParticlesRunning = false
- local RadioMesh = nil
- local InitialScale = nil
- local CurrentCharacter, CurrentTorso = nil, nil
- local rad_p, part_p = nil, nil
- local CharacterDied = true
- local function SetupRadio()
- if CurrentCharacter == nil or CurrentTorso == nil then return end
- if rad_p ~= nil then
- pcall(function()
- rad_p:destroy()
- end)
- end
- if part_p ~= nil then
- pcall(function()
- part_p:destroy()
- end)
- end
- local tex_obj = GetRadioTexture(CurrentTexture)
- local part_obj = GetRadioParticles(CurrentParticle)
- rad_p, RadioMesh = GenRadio(tex_obj)
- InitialScale = RadioMesh.Scale
- local rad_w = Instance.new("Weld")
- rad_w.Name = "RadioWeld"
- rad_w.Part0 = CurrentTorso
- rad_w.Part1 = rad_p
- rad_w.C0 = tex_obj.Offset
- rad_p.Parent = CurrentCharacter
- rad_w.Parent = CurrentTorso
- part_p = GenPart()
- part_p.Transparency = 1
- local part_w = Instance.new("Weld")
- part_w.Part0 = CurrentTorso
- part_w.Part1 = part_p
- part_w.C0 = CFrame.new(tex_obj.Offset.p) * CFrame.Angles(math.rad(90), 0, 0)
- part_p.Parent = CurrentCharacter
- part_w.Parent = CurrentTorso
- ParticleObject = part_obj(part_p)
- end
- local function UpdateRadioSelections()
- CurrentTexture = CLIENT_DATA.GetSelectedItem("radio_textures")
- CurrentParticle = CLIENT_DATA.GetSelectedItem("radio_particles")
- if LastTexture ~= CurrentTexture or LastParticle ~= CurrentParticle then
- if not CharacterDied then
- SetupRadio()
- end
- end
- LastTexture = CurrentTexture
- LastParticle = CurrentParticle
- end
- CLIENT_DATA.PlayerProfileChanged.Event:connect(UpdateRadioSelections)
- UpdateRadioSelections()
- local g_char = player.Character
- if g_char ~= nil then
- local hum = g_char:FindFirstChild("Humanoid")
- local t = g_char:FindFirstChild("Torso")
- if hum ~= nil and t ~= nil then
- if hum.Health > 0 then
- CurrentCharacter = g_char
- CurrentTorso = t
- CharacterDied = false
- SetupRadio()
- end
- end
- end
- player.CharacterAdded:connect(function(char)
- local hum, t
- local start_wait = tick()
- while true do
- if tick() - start_wait > 10 then return end
- hum = char:FindFirstChild("Humanoid")
- t = char:FindFirstChild("Torso")
- if hum ~= nil and t ~= nil then
- break
- end
- wait()
- end
- if hum ~= nil and t ~= nil then
- if hum.Health > 0 then
- CurrentCharacter = char
- CurrentTorso = t
- CharacterDied = false
- SetupRadio()
- hum.Died:connect(function()
- CharacterDied = true
- if ParticlesRunning then
- ParticleObject.Stop()
- end
- end)
- end
- end
- end)
- RenderStepped:connect(function()
- if not CharacterDied then
- if ParticleObject ~= nil then
- local is_playing = CheckIfPlayingSound()
- if is_playing and not ParticlesRunning then
- ParticleObject.Start()
- ParticlesRunning = true
- elseif not is_playing and ParticlesRunning then
- ParticleObject.Stop()
- ParticlesRunning = false
- end
- if is_playing then
- ParticleObject.Update()
- if RadioMesh ~= nil and InitialScale ~= nil then
- RadioMesh.Scale = InitialScale + InitialScale * Settings.RadioBouncePerc * RadioBounce()
- end
- else
- if RadioMesh ~= nil and InitialScale ~= nil then
- RadioMesh.Scale = InitialScale
- end
- end
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement