Advertisement
Guest User

ssss

a guest
Feb 13th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.34 KB | None | 0 0
  1.  
  2. local Vector = {}
  3. local EventHandler = {}
  4. local Particle = {}
  5. local Run = {}
  6. local ParticleStep = nil
  7. local LocalPlayer = game.Players.LocalPlayer
  8. local cos = math.cos
  9. do
  10. local sin = math.sin
  11. local random = math.random
  12. local tau = 2 * math.pi
  13. local v3 = Vector3.new
  14. local Dot = v3().Dot
  15. Vector.RandomUnit = function(t)
  16. local r = (1 - (t and cos(t) or -1)) * random() - 1
  17. local a = random() * tau
  18. local s = 1 - r * r ^ 0.5
  19. return v3(sin(a) * s, cos(a) * s, r)
  20. end
  21.  
  22. Vector.Random = function(t)
  23. local r = (1 - (t and cos(t) or -1)) * random() - 1
  24. local a = random() * tau
  25. local s = 1 - r * r ^ 0.5 * random() ^ 0.33333333333333
  26. return v3(sin(a) * s, cos(a) * s, r)
  27. end
  28.  
  29. Vector.Lerp = function(v0, v1, t)
  30. return v0 + (v1 - v0) * t
  31. end
  32.  
  33. Vector.Slerp = function(v0, v1, t)
  34. return v0 + (v1 - v0) * t
  35. end
  36.  
  37. Vector.Constrain = function(v, c, r)
  38. local rv = v - c
  39. if r < rv.magnitude then
  40. return c + rv.unit * r
  41. else
  42. return v
  43. end
  44. end
  45.  
  46. Vector.ClosestPointOnLineSegment = function(a, b, p)
  47. local l = b - a
  48. local u, m = l.unit, l.magnitude
  49. local d = Dot(u, p - a)
  50. if m < d then
  51. return a + l
  52. else
  53. if d < 0 then
  54. return a
  55. else
  56. return a + u * d
  57. end
  58. end
  59. end
  60.  
  61. Vector.ClosestPointOnDirection = function(d, p)
  62. local u = d.unit
  63. return u * Dot(u, p)
  64. end
  65.  
  66. end
  67. local insert = table.insert
  68. local remove = table.remove
  69. do
  70. local setmetatable = setmetatable
  71. EventHandler.New = function()
  72. local AddQueue = {}
  73. local RemoveQueue = {}
  74. local Connections = {}
  75. local Remove = function(self)
  76. RemoveQueue[self] = true
  77. end
  78.  
  79. return {Connect = function(Function)
  80. local Connection = {Function = Function, Disabled = false, Remove = Remove}
  81. AddQueue[#AddQueue + 1] = Connection
  82. return Connection
  83. end
  84. , Fire = function(...)
  85. local InitialCount = #Connections
  86. for i = 1, #AddQueue do
  87. Connections[InitialCount + i] = AddQueue[i]
  88. AddQueue[i] = nil
  89. end
  90. local Setback = 0
  91. for i = 1, #Connections do
  92. local f = Connections[i - Setback]
  93. if f then
  94. if RemoveQueue[f] then
  95. remove(Connections, i - Setback)
  96. Setback = Setback + 1
  97. RemoveQueue[f] = nil
  98. else
  99. if not f.Disabled then
  100. f.Function(...)
  101. end
  102. end
  103. else
  104. break
  105. end
  106. end
  107. end
  108. }
  109. end
  110.  
  111. local setmetatable = setmetatable
  112. local atan2 = math.atan2
  113. local degrees = math.pi / 180
  114. local remove = table.remove
  115. local tan = math.tan
  116. local Workspace = game.Workspace
  117. local v3 = Vector3.new
  118. local Ray = Ray.new
  119. local RayCast = Workspace.FindPartOnRay
  120. local ud2 = UDim2.new
  121. local PlayerCamera = Workspace.CurrentCamera
  122. local components = CFrame.new().components
  123. local Screen = Instance.new("ScreenGui", LocalPlayer.PlayerGui)
  124. local RemoveQueue = {}
  125. local UpdateFunctions = {}
  126. local ReserveFrames = {}
  127. local PlaneY, PlaneX, ScreenCorrection, PixelSize, CameraPosition = nil, nil, nil, nil, nil
  128. local cx, cy, cz, cxx, cyx, czx, cxy, cyy, czy, cxz, cyz, czz = 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1
  129. Particle.New = function(Position)
  130. local px, py, pz = 0, 0, 0
  131. if Position then
  132. px = Position.x
  133. end
  134. local vx, vy, vz = 0, 0, 0
  135. local WindResistance = 0.2
  136. local CanCollide = true
  137. local Elasticity = 0.3
  138. local Gravity = -196.2
  139. local llx = (px - cx) * cxx + (py - cy) * cxy + (pz - cz) * cxz
  140. local lly = (px - cx) * cyx + (py - cy) * cyy + (pz - cz) * cyz
  141. local llz = -(px - cx) * czx - (py - cy) * czy - (pz - cz) * czz
  142. local Size = 0.2
  143. local Brightness = 1
  144. local Bloom = 2
  145. local Culling = true
  146. local MaxViewDistance = 1000
  147. local Life = false
  148. local Replicated = false
  149. local Interface, OnCollide, Frame = nil, nil, nil
  150. if #ReserveFrames > 0 then
  151. Frame = ReserveFrames[#ReserveFrames]
  152. ReserveFrames[#ReserveFrames] = nil
  153. else
  154. Frame = Instance.new("Frame", Screen)
  155. Frame.BorderSizePixel = 0
  156. end
  157. local Visible = false
  158. local Color = Color3.new(1, 1, 1)
  159. Frame.BackgroundColor3 = Color
  160. local Update = function(dt)
  161. if (Life and Life < tick()) or py < -500 then
  162. Frame.Visible = false
  163. ReserveFrames[#ReserveFrames + 1] = Frame
  164. RemoveQueue[l_0_8_r26] = true
  165. else
  166. local v = vx * vx + vy * vy + vz * vz ^ 0.5
  167. local w = 2 / (2 + dt * WindResistance / 1024 * v)
  168. if CanCollide then
  169. local Part, Position, Normal = RayCast(Workspace, Ray(v3(px, py, pz), v3(vx * dt, vy * dt, vz * dt)))
  170. if Part then
  171. local nx, ny, nz = Normal.x, Normal.y, Normal.z
  172. local vn = vx * nx + vy * ny + vz * nz
  173. local d = (1 + Elasticity) * vn
  174. if vn < 1 or vn > 100 then
  175. px = Position.x + nx / 256
  176. end
  177. vx = vx * w - d * nx
  178. if OnCollide then
  179. if OnCollide == "Remove" then
  180. Life = 0
  181. else
  182. OnCollide(Interface, Part, Position, Normal)
  183. end
  184. end
  185. else
  186. do
  187. do
  188. px = px + vx * dt
  189. vx = vx * w
  190. px = px + vx * dt
  191. vx = vx * w
  192. local rx, ry, rz = px - cx, py - cy, pz - cz
  193. local clx = rx * cxx + ry * cxy + rz * cxz
  194. local cly = rx * cyx + ry * cyy + rz * cyz
  195. local clz = -rx * czx - ry * czy - rz * czz
  196. local CurrentTest = clz > 1
  197. do
  198. local LastTest = llz > 1
  199. if Brightness > 0 and clz < MaxViewDistance and (CurrentTest or LastTest) then
  200. local u0x, u0y, u1x, u1y = nil, nil, nil, nil
  201. if CurrentTest and not LastTest then
  202. local d = (1 - llz) / (clz - llz)
  203. u0x = llx + d * (clx - llx)
  204. u1x = clx / clz
  205. elseif not CurrentTest and LastTest then
  206. local d = (1 - llz) / (clz - llz)
  207. -- DECOMPILER ERROR at PC279: Overwrote pending register: R12 in 'AssignReg'
  208.  
  209. u0x = llx + d * (clx - llx)
  210. -- DECOMPILER ERROR at PC286: Overwrote pending register: R14 in 'AssignReg'
  211.  
  212. u1x = llx / llz
  213. else
  214. -- DECOMPILER ERROR at PC290: Overwrote pending register: R12 in 'AssignReg'
  215.  
  216. u0x = clx / clz
  217. -- DECOMPILER ERROR at PC297: Overwrote pending register: R14 in 'AssignReg'
  218.  
  219. u1x = llx / llz
  220. end
  221. local p0x, p0y = (PlaneX + u0x * ScreenCorrection) * PixelSize, (PlaneY - (u0y)) * PixelSize * ScreenCorrection
  222. local p1x, p1y = (PlaneX + u1x * ScreenCorrection) * PixelSize, (PlaneY - u1y) * PixelSize * ScreenCorrection
  223. local dx, dy = p1x - p0x, p1y - p0y
  224. local Length = dx * dx + dy * dy ^ 0.5
  225. local s = Size / (llz < clz and clz or llz) * PixelSize
  226. local sx, sy = Length + s + Bloom, s + Bloom
  227. local Transparency = 1 - Brightness * s * s / (sx * sy)
  228. if Transparency < 0.99 and sy > 1 and (not Culling or not RayCast(Workspace, Ray(CameraPosition, v3(px - cx, py - cy, pz - cz)))) then
  229. if not Visible then
  230. Frame.Visible = true
  231. Visible = true
  232. end
  233. Frame.Position = ud2(0, (p0x + p1x - sx) / 2, 0, (p0y + p1y - sy) / 2)
  234. Frame.Size = ud2(0, sx, 0, sy)
  235. Frame.Transparency = Transparency
  236. local Rotation = atan2(dy, dx) / degrees
  237. if Rotation ~= 0 then
  238. Frame.Rotation = Rotation
  239. end
  240. elseif Visible then
  241. Frame.Visible = false
  242. Visible = false
  243. end
  244. elseif Visible then
  245. Frame.Visible = false
  246. Visible = false
  247. end
  248. -- DECOMPILER ERROR at PC432: Overwrote pending register: R12 in 'AssignReg'
  249.  
  250. llx = clx
  251. -- DECOMPILER ERROR: 14 unprocessed JMP targets
  252. end
  253. end
  254. end
  255. end
  256. end
  257. end
  258. end
  259.  
  260. UpdateFunctions[#UpdateFunctions + 1] = Update
  261. Interface = setmetatable({ReplicateToServer = function()
  262. if not Replicated then
  263. Replicated = true
  264. end
  265. end
  266. , Remove = function()
  267. Life = 0
  268. Interface.Remove = nil
  269. end
  270. }, {__index = function(_, Index)
  271. if Index == "Position" then
  272. return v3(px, py, pz)
  273. else
  274. if Index == "Velocity" then
  275. return v3(vx, vy, vz)
  276. else
  277. if Index == "WindResistance" then
  278. return WindResistance
  279. else
  280. if Index == "CanCollide" then
  281. return CanCollide
  282. else
  283. if Index == "Elasticity" then
  284. return Elasticity
  285. else
  286. if Index == "Gravity" then
  287. return Gravity
  288. else
  289. if Index == "Size" then
  290. return Size
  291. else
  292. if Index == "Brightness" then
  293. return Brightness
  294. else
  295. if Index == "Bloom" then
  296. return Bloom
  297. else
  298. if Index == "Color" then
  299. return Color
  300. else
  301. if Index == "Culling" then
  302. return Culling
  303. else
  304. if Index == "MaxViewDistance" then
  305. return MaxViewDistance
  306. else
  307. if Index == "Life" then
  308. return Life - tick()
  309. end
  310. end
  311. end
  312. end
  313. end
  314. end
  315. end
  316. end
  317. end
  318. end
  319. end
  320. end
  321. end
  322. end
  323. , __newindex = function(_, Index, Value)
  324. if Index == "Position" then
  325. px = Value.x
  326. else
  327. if Index == "Velocity" then
  328. vx = Value.x
  329. else
  330. if Index == "WindResistance" then
  331. WindResistance = Value
  332. else
  333. if Index == "CanCollide" then
  334. CanCollide = Value
  335. else
  336. if Index == "Elasticity" then
  337. Elasticity = Value
  338. else
  339. if Index == "Gravity" then
  340. Gravity = Value
  341. else
  342. if Index == "Size" then
  343. Size = Value
  344. else
  345. if Index == "Brightness" then
  346. Brightness = Value
  347. else
  348. if Index == "Bloom" then
  349. Bloom = Value
  350. else
  351. if Index == "Color" then
  352. Color = Value
  353. else
  354. if Index == "Culling" then
  355. Culling = Value
  356. else
  357. if Index == "MaxViewDistance" then
  358. MaxViewDistance = Value
  359. else
  360. if Index == "Life" then
  361. Life = tick() + Value
  362. else
  363. if Index == "OnCollide" then
  364. OnCollide = Value
  365. end
  366. end
  367. end
  368. end
  369. end
  370. end
  371. end
  372. end
  373. end
  374. end
  375. end
  376. end
  377. end
  378. end
  379. end
  380. })
  381. return Interface
  382. end
  383.  
  384. do
  385. local Counter = 0
  386. ParticleStep = function(dt)
  387. local ScreenSize = Screen.AbsoluteSize
  388. local ScreenY, ScreenX = ScreenSize.y, ScreenSize.x
  389. PlaneY = tan(degrees * PlayerCamera.FieldOfView / 2)
  390. PlaneX = PlaneY * ScreenX / ScreenY
  391. PixelSize = ScreenY / PlaneY / 2
  392. ScreenCorrection = ScreenY / (ScreenY - 20)
  393. CameraPosition = PlayerCamera.CoordinateFrame.p
  394. cx = components(PlayerCamera.CoordinateFrame)
  395. for R7_PC39 = 1, #UpdateFunctions do
  396. R8_PC38 = UpdateFunctions
  397. R8_PC38 = R8_PC38[i]
  398. R9_PC37 = dt
  399. R8_PC38(R9_PC37)
  400. end
  401. -- DECOMPILER ERROR at PC53: Confused about usage of register R6 for local variables in 'ReleaseLocals'
  402.  
  403. Counter = Counter % 60 + 1
  404. if Counter == 60 then
  405. print("Particles: " .. #UpdateFunctions)
  406. end
  407. for i = #UpdateFunctions, 1, -1 do
  408. local l_0_9_10, i = nil
  409. l_0_9_10 = UpdateFunctions
  410. l_0_9_10 = l_0_9_10[l_0_9_9]
  411. local f = nil
  412. if l_0_9_10 then
  413. i = RemoveQueue
  414. i = i[l_0_9_10]
  415. if i then
  416. i = remove
  417. f = UpdateFunctions
  418. R11_PC35 =
  419. i(f, R11_PC35)
  420. i = RemoveQueue
  421. i[l_0_9_10] = nil
  422. end
  423. end
  424. end
  425. -- DECOMPILER ERROR at PC86: Confused about usage of register R5 for local variables in 'ReleaseLocals'
  426.  
  427. end
  428.  
  429. local insert = table.insert
  430. local remove = table.remove
  431. local setmetatable = setmetatable
  432. local tick = tick
  433. local RenderStepped = game:GetService("RunService").RenderStepped
  434. local AddQueue = {}
  435. local RemoveQueue = {}
  436. local Functions = {}
  437. local Time = tick()
  438. do
  439. local Remove = function(self)
  440. RemoveQueue[self] = true
  441. end
  442.  
  443. Run.Add = function(Function)
  444. local RunObject = {Function = Function, Paused = false, Remove = Remove}
  445. AddQueue[#AddQueue + 1] = RunObject
  446. return RunObject
  447. end
  448.  
  449. RenderStepped:connect(function()
  450. local dt = tick() - Time
  451. Time = Time + dt
  452. ParticleStep(dt)
  453. local InitialCount = #Functions
  454. for i = 1, #AddQueue do
  455. Functions[InitialCount + i] = AddQueue[i]
  456. AddQueue[i] = nil
  457. end
  458. local Setback = 0
  459. for i = 1, #Functions do
  460. local f = Functions[i - Setback]
  461. if f then
  462. if RemoveQueue[f] then
  463. remove(Functions, i - Setback)
  464. Setback = Setback + 1
  465. RemoveQueue[f] = nil
  466. else
  467. if not f.Paused then
  468. f.Function(dt)
  469. end
  470. end
  471. else
  472. break
  473. end
  474. end
  475. end
  476. )
  477. while 1 do
  478. wait(0.5)
  479. local Stuff = game.Players.LocalPlayer.Character.Head.CFrame
  480. local c = Particle.New(Stuff.p)
  481. c.Velocity = Stuff.lookVector * 100 + Vector3.new(0, 200, 0)
  482. c.Brightness = 10
  483. c.Size = 1
  484. c.OnCollide = function(_, _, Position, Normal)
  485. local RandColor = Color3.new(1 - math.random() ^ 2, 1 - math.random() ^ 2, 1 - math.random() ^ 2)
  486. for i = 1, 100 do
  487. local Blah = Particle.New(Position)
  488. Blah.Life = math.random() * 5
  489. Blah.Brightness = math.random() * 5 + 10
  490. Blah.Size = math.random() * 0.5 + 0.05
  491. Blah.MaxViewDistance = 720
  492. Blah.Culling = true
  493. Blah.Color = RandColor
  494. Blah.Velocity = (Normal + Vector.Random()) * 100
  495. Blah.OnCollide = "Remove"
  496. end
  497. c:Remove()
  498. end
  499.  
  500. end
  501. return {Vector = Vector, Particle = Particle, Run = Run}
  502. end
  503. end
  504. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement