Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.75 KB | None | 0 0
  1. local pathservice = game:GetService("PathfindingService")
  2. local root = script.Parent.HumanoidRootPart
  3. local hum = script.Parent.Humanoid
  4. local damage = require(game.ServerScriptService.Damagehandler)
  5. local sunanim = hum:LoadAnimation(script.Parent.SunBall)
  6. local leftdodge = hum:LoadAnimation(script.Parent.LeftEvade)
  7. local bg = root.Aim
  8. local attackrange = 30
  9. local movetorange = 10
  10. local imAttackingSoYield = false
  11. local dodgecool = false
  12.  
  13. for i,part in pairs(script.Parent:GetChildren()) do
  14.     if part:IsA("BasePart") and part:CanSetNetworkOwnership() then
  15.         part:SetNetworkOwner(nil)
  16.     end
  17. end
  18.  
  19. function CheckBothAlive(checktarget, target)
  20.     if checktarget then
  21.         if hum.Health > 0 and target and target.Humanoid and target.Humanoid.Health > 0 then
  22.             return true
  23.         else
  24.             return false
  25.         end
  26.     else
  27.         if hum.Health > 0 then
  28.             return true
  29.         else
  30.             return false
  31.         end
  32.     end
  33. end
  34.  
  35. function Dodge()
  36.     if not dodgecool and CheckBothAlive(false) then
  37.         dodgecool = true
  38.         FindTargets(1000)
  39.         local s = Instance.new("Smoke")
  40.         s.Parent = root
  41.         game:GetService("Debris"):AddItem(s, 0.15)
  42.         local co = coroutine.create(function()
  43.             wait(3)
  44.             dodgecool = false
  45.         end)
  46.         coroutine.resume(co)
  47.         leftdodge:Play()
  48.         local bv = Instance.new("BodyVelocity")
  49.         game:GetService("Debris"):AddItem(bv, 0.15)
  50.         bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  51.         bv.Velocity = -root.CFrame.RightVector * 60
  52.         bv.Parent = root
  53.     end
  54. end
  55.  
  56. function RayToTarget(origin, target)
  57.     if CheckBothAlive(true, target) then
  58.         local ray = Ray.new(origin.Position, (target.HumanoidRootPart.Position - origin.Position).Unit * 30)
  59.         local part,pos = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
  60.         if part and part.Parent and part.Parent:FindFirstChild("Humanoid") then
  61.             if part:IsDescendantOf(target) then
  62.                 print("ray succesfull")
  63.                 return true
  64.             end
  65.         else
  66.             print("failed to ray")
  67.             return false
  68.         end
  69.     end
  70. end
  71.  
  72. function UseMagic(target)
  73.     if CheckBothAlive(true, target) then
  74.         sunanim:Play()
  75.         bg.CFrame = CFrame.new(root.Position, target.HumanoidRootPart.Position)
  76.         imAttackingSoYield = true
  77.         local magic = game.ServerStorage.Magic.LightBall:Clone()
  78.         magic.Position = Vector3.new(root.Position.X + 2, root.Position.Y, root.Position.Z)
  79.         local bv = Instance.new("BodyVelocity")
  80.         bv.Parent = magic
  81.         bv.Velocity = (target.PrimaryPart.Position - root.Position).unit * 50
  82.         magic.Parent = workspace
  83.         magic:SetNetworkOwner(nil)
  84.         game:GetService("Debris"):AddItem(magic, 1)
  85.         if RayToTarget(script.Parent.Head, target) then
  86.             wait(0.3)
  87.             damage.DealDamage(target, math.random(script.Parent.DamageMin.Value, script.Parent.DamageMax.Value))
  88.         end
  89.         wait(1)
  90.         imAttackingSoYield = false
  91.     end
  92. end
  93.  
  94. function GoTo(target, targetchar)
  95.     if not imAttackingSoYield and CheckBothAlive(true, targetchar) then
  96.         if Comparedist(root.Position, target, attackrange) then
  97.             UseMagic(targetchar)
  98.         else
  99.             local path = pathservice:CreatePath()
  100.        
  101.             path:ComputeAsync(root.Position, Vector3.new(target.X + movetorange, target.Y, target.Z))
  102.            
  103.             local waypoints = path:GetWaypoints()
  104.        
  105.             for i,waypoint in pairs(waypoints) do
  106.                 if path.Status == Enum.PathStatus.Success and not imAttackingSoYield then
  107.                     if waypoint.Action == Enum.PathWaypointAction.Jump then
  108.                         hum.Jump = true
  109.                     end
  110.                     bg.CFrame = CFrame.new(root.Position, targetchar.HumanoidRootPart.Position)
  111.                     hum:MoveTo(waypoint.Position)
  112.                 end
  113.             end
  114.         end
  115.     end
  116. end
  117.  
  118. function checkOverallValidity(target)
  119.     if target and target.Parent and target.PrimaryPart and target ~= script.Parent and target.Humanoid and CheckBothAlive(true, target) then
  120.         return true
  121.     else
  122.         return false
  123.     end
  124. end
  125.  
  126. function Comparedist(what, whatto, whatdist)
  127.     if (what - whatto).Magnitude < whatdist then
  128.         return true
  129.     else
  130.         return false
  131.     end
  132. end
  133.  
  134. function FindTargets(optionaldistoverride)
  135.     if not optionaldistoverride then
  136.         local detectionDistance = math.random(100,200)
  137.         for i,maybetarget in pairs(game.Players:GetPlayers()) do
  138.             if checkOverallValidity(maybetarget.Character) then
  139.                 if Comparedist(root.Position, maybetarget.Character.PrimaryPart.Position, detectionDistance) then
  140.                     detectionDistance = (root.Position - maybetarget.Character.PrimaryPart.Position).Magnitude
  141.                     GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
  142.                     local co = coroutine.create(function()
  143.                         while wait(0.3) do
  144.                             if imAttackingSoYield then
  145.                                 break
  146.                             elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget.Character) then
  147.                                 GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
  148.                             end
  149.                         end
  150.                     end)
  151.                     coroutine.resume(co)
  152.                 else
  153.                    
  154.                 end
  155.             end
  156.         end
  157.     else
  158.         local detectionDistance = optionaldistoverride
  159.         for i,maybetarget in pairs(game.Players:GetPlayers()) do
  160.             if checkOverallValidity(maybetarget.Character) then
  161.                 if Comparedist(root.Position, maybetarget.Character.PrimaryPart.Position, detectionDistance) then
  162.                     detectionDistance = (root.Position - maybetarget.Character.PrimaryPart.Position).Magnitude
  163.                     GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
  164.                     local co = coroutine.create(function()
  165.                         while wait(0.3) do
  166.                             if imAttackingSoYield then
  167.                                 break
  168.                             elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget.Character) then
  169.                                 GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
  170.                             end
  171.                         end
  172.                     end)
  173.                     coroutine.resume(co)
  174.                 else
  175.                    
  176.                 end
  177.             end
  178.         end
  179.     end
  180. end
  181.  
  182. hum.HealthChanged:Connect(function(healthsubbed)
  183.     if hum.Health == hum.MaxHealth and hum.Health > 0 then
  184.         return
  185.     else
  186.         Dodge()
  187.     end
  188. end)
  189.  
  190. while wait(2) do
  191.     FindTargets()
  192. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement