Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I add more particles?

Asked by 10 years ago

I'm trying to fix this script up to where it acts as a blizzard and not going slow as it is currently. Here's the whole script.

local SnowLevels = { --[[ <-- Change the amount of snow. ]]--
    ["Light"] = false; --[[ <-- Barely any. ]]--
    ["Medium"] = false; --[[ <-- Some. ]]--
    ["Heavy"] = false; --[[ <-- A respectable amount. :P ]]--
    ["Blizzard"] = true; --[[ <-- Reccomended ]]--
}


local imgs = {"rbxassetid://18867938"}

local sp = script.Parent
local r = game:service("RunService")
local players = game:getService("Players")
local sl 
local rate
local vol

if SnowLevels.Light then 
    sl = 45
    vol = 0
elseif SnowLevels.Medium then 
    sl = 70
    vol = 0.10
elseif SnowLevels.Heavy then 
    sl = 95
    vol = 0.30
elseif SnowLevels.Blizzard then 
    sl = 120
    vol = 0.60
end

local q = Instance.new("Part")
    q.Transparency = 1
    q.Anchored = 0
    q.formFactor = Enum.FormFactor.Symmetric
    q.Size = Vector3.new(1, 1, 1)

function projection(vector, camera, size)
  local abs = math.abs
  local result = camera:toObjectSpace(vector)
  vector = result.p
  local rx, ry, rz = result:toEulerAnglesXYZ()
  if vector.z > 0 then return end
  local sizex = size/abs(vector.z)
  local sizey = sizex * abs(math.cos(rx))
  local sizex = sizex * abs(math.cos(ry))
  return -vector.x / vector.z, vector.y * 1.7071067811865 / vector.z, sizex, sizey
end

local face = Enum.NormalId.Bottom

function getdepth(v)
  local t = q:clone()
  t.Parent = workspace
  t.CFrame = CFrame.new(v)
  local s = 2^5
  local n = 1
  for i = 1, 5 do
    s = s * .5
    if t:Resize(face, s) then
      n = n + s
    end
  end
  t:Destroy()
  return n
end

local torso
local flakes = {}

function remove(flake)
  flake[1]:Destroy()
  flakes[flake] = nil
end

function getFlakes(Num)
    for i, v in pairs(flakes) do
        Num = Num+1
    end
    return Num
end

function spriteWork()
    local cz = script.Parent.AbsoluteSize
    local cx, cy = cz.x, cz.y
    for sprite in pairs(flakes) do
        sprite[2] = sprite[2] * CFrame.new(0, -.2, 0) * CFrame.Angles(0, .037699111843078, 0)
        if sprite[2].p.y < sprite[4] then
            sprite[1]:Destroy() sprite:remove()
        end
        local px, py, sx, sy = projection(sprite[2],workspace.CurrentCamera.CoordinateFrame, sprite[3])
        local label = sprite[1]
        if px and sx >= 1 and sy >= 1 then
            label.Visible = true
            label.Size = UDim2.new(0,sx,0,sy)
            label.Position = UDim2.new(0,((px + 1) * cx - sx) * .5,0,((py + 1) * cy - sy) * .5)
        else
            label.Visible = false
        end
    end
end

function spawn(char)
    for flake in pairs(flakes) do
        flake:Destroy()
    end
    while char.Parent do
        if getFlakes(0) < sl-10 then 
            for i = 1, sl-10 do
                r.Stepped:wait()
                if getFlakes(0) < sl-10 then 
                    local label = Instance.new("ImageLabel", sp)
                    label.Image = imgs[math.random(1, #imgs)]
                    label.BackgroundTransparency = 1
                    local dx, dz = (math.random() - .5) * 200, (math.random() - .5) * 200
                    local pos = char["Torso"].Position + Vector3.new(dx, (30 - math.random() * 20) * (1 - (dx^2 + dz^2)^.5/(1.4142135623731 * 100)) , dz)
                    local sphr = CFrame.new(Vector3.new(),Vector3.new(math.random()-.5,0,math.random()-.5)) + pos
                    local size = 20 * (math.random() * .75 + .25) * 10
                    local sprite = {label, sphr, size, pos.y - getdepth(pos), remove = remove}
                    local cz = sp.AbsoluteSize
                    local cx, cy = cz.x, cz.y
                    flakes[sprite] = 0
                    spriteWork()
                else
                    r.Stepped:wait()
                    spriteWork()
                    break
                end
            end
        else
            r.Stepped:wait()
            spriteWork()
        end
    end
end

repeat wait() until players.LocalPlayer.Character
spawn(players.LocalPlayer.Character)

I'm pretty sure the focus of it is around here.

function getdepth(v)
  local t = q:clone()
  t.Parent = workspace
  t.CFrame = CFrame.new(v)
  local s = 2^5
  local n = 1
  for i = 1, 5 do
    s = s * .5
    if t:Resize(face, s) then
      n = n + s
    end
  end
  t:Destroy()
  return n
end

local torso
local flakes = {}

function remove(flake)
  flake[1]:Destroy()
  flakes[flake] = nil
end

function getFlakes(Num)
    for i, v in pairs(flakes) do
        Num = Num+1
    end
    return Num
end

function spriteWork()
    local cz = script.Parent.AbsoluteSize
    local cx, cy = cz.x, cz.y
    for sprite in pairs(flakes) do
        sprite[2] = sprite[2] * CFrame.new(0, -.2, 0) * CFrame.Angles(0, .037699111843078, 0)
        if sprite[2].p.y < sprite[4] then
            sprite[1]:Destroy() sprite:remove()
        end
        local px, py, sx, sy = projection(sprite[2],workspace.CurrentCamera.CoordinateFrame, sprite[3])
        local label = sprite[1]
        if px and sx >= 1 and sy >= 1 then
            label.Visible = true
            label.Size = UDim2.new(0,sx,0,sy)
            label.Position = UDim2.new(0,((px + 1) * cx - sx) * .5,0,((py + 1) * cy - sy) * .5)
        else
            label.Visible = false
        end
    end
end

function spawn(char)
    for flake in pairs(flakes) do
        flake:Destroy()
    end
    while char.Parent do
        if getFlakes(0) < sl-10 then 
            for i = 1, sl-10 do
                r.Stepped:wait()
                if getFlakes(0) < sl-10 then 
                    local label = Instance.new("ImageLabel", sp)
                    label.Image = imgs[math.random(1, #imgs)]
                    label.BackgroundTransparency = 1
                    local dx, dz = (math.random() - .5) * 200, (math.random() - .5) * 200
                    local pos = char["Torso"].Position + Vector3.new(dx, (30 - math.random() * 20) * (1 - (dx^2 + dz^2)^.5/(1.4142135623731 * 100)) , dz)
                    local sphr = CFrame.new(Vector3.new(),Vector3.new(math.random()-.5,0,math.random()-.5)) + pos
                    local size = 20 * (math.random() * .75 + .25) * 10
                    local sprite = {label, sphr, size, pos.y - getdepth(pos), remove = remove}
                    local cz = sp.AbsoluteSize
                    local cx, cy = cz.x, cz.y
                    flakes[sprite] = 0
                    spriteWork()
                else
                    r.Stepped:wait()
                    spriteWork()
                    break
                end
            end
        else
            r.Stepped:wait()
            spriteWork()
        end
    end
end

I just don't know what to change and how to do it correctly. If you can just show me how to do so, don't have to write me the code, if you just show me where I need to work on I'd appreciate it!

Here's how the gui works. LINK: http://www.roblox.com/Test-place?id=153890092

Answer this question