Advertisement
geethepaster

code

Jun 24th, 2018
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.60 KB | None | 0 0
  1. local PathFindingService = game:GetService("PathfindingService")
  2. local UIS = game:GetService("UserInputService")
  3. local event  = game.ReplicatedStorage.MageAttacks.Attack:WaitForChild("AttackEvent")
  4. local rStorage = game:GetService("ReplicatedStorage")
  5. local remoteFunction = rStorage.MageAttacks.Attack:WaitForChild("AttackFunction")
  6. local animation = Instance.new("Animation")
  7. animation.AnimationId = "http://www.roblox.com/asset/?id=1379182293"
  8. local player = game.Players.LocalPlayer
  9. local char = player.Character
  10. local hum = char.Humanoid
  11. local mouse = player:GetMouse()
  12. local end_p = nil
  13. local moving = false
  14. local attacking = false
  15. local enabled = true
  16. local my_target = nil
  17. local path = nil
  18. local waypoints = nil
  19. hum.WalkSpeed = char.Speed.Value
  20.  
  21. function Find_Obj()
  22.     local target = nil
  23.     if mouse.Target.Parent.Parent.Name == "IceMinions" then
  24.         print("yes")
  25.         target = mouse.Target.Parent.UpperTorso
  26.         return target
  27.     elseif mouse.Target.Parent.Parent.Name == "Firetowers" then
  28.         target = mouse.Target.Parent.UpperTorso
  29.         return target
  30.     else
  31.         target = nil
  32.     end
  33. end
  34.  
  35. function distance_to_object(obj)
  36.     local total = nil
  37.     if obj then
  38.         local magn = (obj.Position - char.UpperTorso.Position).magnitude
  39.         total = magn
  40.     end
  41.     return total
  42. end
  43.  
  44. function stop_start_moving(stop, start)
  45.     if stop == true and start == false then
  46.         start = false
  47.         hum.WalkSpeed = 0
  48.     elseif start == true and stop == false then
  49.         stop = false
  50.         hum.WalkSpeed = char.Speed.Value
  51.     end
  52. end
  53.  
  54. local function onKeyPress(target)
  55.     if not enabled then return end
  56.     if attacking == false then return end
  57.     local animTrack = hum:LoadAnimation(animation)
  58.     enabled = false
  59.     wait(.01)
  60.     animTrack:Play()
  61.     remoteFunction:InvokeServer("Fire Arcane Ball", target)
  62.     enabled = true
  63.     animTrack:Stop()
  64.        
  65. end
  66. local distance
  67.  
  68. if not my_target or my_target == nil then my_target = nil end
  69. UIS.InputBegan:Connect(function(input)
  70.     if input.UserInputType == Enum.UserInputType.MouseButton2 then
  71.         my_target = Find_Obj()
  72.         if my_target ~= nil then
  73.             attacking = true
  74.         else
  75.             attacking = false
  76.         end
  77.         end_p = mouse.Hit.p
  78.         moving = true
  79.        
  80.         while wait() do
  81.             -----------------Move-----------------
  82.             hum.WalkSpeed = char.Speed.Value
  83.             if moving == true then
  84.                 stop_start_moving(false, true)
  85.                 if my_target then
  86.                     path = nil
  87.                     waypoints = nil
  88.                     path = PathFindingService:FindPathAsync(char.UpperTorso.Position, my_target.Position)
  89.                     waypoints = path:GetWaypoints()
  90.                     for _, waypoint in pairs(waypoints) do
  91.                         char.Humanoid:MoveTo(waypoint.Position)
  92.                         repeat
  93.                             distance = (waypoint.Position - char.HumanoidRootPart.Position).magnitude
  94.                             wait()
  95.                         until
  96.                             distance <= 5
  97.                     end
  98.                 else
  99.                     path = nil
  100.                     waypoints = nil
  101.                     path = PathFindingService:FindPathAsync(char.UpperTorso.Position, end_p)
  102.                     waypoints = path:GetWaypoints()
  103.                     for _, waypoint in pairs(waypoints) do
  104.                         repeat
  105.                             char.Humanoid:MoveTo(waypoint.Position)
  106.                             distance = (waypoint.Position - char.HumanoidRootPart.Position).magnitude
  107.                             wait()
  108.                         until
  109.                             distance <= 5
  110.                     end
  111.                 end
  112.                
  113.                 moving = false
  114.             end
  115.            
  116.             -----------------Attack-----------------
  117.            
  118.             if attacking == true then
  119.                 if moving == false then
  120.                     if my_target then
  121.                         if distance_to_object(my_target) < 30 then
  122.                             print("agh")
  123.                             stop_start_moving(true, false)
  124.                             onKeyPress(my_target)
  125.                             if my_target.Parent.Humanoid.Health == 0 then
  126.                                 attacking = false
  127.                             end
  128.                         end
  129.                     end
  130.                 end
  131.             end
  132.         end
  133.     end
  134. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement