Advertisement
DropSquad

Head Cannon (Revision)

Mar 14th, 2015
319
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.74 KB | None | 0 0
  1. local Player = game.Players.LocalPlayer
  2. local Mouse = Player:GetMouse()
  3. repeat wait() until Player.Character
  4. local MyCharacter = Player.Character
  5. local Head = MyCharacter:WaitForChild('Head')
  6. local Template = Head:Clone()
  7. local Enabled = false
  8. local CoolDown = 2
  9. local LastAttack = tick()
  10. local Mode = 1
  11.  
  12. local Help = 'Controls: Q(true) - Enable/Disable, E - Change mode(1), Click - Fire, FocusLost - Target head'
  13. local ScreenGui = Instance.new('ScreenGui')
  14. local TextBox = Instance.new('TextBox', ScreenGui)
  15. TextBox.BackgroundTransparency = 0.5
  16. TextBox.BackgroundColor = BrickColor.Blue()
  17. TextBox.Size = UDim2.new(0.2, 0, 0.1, 0)
  18. TextBox.Position = UDim2.new(0.4, 0, 0, 0)
  19. TextBox.Font = Enum.Font.ArialBold
  20. TextBox.FontSize = Enum.FontSize.Size18
  21. TextBox.TextColor = BrickColor.White()
  22. TextBox.BorderSizePixel = 0
  23. TextBox.Text = Help
  24. TextBox.TextWrapped = true
  25. ScreenGui.Parent = Player.PlayerGui
  26.  
  27. TextBox.FocusLost:connect(function(Enter)
  28.     if Enter then
  29.         local PlayerName = TextBox.Text
  30.         local Character = workspace:FindFirstChild(PlayerName)
  31.         if Character then
  32.             local Found = Character:FindFirstChild('Head')
  33.             if Found then
  34.                 Template = Found:Clone()
  35.             else
  36.                 Template = Head:Clone()
  37.             end
  38.         end
  39.         TextBox.Text = Help
  40.     end
  41. end)
  42.  
  43. Mouse.KeyDown:connect(function(Key)
  44.     if Key == 'q' then
  45.         Enabled = not Enabled
  46.         local str = string.gsub(Help, '%(%a+%)', '(' .. tostring(Enabled) .. ')')
  47.         TextBox.Text = str
  48.     elseif Key == 'e' then
  49.         Mode = Mode == 1 and 2 or 1
  50.         local str = string.gsub(Help, '%d', Mode)
  51.         TextBox.Text = str
  52.     end
  53.     Help = TextBox.Text
  54. end)
  55.  
  56. Mouse.Button1Down:connect(function()
  57.     if not Enabled then return end
  58.     if tick() - LastAttack < CoolDown then return end
  59.     LastAttack = tick()
  60.     local Hit = Mouse.Hit
  61.     local HeadPosition = Head.Position
  62.     local Offset = Hit.p - HeadPosition
  63.     local Direction = Offset.unit
  64.     local SpawnPosition = HeadPosition + (5 * Direction)
  65.     local Projectile = Template:Clone()
  66.     local function onTouched(Hit)
  67.         if Hit:IsDescendantOf(MyCharacter) then return end
  68.         local Explosion = Instance.new('Explosion', workspace)
  69.         Explosion.BlastRadius = 20
  70.         Explosion.BlastPressure = 7E5
  71.         Explosion.Position = Projectile.Position
  72.         Projectile:Destroy()
  73.     end
  74.     local function attack(mode, object)
  75.         if mode == 1 then
  76.             object.Parent = workspace
  77.             object.CFrame = CFrame.new(SpawnPosition, Hit.p)
  78.             object:BreakJoints()
  79.             object.Velocity = 300 * Direction
  80.             game.Debris:AddItem(object, 5)
  81.         elseif mode == 2 then
  82.             local Expire = 20
  83.             local Target
  84.             local function FindNearestHead()
  85.                 local Distance = 70
  86.                 local Closest
  87.                 for Index, Instance in next, workspace:GetChildren() do
  88.                     if Instance:IsA('Model') then
  89.                         local Humanoid = Instance:FindFirstChild('Humanoid')
  90.                         if Humanoid then
  91.                             local Located = Instance:FindFirstChild('Head')
  92.                             if Located and Located ~= Head then
  93.                                 local Offset = Located.Position - Head.Position
  94.                                 if Offset.magnitude < Distance then
  95.                                     Distance = Offset.magnitude
  96.                                     Closest = Located
  97.                                 end
  98.                             end
  99.                         end
  100.                     end
  101.                 end
  102.                 return Closest
  103.             end
  104.             game.Debris:AddItem(object, Expire)
  105.             object.Parent = workspace
  106.             object.CanCollide = false
  107.             object.Anchored = true
  108.             object:BreakJoints()
  109.             for Value = 1, Expire * 30 do
  110.                 wait()
  111.                 object.CFrame = Head.CFrame * CFrame.new(5 * math.sin(math.rad(Value)), 0, 5 * math.cos(math.rad(Value)))
  112.                 Target = FindNearestHead()
  113.                 if Target then
  114.                     break
  115.                 end
  116.             end
  117.             if Target then
  118.                 object.Anchored = false
  119.                 object.Velocity = 700 * (Target.Position - Head.Position).unit
  120.             end
  121.         end
  122.     end
  123.     Projectile.Name = 'Explosive'
  124.     Projectile.Touched:connect(onTouched)
  125.     attack(Mode, Projectile)
  126. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement