Advertisement
suremarc

Untitled

Mar 29th, 2015
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local DrawLine = function(v1, v2, color)
  2.     local part = Instance.new("Part", Workspace)
  3.     Instance.new("BlockMesh", part).Scale = Vector3.new(0.3, 0.3, (v1 - v2).magnitude)
  4.     part.Size = Vector3.new()
  5.     part.BrickColor = color
  6.     part.formFactor = "Symmetric"
  7.     part.CFrame = CFrame.new(v1:Lerp(v2, 0.5), v2)
  8.     part.Anchored = true
  9.     part.CanCollide = false
  10.     return part
  11. end
  12.  
  13. function DrawLightning(v1, v2, displace, color)
  14.     local parts = {}
  15.  
  16.     local function recurse(v1, v2, displace, color)
  17.         if displace < 1 then
  18.             table.insert(parts, DrawLine(v1, v2, color))
  19.         else
  20.             local midpoint = (v1 + v2) / 2
  21.             midpoint = midpoint + Vector3.new((math.random() - 0.5) * displace, (math.random() - 0.5) * displace, (math.random() - 0.5) * displace)
  22.             recurse(v1, midpoint, displace/2, color)
  23.             recurse(v2, midpoint, displace/2, color)
  24.         end
  25.     end
  26.    
  27.     recurse(v1, v2, displace, color)
  28.    
  29.     table.sort(parts, function(a, b)
  30.         return (v1 - a.Position).magnitude < (v1 - b.Position).magnitude
  31.     end)
  32.     return parts
  33. end
  34.  
  35. local bpos = Instance.new("BodyPosition")
  36. local LocalPlayer = game.Players.suremark
  37. local height = 0
  38.  
  39. local bin = Instance.new("HopperBin", LocalPlayer.Backpack)
  40. bin.Name = "Levitate"
  41.  
  42. local gravitating = false
  43. local box
  44. local target
  45.  
  46. bin.Selected:connect(function(mouse)
  47.     Spawn(function()
  48.         local parts;
  49.         while wait() do
  50.             box = box and box:Destroy() or nil
  51.             box = Instance.new("SelectionBox", LocalPlayer.PlayerGui)
  52.             box.Adornee = target
  53.             bpos.position = mouse.Hit.p + Vector3.new(0, height, 0)
  54.             bpos.maxForce = mouse.Target and Vector3.new(1, 1, 1) * mouse.Target:GetMass()^2 or Vector3.new()
  55.             if target then
  56.                 parts = DrawLightning(LocalPlayer.Character.Head.Position + Vector3.new(0, 2, 0), target.Position, 32, BrickColor.new 'Really red');
  57.                 for _, part in next, parts do game.Debris:AddItem(part, 0.05); end
  58.             end
  59.         end
  60.     end)
  61.    
  62.     mouse.Button1Down:connect(function()
  63.         if not mouse.Target then return end
  64.         gravitating = true
  65.         bpos.Parent = mouse.Target
  66.         target = mouse.Target
  67.     end)
  68.    
  69.     mouse.Button1Up:connect(function()
  70.         gravitating = false
  71.         bpos.Parent = nil
  72.         target = nil
  73.     end)
  74.    
  75.     mouse.KeyDown:connect(function(key)
  76.         if not gravitating then return end
  77.         if key:lower() == "e" then
  78.             local running = true
  79.             Spawn(function()
  80.                 while wait() and running do
  81.                     height = height + 1
  82.                 end
  83.             end)
  84.             repeat until mouse.KeyUp:wait():lower() == "e"
  85.             running = false
  86.         elseif key:lower() == "q" then
  87.             local running = true
  88.             Spawn(function()
  89.                 while wait() and running do
  90.                     height = height - 1
  91.                 end
  92.             end)
  93.             repeat until mouse.KeyUp:wait():lower() == "q"
  94.             running = false
  95.         end
  96.     end)
  97. end)
  98.  
  99. bin.Deselected:connect(function()
  100.     bpos.Parent = nil
  101.     target = nil
  102.     box = box and box:Destroy() or nil
  103.     gravitating = false
  104. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement