Advertisement
Descaii

Particle Emitter

Jul 24th, 2014
661
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 14.71 KB | None | 0 0
  1. --asd Emitter--
  2. if script.ClassName == "LocalScript" then
  3.     repeat wait() until game.Players.LocalPlayer.Character
  4.     game.Players.LocalPlayer.Character:WaitForChild("Head")
  5.     Mouse = game.Players.LocalPlayer:GetMouse()
  6.     Workspace.CurrentCamera:ClearAllChildren()
  7. end
  8. local Particles = {}
  9. local Emitters = {}
  10. FPS = 30
  11. function random(a,b)
  12.     seed = tick()
  13.     rick = rick and rick+1 or 1
  14.     return a+(b-a)*(seed*rick%1)
  15. end
  16. function ray(p1,p2)
  17.     local n = Ray.new(p1,p2)
  18.     local hit,pos = Workspace:findPartOnRay(n)
  19.     return hit,pos
  20. end
  21. function lerp(a,b,c)
  22.     return a+(b-a)*c
  23. end
  24. function NewParticleEmitter(Adornee)
  25.     local P = {}
  26.     P.LastEmit = tick()
  27.     P.EmitSpeed = 1
  28.     P.Adornee = Adornee
  29.     P.Image = 169845936
  30.     P.LifeTime = 2
  31.     P.Offset = Vector3.new(0,0,0)
  32.     P.Speed = CFrame.new(0,0,0)
  33.     P.OffVelocity = Vector3.new(0,0,0)
  34.     P.OnVelocity = Vector3.new(0,0,0)
  35.     P.Spread = Vector3.new(0,0,0)
  36.     P.Growth = Vector2.new(0,0)
  37.     P.ParticleSize = Vector2.new(1,1)
  38.     P.EmitSize = Vector3.new(0,0,0)
  39.     P.Rotation = 5
  40.     P.ConnectPower = 0
  41.     P.Dampen = 0
  42.     P.Velocity = Vector3.new(0,0,0)
  43.     P.LinearMultiplication = Vector3.new(0,0,0)
  44.     P.VerletMultiplication = false
  45.     P.Color = Color3.new(1,1,1)
  46.     P.ToColor = P.Color
  47.     P.PowerToMouse = 0
  48.     P.Replication = 0
  49.     function P:Emit(prop,pprop,gprop)
  50.         if P.Adornee then
  51.             local N = Instance.new("Part",script.ClassName == "LocalScript" and Workspace.CurrentCamera or P.Adornee)
  52.             N.FormFactor = "Custom"
  53.             N.Transparency = 1
  54.             N.Size = Vector3.new(0,0,0)
  55.             N.CFrame = P.Adornee.CFrame*CFrame.new(P.Offset)*CFrame.new(math.random(-P.EmitSize.X,P.EmitSize.X),math.random(-P.EmitSize.X,P.EmitSize.X),math.random(-P.EmitSize.X,P.EmitSize.X))
  56.             N.CanCollide = false
  57.             N.Anchored = true
  58.             local C = Instance.new("BillboardGui",N)
  59.             C.Size = UDim2.new(P.ParticleSize.X,0,P.ParticleSize.X,0)
  60.             local I = Instance.new("ImageLabel",C)
  61.             I.Rotation = math.random(0,360)
  62.             I.Size = UDim2.new(1,0,1,0)
  63.             I.Image = "http://www.roblox.com/asset/?id="..P.Image-1
  64.             I.BackgroundTransparency = 1
  65.             I.ImageColor3 = Color3.new(0,0,0)
  66.             local S = {}
  67.             S.Part = N
  68.             S.Board = C
  69.             S.Gui = I
  70.             S.Last = S.Part.CFrame.p
  71.             S.Direction = math.random(1,2)
  72.             S.Velocity = Vector3.new()
  73.             S.LifeTime =P.LifeTime
  74.             local H = N.CFrame*CFrame.new(P.Velocity)
  75.             local D = H.p-N.CFrame.p
  76.             ypcall(function()
  77.                 table.foreach(prop or {},function(a,b) S[a]=b end)
  78.             end)
  79.             S.Velocity = S.Velocity+D+Vector3.new(
  80.                 P.Spread.X > 0 and random(-P.Spread.X,P.Spread.X)/50 or 0,
  81.                 P.Spread.Y > 0 and random(-P.Spread.Y,P.Spread.Y)/50 or 0,
  82.                 P.Spread.Z > 0 and random(-P.Spread.Z,P.Spread.Z)/50 or 0
  83.             )
  84.             S.CreationDate = tick()
  85.             table.foreach(pprop or {},function(a,b) N[a]=b end)
  86.             table.foreach(gprop or {},function(a,b) S.Board[a]=b end)
  87.             function S:Update()
  88.                 local T = tick()-S.CreationDate
  89.                 local Age = (T/S.LifeTime)
  90.                 if T < S.LifeTime then
  91.                     S.Gui.Rotation = S.Gui.Rotation +(S.Direction == 1 and P.Rotation or -P.Rotation)
  92.                     local ic3 = S.Gui.ImageColor3
  93.                     S.Gui.ImageColor3 = Color3.new(lerp(P.Color.r,P.ToColor.r,Age),lerp(P.Color.g,P.ToColor.g,Age),lerp(P.Color.b,P.ToColor.b,Age))--Color3.new(ic3.r+0.02,ic3.g+0.02,ic3.b+0.02)
  94.                     S.Gui.ImageTransparency = (T/P.LifeTime)
  95.                     S.Part.CFrame = S.Part.CFrame*CFrame.new(P.Speed.X/(1/FPS),P.Speed.Y/(1/FPS),P.Speed.Z/(1/FPS))
  96.                     S.Velocity = S.Velocity +(((P.Adornee.CFrame.p+P.Offset)-(S.Part.CFrame.p))*P.ConnectPower)
  97.                     S.Velocity = S.Velocity +(P.OffVelocity/(1/FPS))
  98.                     S.Velocity = S.Velocity +(P.OnVelocity/(1/FPS))
  99.                     S.Velocity = S.Velocity-(S.Velocity*P.Dampen)
  100.                     S.Velocity = S.Velocity+(S.Velocity*P.LinearMultiplication)
  101.                     S.Velocity = S.Velocity+(-(S.Part.CFrame.p-(Mouse.Hit.p or S.Part.CFrame.p)).unit*(P.PowerToMouse/(1/FPS)))
  102.                     FakeVel = S.Velocity
  103.                 --      FakeVel = Vector3.new(unpack(FakeVel))
  104.                     S.Part.CFrame = S.Part.CFrame+FakeVel
  105.                     if P.VerletMultiplication then
  106.                         S.Velocity = S.Velocity+(S.Part.CFrame.p-S.Last)
  107.                     end
  108.                     S.Board.Size = S.Board.Size +UDim2.new(P.Growth.X/(1/FPS),0,P.Growth.Y/(1/FPS),0)
  109.                     --S.Gui.Position = UDim2.new(-(S.Gui.Size.X.Scale-1)/4,0,-(S.Gui.Size.Y.Scale-1)/4,0)
  110.                     S.Last = S.Part.CFrame.p
  111.                     if (tick()-S.CreationDate)%P.Replication<0.01 then
  112.                         --print'hax'
  113.                         wait(1)
  114.                         P:Emit({Velocity = S.Velocty,LifeTime=S.LifeTime*0.2},{CFrame=S.Part.CFrame},{Size = S.Board.Size-UDim2.new(0.5,0,0.5,0)})
  115.                         for i,v in pairs(Particles) do
  116.                             if v == S then
  117.                                 table.remove(Particles,i)
  118.                             end
  119.                         end
  120.                         N:Destroy()
  121.                     end
  122.                 else
  123.                     for i,v in pairs(Particles) do
  124.                         if v == S then
  125.                             table.remove(Particles,i)
  126.                         end
  127.                     end
  128.                     N:Destroy()
  129.                 end
  130.             end
  131.             table.insert(Particles,S)
  132.             return S
  133.         end
  134.     end
  135.     function P:Update()
  136.         if tick()-P.LastEmit > 1/P.EmitSpeed then
  137.             P.LastEmit = tick()
  138.             P:Emit()
  139.         end
  140.     end
  141.     table.insert(Emitters,P)
  142.     return P
  143. end
  144.  
  145. local C = NewParticleEmitter(game.Players.LocalPlayer.Character:WaitForChild("Torso"))
  146. local Types = {}
  147. Types.Default = function()
  148.     C.EmitSpeed = 10
  149.     C.ParticleSize = Vector2.new(2,2)
  150.     C.Offset = Vector3.new(0,5,0)
  151.     C.Speed = CFrame.new(0,0,0)
  152.     C.Velocity = Vector3.new(0,0.6,0)
  153.     C.Spread = Vector3.new(10,0,10)
  154.     C.OnVelocity = Vector3.new(0,-0.4,0)
  155.     C.OffVelocity = Vector3.new(0,0,0)
  156.     --C.Growth = Vector2.new(-0.02,-0.02)
  157.     C.EmitSize = Vector3.new(0,0,0)
  158.     C.Rotation = 5
  159.     C.ConnectPower = 0
  160.     C.Dampen = 0.02
  161.     C.LifeTime = 8
  162.     C.Image = 169845936
  163.     C.Growth = Vector2.new(0,0)
  164. end
  165.  
  166. Types.Smoke = function()
  167.     C.OnVelocity = Vector3.new(0,-0.01,0)
  168.     C.Image = 122434486
  169.     C.Spread = Vector3.new(1,1,1)
  170.     C.Growth = Vector2.new(5,5)
  171.     C.Velocity = Vector3.new(0,0.2,0)
  172.     C.LifeTime = 8
  173.     C.Dampen = 0
  174. end
  175.  
  176.  
  177. Types.Default()
  178. function gt(s,m,b)
  179.     local n = {}
  180.     local curr = ""
  181.     for i = 1,#s do
  182.         local t = string.sub(s,i,i)
  183.         if t:match(m) then
  184.             n[#n+1]=curr
  185.             curr = ""
  186.         else
  187.             if not t:match(b) then
  188.                 curr = curr..t
  189.             end
  190.             if i == #s then
  191.                 n[#n+1]=curr
  192.             end
  193.         end
  194.     end
  195.     return n
  196. end
  197. local Player = game.Players.LocalPlayer
  198. local Mouse = Player:GetMouse()
  199. local PlayerGui = Player:WaitForChild("PlayerGui")
  200. local Screen = Instance.new("ScreenGui",PlayerGui)
  201. local Count = 0
  202. local Allow = {
  203.     ["Vector3"]=true;
  204.     ["CFrame"]=true;
  205.     ["tick"]=true;
  206.     ["Vector2"]=true;
  207. }
  208. local MX = 0
  209. local UI = {}
  210. local PBX = Instance.new("Frame",Screen)
  211. PBX.Size = UDim2.new(0,500,0,0)
  212. PBX.Position = UDim2.new(0,0.5,0,0)
  213. PBX.Active = true
  214. PBX.Draggable = true
  215. PBX.ClipsDescendants = false
  216. PBX.BackgroundColor3 = Color3.new(0.3,0.3,0.3)
  217. PBX.BorderColor3 = Color3.new(0.2,0.2,0.2)
  218. PBX.BorderSizePixel = 5
  219. for i,v in pairs(C) do
  220.     if type(v) ~= "function" and type(v) ~= "table" then
  221.         local IsPart = pcall(function() return v.Position  end)
  222.         local T = Instance.new("TextLabel",PBX)
  223.         T.Text = i ~= 1 and tostring(i) or "Info"
  224.         T.Size = UDim2.new(0,T.TextBounds.X,0,20)
  225.         T.Position = UDim2.new(0,0,0,Count*20)
  226.         T.BorderColor3 = PBX.BorderColor3
  227.         T.BorderSizePixel = 2
  228.         T.BackgroundColor3 = Color3.new(0.3,0.3,0.3)
  229.         T.TextColor3 = IsPart and Color3.new(0.5,0.5,0.5) or Color3.new(1,1,1)
  230.         if MX-10 < T.TextBounds.X then
  231.             MX = T.TextBounds.X+10
  232.         else
  233.             T.Size = UDim2.new(0,MX,0,20)
  234.         end
  235.         local N = Instance.new(i ~= 1 and (not IsPart) and "TextBox" or "TextLabel",PBX)
  236.         N.Text = not pcall(function() return v.r end) and " "..tostring(v) or " "..(math.floor(255*v.r)..", "..math.floor(255*v.g)..", "..math.floor(255*v.b))
  237.         N.Size = UDim2.new(1,-MX,0,20)
  238.         N.Position = UDim2.new(0,MX,0,Count*20)
  239.         N.BorderColor3 = PBX.BorderColor3
  240.         N.BorderSizePixel = T.BorderSizePixel
  241.         N.BackgroundColor3 = T.BackgroundColor3
  242.         N.TextColor3 = T.TextColor3
  243.         N.TextXAlignment = "Left"
  244.         N.ClipsDescendants = true
  245.         --[[if v.X and v.Y and v.Z then
  246.             N.FocusLost:connect(function()
  247.                 if S
  248.             end)
  249.         end]]
  250.         if N.ClassName == "TextBox" then
  251.             N.FocusLost:connect(function()
  252.                 --[[local test,er = loadstring("return "..N.Text)
  253.                 local asd
  254.                 if test then
  255.                     setfenv(test,setmetatable({},{__index = function(a,b) if Allow[b] then return getfenv()[b] end end,
  256.                     __newindex = function(a,b,c) if Allow[b] then getfenv()[b]=c return getfenv()[b] end end}))
  257.                     p,d = ypcall(function()
  258.                         asd = test()
  259.                     end)
  260.                     if p and asd and type(asd) == type(C[i]) then
  261.                         C[i]=asd
  262.                     else
  263.                         if not p then
  264.                             --print(d)
  265.                         end
  266.                     end
  267.                 end]]
  268.                 local STR
  269.                 local EQ = C[i]
  270.                 u,h = ypcall(function()
  271.                     local v = EQ
  272.                     local T = gt(N.Text,","," ")
  273.                     local tn = tonumber
  274.                     --print(unpack(T))
  275.                     if type(v) ~= "number" and pcall(function() return v.X end) and pcall(function() return v.Y end) and pcall(function() return v.Z end) and pcall(function() return v.toEulerAnglesXYZ end) then
  276.                         EQ = CFrame.new(unpack(T))
  277.                     elseif type(v) ~= "number" and pcall(function() return v.X end) and pcall(function() return v.Y end) and pcall(function() return v.Z end) then
  278.                         EQ = Vector3.new(tn(T[1]),tn(T[2]),tn(T[3]))
  279.                     elseif type(v) ~= "number" and pcall(function() return v.X end) and pcall(function() return v.Y end) and not pcall(function() return v.Z end) then
  280.                         EQ = Vector2.new(tn(T[1]),tn(T[2]))
  281.                     elseif pcall(function() return v.r end) and pcall(function() return v.g end) and pcall(function() return v.b end) then
  282.                         EQ = Color3.new(tn(T[1])/255,tn(T[2])/255,tn(T[3])/255)
  283.                         STR = (math.floor(255*EQ.r)..", "..math.floor(255*EQ.g)..", "..math.floor(255*EQ.b))
  284.                     elseif type(v) == "number" and T[1] and tonumber(T[1]) and #T == 1 then
  285.                         EQ = tonumber(T[1])
  286.                     elseif type(v) == "boolean"and T[1] then
  287.                         EQ = (string.lower(T[1]) == "true" and true) or (string.lower(T[1]) == "false" and false)
  288.                     end
  289.                     C[i]= EQ
  290.                 end)
  291.                 if not u then print(h) end
  292.                 if not pcall(function() return v.r end) then
  293.                     N.Text = " "..(STR or tostring(C[i]))
  294.                 else
  295.                     if not u then
  296.                         N.Text = " "..(math.floor(255*EQ.r)..", "..math.floor(255*EQ.g)..", "..math.floor(255*EQ.b))
  297.                     else
  298.                         N.Text = " "..(STR or tostring(C[i]))
  299.                     end
  300.                 end
  301.             end)
  302.         end
  303.         local HX = {}
  304.         HX.NM = T
  305.         HX.BX = N
  306.         HX.TP = i
  307.         HX.OB = v
  308.         for _,p in pairs(UI) do
  309.             p.NM.Size = T.Size
  310.             p.BX.Size = N.Size
  311.             p.BX.Position = UDim2.new(0,MX,p.BX.Position.Y.Scale,p.BX.Position.Y.Offset)
  312.         end
  313.         table.insert(UI,HX)
  314.         Count = Count+1
  315.         PBX.Size = UDim2.new(0,500,0,(Count*20))
  316.         PBX.Position = UDim2.new(1,-500,1,-Count*20)
  317.     end
  318. end
  319. local Minimized = false
  320. --print("making min gui")
  321. local Min = Instance.new("TextButton",PBX)
  322. Min.Position = UDim2.new(0,0,0,-(20+PBX.BorderSizePixel))
  323. Min.Size = UDim2.new(0,50,0,20)
  324. Min.ZIndex = 3
  325. Min.BackgroundTransparency = PBX.BackgroundTransparency
  326. Min.TextColor3 = Color3.new(1,1,1)
  327. Min.BackgroundColor3 = PBX.BackgroundColor3
  328. Min.BorderSizePixel = PBX.BorderSizePixel
  329. Min.BorderColor3 = PBX.BorderColor3
  330. Min.Text = "Minimize"
  331. local Max = Min:clone()
  332. Max.Parent = Screen
  333. Max.Position = UDim2.new(1,0,1,0)-(Min.Size+UDim2.new(0,10,0,10))
  334. Max.Text = "Maximize"
  335. Max.Visible = false
  336. function Set()
  337.     if not Minimized then
  338.         Minimized = true
  339.         Max.Visible = true
  340.         PBX.Visible = false
  341.     else
  342.         Minimized = false
  343.         Max.Visible = false
  344.         PBX.Visible = true
  345.     end
  346. end
  347. Min.MouseButton1Click:connect(Set)
  348. Max.MouseButton1Click:connect(Set)
  349. local NMB = 0
  350. for i,v in pairs(Types) do
  351.     local NEW = Min:clone()
  352.     NEW.Parent = PBX
  353.     NEW.Text = i
  354.     NEW.Size = UDim2.new(0,MX-2,0,20)
  355.     NEW.Position = UDim2.new(0,Min.Position.X.Offset+5+(Min.Size.X.Offset+(MX-2+5)*NMB),0,Min.Position.Y.Offset)
  356.     NEW.MouseButton1Click:connect(function()
  357.         v()
  358.         for i,v in pairs(UI) do
  359.             if not pcall(function() return v.OB.r end) then
  360.                 v.BX.Text = " "..tostring(C[v.TP])
  361.             else
  362.                 v.BX.Text = " "..(math.floor(255*C[v.TP].r)..", "..math.floor(255*C[v.TP].g)..", "..math.floor(255*C[v.TP].b))
  363.             end
  364.         end
  365.     end)
  366.     NMB = NMB+1
  367. end
  368. local Last = tick()
  369. game:GetService("RunService").Stepped:connect(function()
  370.     FPS = tick()-Last
  371.     for i,v in pairs(Emitters) do
  372.         v:Update()
  373.     end
  374.     for i,v in pairs(Particles) do
  375.         v:Update()
  376.     end
  377.     --[[for i,v in pairs(UI) do
  378.         v.BX.Size = UDim2.new(0,v.BX.TextBounds.X+20,0,20)
  379.     end]]
  380.     Last = tick()
  381. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement