Advertisement
aarontje11002

Stravant's lightning

Mar 28th, 2015
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 33.31 KB | None | 0 0
  1. local Players = Game:GetService('Players')
  2. local RunService = Game:GetService('RunService')
  3.  
  4. local Character = script.Parent
  5. local Player = Players:GetPlayerFromCharacter(Character)
  6. local Mouse = Player:GetMouse()
  7. local Camera = Workspace.CurrentCamera
  8.  
  9. local PartList = {
  10. {
  11. -- 15 degrees
  12. Sweep = 20;
  13. Mesh = 'rbxassetid://168892318';
  14. CFrame = CFrame.new(-2.028, 0.003, 0.063, 0.482962936, -0.258818984, -0.836516321, 0.129409432, 0.965925813, -0.224143848, 0.866025388, 6.70552254e-008, 0.5);
  15. },
  16. {
  17. -- 180 degrees
  18. Sweep = 180;
  19. Mesh = 'rbxassetid://168892343';
  20. CFrame = CFrame.new(-0.500, -0.169, -0.275, -0.546336055, 0.136979967, 0.826288223, -0.0343417339, 0.982042372, -0.185506523, -0.836861134, -0.129725233, -0.531821132);
  21. },
  22. {
  23. -- 30 degrees
  24. Sweep = 40;
  25. Mesh = 'rbxassetid://168892363';
  26. CFrame = CFrame.new(-1.738, -0.056, -0.034, 0.913205206, -0.157400429, -0.375873566, 0.0347544663, 0.949112594, -0.313011229, 0.406014502, 0.272780538, 0.872205615);
  27. },
  28. {
  29. -- 250 degrees
  30. Sweep = 250;
  31. Mesh = 'rbxassetid://168892387';
  32. CFrame = CFrame.new(0.033, -0.053, -0.015, -0.947963715, 0.129520699, 0.290842265, 0.0606384911, 0.970239401, -0.23443158, -0.312550366, -0.20459649, -0.927605391);
  33. },
  34. {
  35. -- 200 degrees
  36. Sweep = 200;
  37. Mesh = 'rbxassetid://168892408';
  38. CFrame = CFrame.new(-0.293, -0.027, -0.226, -0.517871141, -0.154164821, -0.841452301, 0.081988588, 0.970154822, -0.228204504, 0.85152036, -0.187170446, -0.489775389);
  39. },
  40. }
  41.  
  42. local MainBodyPartList = {
  43. 'Head', 'Torso', 'Right Arm', 'Left Arm', 'Right Leg', 'Left Leg';
  44. }
  45.  
  46. local function DuplicateCharacterInto(character, parent)
  47. local partSet = {}
  48. --
  49. for _, ch in pairs(character:GetChildren()) do
  50. if ch:IsA('Clothing') then
  51. ch:Clone().Parent = parent
  52. end
  53. end
  54. for _, partName in pairs(MainBodyPartList) do
  55. local ch = Character:FindFirstChild(partName)
  56. if ch and ch:IsA('BasePart') then
  57. local c = ch:Clone()
  58. c.Parent = parent
  59. c.Anchored = true
  60. c.CanCollide = false
  61. c.TopSurface = 'Smooth'
  62. c.BottomSurface = 'Smooth'
  63. c.RightSurface = 'Smooth'
  64. c.LeftSurface = 'Smooth'
  65. c.FrontSurface = 'Smooth'
  66. c.BackSurface = 'Smooth'
  67. c:BreakJoints()
  68. partSet[c.Name] = c
  69. end
  70. end
  71. --
  72. return partSet
  73. end
  74.  
  75. local function CreateEffectModel(character)
  76. local model;
  77. if Workspace.FilteringEnabled then
  78. model = Instance.new('Configuration', character)
  79. else
  80. model = Instance.new('Configuration', Workspace.CurrentCamera)
  81. end
  82. model.Name = Player.Name.."_EffectModel"
  83. return model
  84. end
  85.  
  86. local function CreatePartPool()
  87. local this = {}
  88.  
  89. local mPartPoolPtr = 0
  90. local mPartPool = {}
  91.  
  92. function this:Allocate()
  93. mPartPoolPtr = mPartPoolPtr + 1
  94. local part = mPartPool[mPartPoolPtr]
  95. if not part then
  96. part = Instance.new('Part')
  97. part.Anchored = true
  98. part.CanCollide = false
  99. part.FormFactor = 'Custom'
  100. part.TopSurface = 'Smooth'
  101. part.BottomSurface = 'Smooth'
  102. part.BrickColor = BrickColor.new(23)
  103. local box = Instance.new('SelectionBox', part)
  104. box.Adornee = part
  105. box.Transparency = 0.3
  106. box.Color = BrickColor.new(1010)
  107. --
  108. mPartPool[mPartPoolPtr] = part
  109. end
  110. return part
  111. end
  112.  
  113. function this:ResetPointer()
  114. mPartPoolPtr = 0
  115. end
  116.  
  117. function this:HideRest()
  118. for i = mPartPoolPtr+1, #mPartPool do
  119. mPartPool[i].Parent = nil
  120. end
  121. end
  122.  
  123. function this:HideAll()
  124. for _, part in pairs(mPartPool) do
  125. part.Parent = nil
  126. end
  127. end
  128.  
  129. function this:Destroy()
  130. for _, part in pairs(mPartPool) do
  131. part:Destroy()
  132. end
  133. end
  134.  
  135. return this
  136. end
  137.  
  138. local function CreateBlurEffect(parent, partSet)
  139. local this = {}
  140. local mTransparency = 0.5
  141. local mVelocity = Vector3.new(0, 0, 0)
  142. local mRiseDir = Vector3.new(0, 1, 0)
  143. --
  144. local mPartList = {}
  145. local mTweenSet = {}
  146. --
  147. local tm = tick()
  148. for part, _ in pairs(partSet) do
  149. local dat = {}
  150. dat.Part = part
  151. dat.NextEmit = tm + math.random()*0.5
  152. table.insert(mPartList, dat)
  153. end
  154.  
  155. function this:SetTransparency(trans)
  156. mTransparency = trans
  157. end
  158. function this:SetVelocity(velo)
  159. mVelocity = velo
  160. end
  161.  
  162. local function emit(part)
  163. local dir = (CFrame.new(Vector3.new(), mRiseDir) * CFrame.Angles(0, 0, math.pi*2*math.random()) * CFrame.Angles(2*math.random(), 0, 0)).lookVector
  164. local dat = {}
  165. dat.CFrame = part.CFrame
  166. dat.Direction = dir
  167. dat.Emitted = tick()
  168. dat.Lifetime = 0.4 + math.random()*0.3
  169. dat.SpeedFactor = 1 + (math.random()*2-1)*0.5
  170. dat.BaseSize = part.Size
  171. dat.Velocity = mVelocity
  172. local newPart = part:Clone()
  173. dat.Part = newPart
  174. newPart.Anchored = true
  175. newPart.CanCollide = false
  176. newPart.FormFactor = 'Custom'
  177. newPart.Transparency = mTransparency
  178. newPart.BrickColor = BrickColor.new(23)
  179. newPart.TopSurface = 'Smooth'
  180. newPart.BottomSurface = 'Smooth'
  181. newPart.RightSurface = 'Smooth'
  182. newPart.LeftSurface = 'Smooth'
  183. newPart:BreakJoints()
  184. mTweenSet[dat] = true
  185. end
  186.  
  187. function this:Update(dt)
  188. -- Update rise dir
  189. local desiredRise = (Vector3.new(0, 2, 0) - mVelocity).unit
  190. if (desiredRise - mRiseDir).magnitude <= 2*dt then
  191. mRiseDir = desiredRise
  192. else
  193. mRiseDir = (mRiseDir + (desiredRise - mRiseDir).unit * (2*dt)).unit
  194. end
  195.  
  196. -- Update part list
  197. for _, dat in pairs(mPartList) do
  198. if tick() > dat.NextEmit then
  199. emit(dat.Part)
  200. dat.NextEmit = tick() + (0.1 + math.random()*0.2)
  201. end
  202. end
  203.  
  204. -- Update the tween parts
  205. for dat, _ in pairs(mTweenSet) do
  206. local frac = (tick() - dat.Emitted) / dat.Lifetime
  207. if frac > 1 then
  208. mTweenSet[dat] = nil
  209. dat.Part:Destroy()
  210. else
  211. dat.Part.Parent = parent
  212. dat.Part:BreakJoints()
  213. dat.Part.Size = dat.BaseSize * (1 - 0.3*frac)
  214. dat.CFrame = dat.CFrame + (frac^1.5*dt*20*dat.SpeedFactor)*dat.Direction + dat.Velocity*dt
  215. dat.Part.CFrame = dat.CFrame
  216. dat.Part.Transparency = mTransparency + (1 - mTransparency)*(frac^1.5)
  217. end
  218. end
  219. end
  220.  
  221. function this:Destroy()
  222. for dat, _ in pairs(mTweenSet) do
  223. dat.Part:Destroy()
  224. end
  225. end
  226.  
  227. return this
  228. end
  229.  
  230. local function CreateSpinEffect(parent)
  231. local this = {}
  232.  
  233. local mTransparency = 0.5
  234. local mCFrame = CFrame.new()
  235.  
  236. local mRingSet = {}
  237. local mRingCount = 0
  238. local mNextRingAt = tick() + 0.5
  239. local mDesiredRingCount = 8
  240.  
  241. function this:SetTransparency(trans)
  242. mTransparency = trans
  243. end
  244.  
  245. function this:SetCFrame(cf)
  246. mCFrame = CFrame.new(cf.p)
  247. end
  248.  
  249. function this:AddRing()
  250. local ring = PartList[math.random(1, #PartList)]
  251. mRingCount = mRingCount + 1
  252. --
  253. local dat = {}
  254. dat.Started = tick()
  255. dat.Created = dat.Started
  256. dat.Mode = 'In'
  257. dat.PartRotOffset = (ring.CFrame - ring.CFrame.p)
  258. dat.PartMoveOffset = ring.CFrame.p
  259. --
  260. local part = Instance.new('Part')
  261. part.FormFactor = 'Custom'
  262. part.Size = Vector3.new(1, 1, 1)
  263. part.TopSurface = 'Smooth'
  264. part.BottomSurface = 'Smooth'
  265. part.Anchored = true
  266. part.CanCollide = false
  267. local mesh = Instance.new('SpecialMesh', part)
  268. mesh.TextureId = 'rbxassetid://168892465'
  269. mesh.MeshId = ring.Mesh
  270. mesh.VertexColor = Vector3.new(0, 0.5, 1)
  271. --
  272. dat.Part = part
  273. dat.Mesh = mesh
  274. dat.VerticalOffset = 4*(math.random()*2-1)
  275. dat.Radius = 2 + 5*math.sqrt(1 - math.abs(dat.VerticalOffset/4))
  276. dat.Theta = (math.random()*math.pi*2)
  277. dat.TurnDirection = (math.random(0,1)*2-1)
  278. dat.TurnSpeed = 3 + (math.random()*2-1)*2
  279. mRingSet[dat] = true
  280. end
  281.  
  282. function this:ShedRing()
  283. for ring, _ in pairs(mRingSet) do
  284. if ring.Mode == 'Norm' then
  285. ring.Mode = 'Out'
  286. ring.Started = tick()
  287. mRingCount = mRingCount - 1
  288. end
  289. end
  290. end
  291.  
  292. function this:Update(dt)
  293. local now = tick()
  294.  
  295. if now > mNextRingAt then
  296. if mRingCount > mDesiredRingCount then
  297. this:ShedRing()
  298. else
  299. this:AddRing()
  300. end
  301. mNextRingAt = now + (0.1 + math.random()*(0.3 * (mRingCount / mDesiredRingCount)))
  302. end
  303.  
  304. for ring, _ in pairs(mRingSet) do
  305. local frac = (now - ring.Started) / 2
  306. local radius = nil
  307. local trans = nil
  308. if ring.Mode == 'In' then
  309. if frac > 1 then
  310. ring.Mode = 'Norm'
  311. else
  312. local turnFactor = 0.2 + 0.8*(0.5+0.5*math.cos(frac*math.pi))^2
  313. local turnSpeed = ring.TurnSpeed + turnFactor*10
  314. ring.Theta = ring.Theta + dt*(ring.TurnDirection*turnSpeed)
  315. radius = ring.Radius + turnFactor*5
  316. trans = frac
  317. end
  318. elseif ring.Mode == 'Out' then
  319. if frac > 1 then
  320. mRingSet[ring] = nil
  321. ring.Part:Destroy()
  322. else
  323. radius = ring.Radius + 5*(frac^2)
  324. ring.Theta = ring.Theta + dt*(ring.TurnDirection*ring.TurnSpeed)
  325. trans = frac^2
  326. end
  327. end
  328. if ring.Mode == 'Norm' then
  329. radius = ring.Radius
  330. trans = 1
  331. ring.Theta = ring.Theta + dt*(ring.TurnDirection*ring.TurnSpeed)
  332. end
  333. --
  334. if mRingSet[ring] then
  335. local sz = radius / 4
  336. ring.Mesh.Scale = Vector3.new(sz, 1, sz)
  337. ring.Part.Parent = parent
  338. ring.Part.CFrame = (mCFrame * CFrame.new(0, ring.VerticalOffset, 0) * CFrame.Angles(0, ring.Theta, 0) * CFrame.new(ring.PartMoveOffset*sz)) * ring.PartRotOffset
  339. ring.Part.Transparency = 1 - (1-mTransparency)*(1-trans)
  340. end
  341. end
  342. end
  343.  
  344. return this
  345. end
  346.  
  347. local function CreateLightningEffect(parent)
  348. local this = {}
  349.  
  350. local mPartPool = CreatePartPool()
  351. local mActive = false
  352. local mActivatedAt = 0
  353. local mFrom = Vector3.new()
  354. local mTo = Vector3.new()
  355. local mLightningPath = {{P = mFrom; T = tick(); Expiry = 0}}
  356. local mLightningPart = Instance.new('Part')
  357. mLightningPart.Anchored = true
  358. mLightningPart.CanCollide = false
  359. mLightningPart.FormFactor = 'Custom'
  360. mLightningPart.Size = Vector3.new()
  361. mLightningPart.Transparency = 1
  362. local fire = Instance.new('Fire', mLightningPart)
  363. fire.Heat = 20
  364. fire.Color = Color3.new(10/255, 149/255, 255/255)
  365. fire.SecondaryColor = Color3.new(0, 0, 0)
  366. fire.Size = 5
  367. fire:Clone().Parent = mLightningPart
  368. local light = Instance.new('PointLight', mLightningPart)
  369. light.Brightness = 2
  370. light.Range = 4
  371. light.Color = Color3.new(0/255, 153/255, 255/255)
  372.  
  373. local function tickPath(dt)
  374. local cachedPoints = {}
  375. mLightningPath[1].P = mFrom
  376. local i = 1
  377. local now = tick()
  378. while true do
  379. -- Fudge the current point
  380. local currentPoint = mLightningPath[i]
  381. currentPoint.P = currentPoint.P + Vector3.new(math.random()*2-1, math.random()*2-1, math.random()*2-1)*(5*dt)
  382.  
  383. -- Are we at the goal?
  384. -- If we are then clear out the other points
  385. if (currentPoint.P - mTo).magnitude < 0.5 then
  386. for j = i+1, #mLightningPath do
  387. mLightningPath[j] = nil
  388. end
  389. break
  390. end
  391.  
  392. -- Not at the goal, do we have a next point?
  393. local useNext;
  394. local nextPoint = mLightningPath[i+1]
  395. if nextPoint then
  396. local toNext = nextPoint.P - currentPoint.P
  397. local toGoal = mTo - currentPoint.P
  398.  
  399. -- Is the next point near the goal?
  400. if toGoal.magnitude < 4.6 then
  401. -- Just snap it to the goal
  402. nextPoint.P = mTo
  403. useNext = true
  404. else
  405. --
  406. if math.acos(toNext.unit:Dot(toGoal.unit)) > math.pi/2 then
  407. -- The next point is too far out of direction
  408. useNext = false
  409. else
  410. useNext = true
  411. end
  412. end
  413. else
  414. useNext = false
  415. end
  416.  
  417. if useNext and (now - currentPoint.T) > currentPoint.Expiry then
  418. local fracThere = (currentPoint.P - mFrom).magnitude / (mFrom - mTo).magnitude
  419. currentPoint.Expiry = math.random()*0.1 + 0.6*fracThere
  420. currentPoint.T = now
  421. useNext = false
  422. end
  423.  
  424. -- If we can't use the next then we need to do some work
  425. if not useNext then
  426. -- Move all the points ahead to the cached list
  427. for j = i+1, #mLightningPath do
  428. table.insert(cachedPoints, mLightningPath[j])
  429. mLightningPath[j] = nil
  430. end
  431.  
  432. -- Create the next point
  433. local toGoal = mTo - currentPoint.P
  434. if toGoal.magnitude < 4.5 then
  435. -- If we're close enough to the goal, just snap there
  436. table.insert(mLightningPath, {P = mTo; T = now; Expiry = math.random()*0.4})
  437. else
  438. -- Otherwise, perturb the direction
  439. local upwards = math.min(1, (now - mActivatedAt) / 0.8)
  440. if upwards == 1 then
  441. mActivatedAt = now
  442. end
  443. local dir = CFrame.new(Vector3.new(), toGoal) * CFrame.Angles(0.2 + upwards*0.5, 0, 0) * CFrame.Angles(0, 0, math.random()*math.pi*2) * CFrame.Angles(math.random()*math.pi/3, 0, 0)
  444. dir = dir.lookVector * (2 + math.random()*1)
  445. local fracThere = (currentPoint.P + dir - mFrom).magnitude / (mFrom - mTo).magnitude
  446. table.insert(mLightningPath, {
  447. P = currentPoint.P + dir;
  448. T = now;
  449. Expiry = math.random()*0.1 + 0.6*fracThere;
  450. })
  451. end
  452. end
  453.  
  454. -- Done
  455. i = i + 1
  456. if i > 40 then
  457. break
  458. end
  459. end
  460. end
  461.  
  462. local function drawPath()
  463. mPartPool:ResetPointer()
  464. for i = 1, #mLightningPath - 1 do
  465. local a = mLightningPath[i].P
  466. local b = mLightningPath[i+1].P
  467. --
  468. local frac = i / (#mLightningPath-1)
  469. local w = 0.2 + 0.2*(1 - 2*math.abs(frac - 0.5))
  470. --
  471. local part = mPartPool:Allocate()
  472. part.Size = Vector3.new(w, w, (a-b).magnitude)
  473. part.CFrame = CFrame.new(0.5*(a+b), b)
  474. part.Parent = parent
  475. part.Transparency = 1
  476. end
  477. mPartPool:HideRest()
  478. mLightningPart.CFrame = CFrame.new(mTo)
  479. mLightningPart.Parent = parent
  480. end
  481.  
  482. function this:Set(from, to)
  483. mFrom = from
  484. mTo = to
  485. end
  486.  
  487. function this:SetActive(state)
  488. if mActive == state then return end
  489. mActive = state
  490. if mActive then
  491. mActivatedAt = tick()
  492. mLightningPath[1].P = mFrom
  493. for i = 2, #mLightningPath do
  494. mLightningPath[i] = nil
  495. end
  496. else
  497. mPartPool:HideAll()
  498. mLightningPart.Parent = nil
  499. end
  500. end
  501.  
  502. function this:Update(dt)
  503. if mActive then
  504. tickPath(dt)
  505. drawPath()
  506. end
  507. end
  508.  
  509. function this:Destroy()
  510. mPartPool:Destroy()
  511. end
  512.  
  513. return this
  514. end
  515.  
  516. local BREAKOFF_TIME = 1
  517. local FLOAT_FINISH_TIME = 3
  518. local FLOAT_HEIGHT = 10
  519. --
  520. local RISE_VELOCITY = FLOAT_FINISH_TIME / FLOAT_HEIGHT
  521.  
  522. local function TransformationSequence(character)
  523. local torso = character:WaitForChild('HumanoidRootPart')
  524. local humanoid = character:WaitForChild('Humanoid')
  525. local dir = torso.CFrame.lookVector
  526. local transformBase = CFrame.new(torso.Position, torso.Position + Vector3.new(dir.X, 0, dir.Z))
  527.  
  528. -- Remove the tools
  529. Delay(0.2, function()
  530. for _, tool in pairs(Player:WaitForChild('Backpack'):GetChildren()) do
  531. if tool:IsA('Tool') or tool:IsA('Hopperbin') then
  532. tool.Parent = nil
  533. end
  534. end
  535. for _, tool in pairs(Character:GetChildren()) do
  536. if tool:IsA('Tool') then
  537. tool.Parent = nil
  538. end
  539. end
  540. end)
  541.  
  542. -- If not filtering, we can clone the viewLocal into the other clients
  543. local addViewCn;
  544. if not Workspace.FilteringEnabled then
  545. local viewLocal = script:WaitForChild('ViewLocal')
  546. for _, player in pairs(Players:GetChildren()) do
  547. if player ~= Player then
  548. Spawn(function()
  549. local cl = viewLocal:Clone()
  550. cl:WaitForChild('TargetCharacter').Value = character
  551. cl.Disabled = false
  552. while not player.Character do player.Changed:wait() end
  553. cl.Parent = player.Character
  554. end)
  555. end
  556. end
  557. -- .PlayerAdded does not work for other players on the client
  558. addViewCn = Players.ChildAdded:connect(function(player)
  559. if not player:IsA('Player') then return end
  560. Spawn(function()
  561. local cl = viewLocal:Clone()
  562. cl:WaitForChild('TargetCharacter').Value = character
  563. cl.Disabled = false
  564. while not player.Character do player.Changed:wait() end
  565. cl.Parent = player.Character
  566. end)
  567. end)
  568. end
  569.  
  570. -- Gather the parts to do the tween on
  571. local partsToTween = {}
  572. local function gatherParts(object)
  573. for _, ch in pairs(object:GetChildren()) do
  574. if ch:IsA('BasePart') then
  575. local tweenPart = {
  576. Part = ch;
  577. }
  578. table.insert(partsToTween, tweenPart)
  579. else
  580. gatherParts(ch)
  581. end
  582. end
  583. end
  584. gatherParts(character)
  585.  
  586. -- The effect model
  587. local effectModel = CreateEffectModel(character)
  588.  
  589. -- Duplicate the parts we want normally, but want to make fly away
  590. local flyAwayParts = DuplicateCharacterInto(character, effectModel)
  591.  
  592. -- Put the body parts into a set
  593. local flyAwayPartSet = {}
  594.  
  595. -- Decide what to do with each of the parts
  596. for _, dat in pairs(partsToTween) do
  597. if flyAwayParts[dat.Part.Name] then
  598. flyAwayPartSet[dat.Part] = true
  599. dat.Mode = 'BreakAway'
  600. dat.BreakAwayPart = flyAwayParts[dat.Part.Name]
  601. else
  602. dat.Mode = 'Fade'
  603. end
  604. end
  605.  
  606. -- Anchor and ready the character
  607. torso.Anchored = true
  608. humanoid:ChangeState('Physics')
  609.  
  610. -- Go into the transformation sequence
  611. local transformStart = tick()
  612. local transformLast = transformStart
  613. local transformBase = character.Torso.CFrame * CFrame.new(0, -3, 0)
  614. transformBase = CFrame.new(transformBase.p, transformBase.p + Vector3.new(transformBase.lookVector.X, 0, transformBase.lookVector.z))
  615.  
  616. -- Generate some of the effects
  617. local effectSet = {}
  618.  
  619. -- Takeoff ground waves
  620. do
  621. local waves = {}
  622. for i = 1, 4 do
  623. local wave = {}
  624. wave.Delay = ((i-1)/4)*0.25 + math.random()*0.3
  625. wave.Size = ((5-i)/4)*15 + math.random()*3
  626. wave.Duration = 0.5 + math.random()*0.2
  627. --
  628. local part = Instance.new('Part')
  629. part.FormFactor = 'Custom'
  630. part.BrickColor = BrickColor.new(23)
  631. part.Size = Vector3.new(1, 1, 1)
  632. part.Anchored = true
  633. part.CanCollide = false
  634. part.CFrame = transformBase * CFrame.new(math.random()*4-2, 0, math.random()*4-2)
  635. part.TopSurface = 'Smooth'
  636. --
  637. local mesh = Instance.new('SpecialMesh', part)
  638. mesh.MeshType = 'Sphere'
  639. wave.Part = part
  640. wave.Mesh = mesh
  641. table.insert(waves, wave)
  642. end
  643. local function updateWaves(elapsed, dt)
  644. local allDone = true
  645. for _, wave in pairs(waves) do
  646. if elapsed > wave.Delay then
  647. if elapsed > wave.Delay + wave.Duration then
  648. wave.Part:Destroy()
  649. else
  650. allDone = false
  651. -- Normal case
  652. local frac = (elapsed - wave.Delay) / wave.Duration
  653. local fracIn = 1 - frac^0.25
  654. local fracOut = frac^5
  655. wave.Mesh.Scale = Vector3.new(wave.Size * fracIn, 0.1 + 9*fracOut, wave.Size * fracIn)
  656. wave.Part.Transparency = 0.3 + 0.7*fracOut
  657. wave.Part.Parent = effectModel
  658. end
  659. else
  660. allDone = false
  661. end
  662. end
  663. return allDone
  664. end
  665. local function destroyWaves()
  666. for _, wave in pairs(waves) do
  667. wave.Part:Destroy()
  668. end
  669. end
  670. effectSet[{
  671. Update = updateWaves;
  672. Destroy = destroyWaves;
  673. }] = true
  674. end
  675.  
  676. -- Takeoff vertical risers
  677. do
  678. local risers = {}
  679. for i = 1, 6 do
  680. local riser = {}
  681. riser.Delay = 0.3 + math.random() * 0.4
  682. riser.Duration = 1 + math.random() * 1.5
  683. riser.Offset = CFrame.new(math.random()*4 - 2, 0, math.random()*4 - 2)
  684. riser.Width = 0.3 + math.random() * 0.5
  685. riser.Height = 1 + math.random() * 2
  686. --
  687. local part = Instance.new('Part')
  688. part.FormFactor = 'Custom'
  689. part.Size = Vector3.new(1, 1, 1)
  690. part.Anchored = true
  691. part.CanCollide = false
  692. part.BrickColor = BrickColor.new(23)
  693. part.TopSurface = 'Smooth'
  694. part.BottomSurface = 'Smooth'
  695. --
  696. local mesh = Instance.new('SpecialMesh', part)
  697. mesh.MeshType = 'Brick'
  698. riser.Part = part
  699. riser.Mesh = mesh
  700. table.insert(risers, riser)
  701. end
  702. local function updateRisers(elapsed, dt)
  703. local allDone = true
  704. for _, riser in pairs(risers) do
  705. if elapsed > riser.Delay then
  706. if elapsed > riser.Delay + riser.Duration then
  707. riser.Part:Destroy()
  708. else
  709. allDone = false
  710. -- Normal case
  711. local frac = (elapsed - riser.Delay) / riser.Duration
  712. local rampFrac = 1 - math.abs(frac - 0.5)
  713. local widthFrac = rampFrac^2
  714. local heightFrac = rampFrac
  715. riser.Mesh.Scale = Vector3.new(riser.Width * widthFrac, riser.Height * heightFrac, riser.Width * widthFrac)
  716. riser.Part.Transparency = 0.2 --widthFrac
  717. riser.Part.CFrame = transformBase * riser.Offset * CFrame.new(0, -riser.Height/2 + frac^2*(6 + riser.Height), 0) * CFrame.Angles(0, frac*8, 0)
  718. riser.Part.Parent = effectModel
  719. end
  720. else
  721. allDone = false
  722. end
  723. end
  724. return allDone
  725. end
  726. local function destroyRisers()
  727. for _, riser in pairs(risers) do
  728. riser.Part:Destroy()
  729. end
  730. end
  731. effectSet[{
  732. Update = updateRisers;
  733. Destroy = destroyRisers;
  734. }] = true
  735. end
  736.  
  737. -- Main effect
  738. local blurEffect = CreateBlurEffect(effectModel, flyAwayPartSet)
  739.  
  740. -- The ring effect
  741. local ringEffect = CreateSpinEffect(effectModel)
  742.  
  743. -- Main transformation sequence
  744. while humanoid.Health > 0 and character.Parent do
  745. -- How much time has elapsed
  746. local now = tick()
  747. local dt = now - transformLast
  748. local elapsed = now - transformStart
  749. transformLast = now
  750.  
  751. -- Run any effects
  752. for effect, _ in pairs(effectSet) do
  753. if effect.Update(elapsed, dt) then
  754. effect.Destroy()
  755. effectSet[effect] = nil
  756. end
  757. end
  758.  
  759. -- Main timer
  760. local frac = math.min(1, elapsed / FLOAT_FINISH_TIME)
  761. local breakFrac = math.max(0, math.min(1, (elapsed - BREAKOFF_TIME) / (FLOAT_FINISH_TIME - BREAKOFF_TIME)))
  762. local moveFrac = frac^1.2
  763.  
  764. -- Float up the torso
  765. if not Workspace.FilteringEnabled then
  766. torso.Anchored = false
  767. torso.CFrame = transformBase * CFrame.new(0, 3 + moveFrac * FLOAT_HEIGHT, 0)
  768. torso.Anchored = true
  769. end
  770.  
  771. -- Tween part positions + transparency
  772. for _, dat in pairs(partsToTween) do
  773. if dat.Mode == 'Fade' then
  774. dat.Part.Transparency = frac
  775. elseif dat.Mode == 'BreakAway' then
  776. if dat.Part.Name == 'Head' then
  777. dat.Part.Transparency = 0.99
  778. else
  779. dat.Part.Transparency = 1
  780. end
  781. if elapsed > BREAKOFF_TIME then
  782. if not dat.Broken then
  783. dat.BreakCFrame = dat.Part.CFrame
  784. for _, ch in pairs(dat.Part:GetChildren()) do
  785. if ch:IsA('Decal') then ch:Destroy() end
  786. end
  787. dat.BreakVelocity = Vector3.new(math.random()-0.5, 1, math.random()-0.5).unit * 4*(1+math.random())
  788. dat.BreakRotVelocity = Vector3.new(math.random()-0.5, math.random()-0.5, math.random()-0.5)*5
  789. dat.Broken = true
  790. end
  791. local rvelo = dat.BreakRotVelocity*dt
  792. dat.BreakCFrame = (dat.BreakCFrame + dat.BreakVelocity*dt) * CFrame.Angles(rvelo.X, rvelo.Y, rvelo.Z)
  793. dat.BreakAwayPart.CFrame = dat.BreakCFrame
  794. dat.BreakAwayPart.Transparency = (frac < 0.5) and 0 or ((frac-0.5)/0.5)^2
  795. else
  796. dat.BreakAwayPart.CFrame = dat.Part.CFrame
  797. end
  798. else
  799. assert(false, "unreachable")
  800. end
  801. end
  802.  
  803. -- Fade in blur effect
  804. blurEffect:SetTransparency(1 - frac*0.7)
  805. blurEffect:Update(dt)
  806.  
  807. -- Fade in ring effect
  808. ringEffect:SetCFrame(torso.CFrame)
  809. ringEffect:SetTransparency(1 - breakFrac*0.7)
  810. ringEffect:Update(dt)
  811.  
  812. -- Exit
  813. if elapsed > FLOAT_FINISH_TIME + 0.5 then
  814. break
  815. end
  816.  
  817. RunService.RenderStepped:wait()
  818. end
  819.  
  820. for _, part in pairs(flyAwayParts) do
  821. part:Destroy()
  822. end
  823. for _, obj in pairs(effectModel:GetChildren()) do
  824. if obj:IsA('Clothing') then
  825. obj:Destroy()
  826. end
  827. end
  828. blurEffect:SetTransparency(0.3)
  829. blurEffect:Update(0)
  830. ringEffect:SetTransparency(0.3)
  831. ringEffect:Update(0)
  832.  
  833. return addViewCn, effectModel, blurEffect, ringEffect
  834. end
  835.  
  836. local mDirectionKey = {
  837. w = Vector3.new(0, 0, -1);
  838. s = Vector3.new(0, 0, 1);
  839. a = Vector3.new(-1, 0, 0);
  840. d = Vector3.new(1, 0, 0);
  841. [string.char(17)] = Vector3.new(0, 0, -1);
  842. [string.char(18)] = Vector3.new(0, 0, 1);
  843. [string.char(20)] = Vector3.new(-1, 0, 0);
  844. [string.char(19)] = Vector3.new(1, 0, 0);
  845. }
  846. local mKeySet = {}
  847.  
  848. local MouseDown = false
  849.  
  850. local Anim;
  851.  
  852. function RunController(addViewCn, character, effectModel, blurEffect, ringEffect)
  853. -- Already dead
  854. if not (character.Parent and character:FindFirstChild('Humanoid') and character.Humanoid.Health > 0) then
  855. effectModel:Destroy()
  856. if addViewCn then
  857. addViewCn:disconnect()
  858. end
  859. return nil
  860. end
  861. --
  862. local torso = character:WaitForChild('HumanoidRootPart')
  863. local humanoid = character:WaitForChild('Humanoid')
  864. local anim = script:WaitForChild('FlyAnimation')
  865. Anim = humanoid:LoadAnimation(anim)
  866. Anim:Play(2)
  867. --
  868. local turn, move;
  869. if Workspace.FilteringEnabled then
  870. turn = torso:WaitForChild('Turn')
  871. move = torso:WaitForChild('Move')
  872. else
  873. turn = Instance.new('BodyGyro', torso)
  874. turn.maxTorque = Vector3.new(10000, 10000, 10000)
  875. turn.cframe = torso.CFrame
  876. --
  877. move = Instance.new('BodyPosition', torso)
  878. move.maxForce = Vector3.new(10000, 10000, 10000)
  879. move.position = torso.Position
  880. end
  881. --
  882. local fireSound = Instance.new('Sound', effectModel)
  883. fireSound.SoundId = 'rbxassetid://69446845'
  884. fireSound.Pitch = 1.5
  885. fireSound.Volume = 0.25
  886. fireSound.Looped = true
  887. local fireSound2 = Instance.new('Sound', effectModel)
  888. fireSound2.SoundId = 'rbxassetid://69446845'
  889. fireSound2.Pitch = 1.5
  890. fireSound2.Volume = 0.25
  891. fireSound2.Looped = true
  892. --
  893. local UpdateMove;
  894. if Workspace.FilteringEnabled then
  895. UpdateMove = Character:WaitForChild('RunGlobal_SSTool'):WaitForChild('UpdateMove')
  896. local val = Character:WaitForChild('RunGlobal_SSTool'):WaitForChild('ControlReady')
  897. while not val.Value do val.Changed:wait() end
  898. end
  899. --
  900. humanoid:ChangeState('Physics')
  901. torso.Anchored = false
  902. --
  903. local mMovementPosition = torso.Position
  904. local mMoveVelocity = Vector3.new()
  905. local mMoveYVelocity = 0
  906. --
  907. local function updateMove(dt)
  908. -- Get the local space move direction
  909. local moveDir = Vector3.new()
  910. for key, d in pairs(mDirectionKey) do
  911. if mKeySet[key] then
  912. moveDir = moveDir + d
  913. end
  914. end
  915. moveDir = moveDir.unit
  916.  
  917. -- To global space
  918. local cam = Workspace.CurrentCamera.CoordinateFrame
  919. local dirCF = CFrame.new(cam.p, cam.p + Vector3.new(cam.lookVector.x, 0, cam.lookVector.z))
  920. moveDir = dirCF:vectorToWorldSpace(moveDir)
  921.  
  922. -- Accelerate
  923. if moveDir.magnitude > 0.01 then
  924. mMoveVelocity = mMoveVelocity + moveDir*(dt*80)
  925. if mMoveVelocity.magnitude > 20 then
  926. mMoveVelocity = mMoveVelocity.unit*20
  927. end
  928. else
  929. if mMoveVelocity.magnitude > 0 then
  930. mMoveVelocity = mMoveVelocity.unit * math.max(0, mMoveVelocity.magnitude - dt*30)
  931. end
  932. end
  933.  
  934. -- Move
  935. mMovementPosition = mMovementPosition + mMoveVelocity*dt
  936.  
  937. -- Movement is blocked
  938. if (mMovementPosition - torso.Position).magnitude > 5 then
  939. mMovementPosition = mMovementPosition + (torso.Position - mMovementPosition).unit * 5
  940. end
  941.  
  942. -- Adjust height
  943. local toIgnore = {Character}
  944. local downRay = Ray.new(mMovementPosition, Vector3.new(0, -1000, 0))
  945. local hit, at = Workspace:FindPartOnRayWithIgnoreList(downRay, toIgnore)
  946. while hit and not hit.CanCollide do
  947. table.insert(toIgnore, hit)
  948. downRay = Ray.new(at, Vector3.new(0, -1000, 0))
  949. hit, at = Workspace:FindPartOnRayWithIgnoreList(downRay, toIgnore)
  950. end
  951. local float = (at - mMovementPosition).magnitude
  952. if float > FLOAT_HEIGHT then
  953. mMoveYVelocity = mMoveYVelocity - 9.81*20*dt
  954. mMovementPosition = mMovementPosition + Vector3.new(0, math.min(float - FLOAT_HEIGHT, mMoveYVelocity*dt), 0)
  955. else
  956. mMoveYVelocity = 0
  957. mMovementPosition = mMovementPosition + Vector3.new(0, math.max(FLOAT_HEIGHT - float - 1), 0)
  958. end
  959.  
  960. -- Update objects
  961. move.position = mMovementPosition
  962. if mMoveVelocity.magnitude > 0 then
  963. turn.cframe = CFrame.new(Vector3.new(), mMoveVelocity)
  964. end
  965. end
  966. --
  967. local lightningEffect = CreateLightningEffect(effectModel)
  968. lightningEffect:SetActive(true)
  969. --
  970. local lightningActive = false
  971. local lightningActiveSince = 0
  972. local lightningRunId = 0
  973. --
  974. local lastDamagedHum = nil
  975. local lastDamagedAt = 0
  976. local lastDamagedCreator;
  977. local DamagePerSecond = 70
  978. --
  979. Spawn(function()
  980. local lastTime = tick()
  981. while humanoid.Health > 0 and character.Parent do
  982. local now = tick()
  983. local dt = (now - lastTime)
  984. lastTime = now
  985.  
  986. -- Movement
  987. updateMove(dt)
  988. if Workspace.FilteringEnabled then
  989. Spawn(function()
  990. UpdateMove:InvokeServer(Workspace.DistributedGameTime, mMovementPosition, mMoveVelocity, mMoveYVelocity)
  991. end)
  992. end
  993.  
  994. -- Attack effect
  995. local toIgnore = {Character, effectModel}
  996. local ray = Ray.new(Mouse.UnitRay.Origin, Mouse.UnitRay.Direction*999)
  997. local hit, at = Workspace:FindPartOnRayWithIgnoreList(ray, toIgnore)
  998. while hit and hit.Transparency == 1 do
  999. table.insert(toIgnore, hit)
  1000. hit, at = Workspace:FindPartOnRayWithIgnoreList(ray, toIgnore)
  1001. end
  1002. --
  1003. local hitHumanoid;
  1004. if hit then
  1005. local hum = hit.Parent:FindFirstChild('Humanoid')
  1006. if hum then hitHumanoid = hum end
  1007. if hit.Parent.Parent then
  1008. hum = hit.Parent.Parent:FindFirstChild('Humanoid')
  1009. if hum then hitHumanoid = hum end
  1010. end
  1011. end
  1012. --
  1013. local mouseAt = at
  1014. local vec = mouseAt - torso.Position
  1015. if not MouseDown or not hit or vec.magnitude > 60 then
  1016. lightningEffect:SetActive(false)
  1017. if lightningActive then
  1018. lightningActive = false
  1019. fireSound:Stop()
  1020. fireSound2:Stop()
  1021. lightningRunId = lightningRunId + 1
  1022. end
  1023. --
  1024. if lastDamagedHum then
  1025. if not Workspace.FilteringEnabled then
  1026. -- Deal remaining damage to the old target
  1027. lastDamagedHum:TakeDamage((now - lastDamagedAt)*DamagePerSecond)
  1028. Game:GetService('Debris'):AddItem(lastDamagedCreator, 0.5)
  1029. lastDamagedCreator = nil
  1030. lastDamagedHum = nil
  1031. end
  1032. end
  1033. --
  1034. local sc = Character:WaitForChild('RunGlobal_SSTool')
  1035. sc:WaitForChild('IsShooting').Value = false
  1036. sc:WaitForChild('HumanoidToDamage').Value = nil
  1037. if Workspace.FilteringEnabled then
  1038. sc:WaitForChild('UpdateShoot'):FireServer(false, Vector3.new(), Vector3.new(), nil)
  1039. end
  1040. else
  1041. if not lightningActive then
  1042. lightningActive = true
  1043. lightningActiveSince = now
  1044. fireSound.Pitch = 1.5 - 0.7
  1045. fireSound2.Pitch = 1.5 - 0.7
  1046. fireSound:Play()
  1047. lightningRunId = lightningRunId + 1
  1048. local thisRunId = lightningRunId
  1049. Delay(0.2, function()
  1050. if lightningRunId == thisRunId then
  1051. fireSound2:Play()
  1052. end
  1053. end)
  1054. else
  1055. local frac = math.min(1, (now - lightningActiveSince) / 0.3)
  1056. local modPitch = 1.5 - 0.7*(1-frac)
  1057. fireSound.Pitch = modPitch
  1058. fireSound2.Pitch = modPitch
  1059. end
  1060. lightningEffect:Set(torso.Position, torso.Position + vec)
  1061. lightningEffect:SetActive(true)
  1062. lightningEffect:Update(dt)
  1063. --
  1064. if not Workspace.FilteringEnabled then
  1065. -- Do damage on the client
  1066. if lastDamagedHum ~= hitHumanoid then
  1067. print("Switch target")
  1068. if lastDamagedHum then
  1069. lastDamagedHum:TakeDamage((now - lastDamagedAt)*DamagePerSecond)
  1070. Game:GetService('Debris'):AddItem(lastDamagedCreator, 0.5)
  1071. end
  1072. lastDamagedHum = hitHumanoid
  1073. lastDamagedCreator = Instance.new('ObjectValue')
  1074. lastDamagedCreator.Value = Player
  1075. lastDamagedCreator.Name = 'creator'
  1076. lastDamagedCreator.Parent = hitHumanoid
  1077. lastDamagedAt = now
  1078. end
  1079. if lastDamagedHum then
  1080. print("Try damage target")
  1081. if (now - lastDamagedAt) > 0.1 then
  1082. print("Damage target")
  1083. lastDamagedHum:TakeDamage((now - lastDamagedAt)*DamagePerSecond)
  1084. lastDamagedAt = now
  1085. end
  1086. end
  1087. end
  1088. --
  1089. local sc = Character:WaitForChild('RunGlobal_SSTool')
  1090. sc:WaitForChild('ShootFrom').Value = torso.Position
  1091. sc:WaitForChild('ShootTo').Value = torso.Position + vec
  1092. sc:WaitForChild('HumanoidToDamage').Value = hitHumanoid
  1093. sc:WaitForChild('IsShooting').Value = true
  1094. if Workspace.FilteringEnabled then
  1095. sc:WaitForChild('UpdateShoot'):FireServer(true, torso.Position, torso.Position + vec, hitHumanoid)
  1096. end
  1097. end
  1098.  
  1099. -- Character effects
  1100. blurEffect:Update(dt)
  1101. blurEffect:SetVelocity(torso.Velocity)
  1102. ringEffect:SetCFrame(torso.CFrame)
  1103. ringEffect:Update(dt)
  1104. --
  1105. while _G.Stop do wait() end
  1106. RunService.RenderStepped:wait()
  1107. end
  1108.  
  1109. if addViewCn then
  1110. addViewCn:disconnect()
  1111. end
  1112. if lastDamagedCreator then
  1113. Game:GetService('Debris'):AddItem(lastDamagedCreator, 1)
  1114. end
  1115.  
  1116. -- Destroy the movers
  1117. turn:Destroy()
  1118. move:Destroy()
  1119.  
  1120. -- Turn off the lightning if still running
  1121. fireSound:Stop()
  1122. fireSound2:Stop()
  1123. local sc = Character:WaitForChild('RunGlobal_SSTool')
  1124. sc:WaitForChild('IsShooting').Value = false
  1125. lightningEffect:SetActive(false)
  1126.  
  1127. -- Fade out the other effects
  1128. local lastTime = tick()
  1129. local trans = 0.3
  1130. while character.Parent do
  1131. local now = tick()
  1132. local dt = (now - lastTime)
  1133. lastTime = now
  1134. trans = math.min(1, trans + 0.5*dt)
  1135. blurEffect:SetTransparency(trans)
  1136. ringEffect:SetTransparency(trans)
  1137. blurEffect:Update(dt)
  1138. ringEffect:Update(dt)
  1139. RunService.RenderStepped:wait()
  1140. end
  1141.  
  1142. -- Finally Kill the effects and end
  1143. effectModel:Destroy()
  1144. end)
  1145. --
  1146. local this = {}
  1147. --
  1148. function this:ShootAt()
  1149.  
  1150. end
  1151. --
  1152. return this
  1153. end
  1154.  
  1155. local addViewCn, effectModel, blurEffect, ringEffect = TransformationSequence(Character)
  1156. local Controller = RunController(addViewCn, Character, effectModel, blurEffect, ringEffect)
  1157.  
  1158. if Controller then
  1159. Mouse.Button1Down:connect(function()
  1160. Controller:ShootAt()
  1161. MouseDown = true
  1162. end)
  1163. Mouse.Button1Up:connect(function()
  1164. MouseDown = false
  1165. end)
  1166. Mouse.KeyDown:connect(function(key)
  1167. print("Key:", string.byte(key))
  1168. key = key:lower()
  1169. mKeySet[key] = true
  1170. end)
  1171. Mouse.KeyUp:connect(function(key)
  1172. key = key:lower()
  1173. mKeySet[key] = nil
  1174. end)
  1175. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement