Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pathservice = game:GetService("PathfindingService")
- local root = script.Parent.HumanoidRootPart
- local hum = script.Parent.Humanoid
- local damage = require(game.ServerScriptService.Damagehandler)
- local sunanim = hum:LoadAnimation(script.Parent.SunBall)
- local leftdodge = hum:LoadAnimation(script.Parent.LeftEvade)
- local bg = root.Aim
- local attackrange = 30
- local movetorange = 10
- local imAttackingSoYield = false
- local dodgecool = false
- for i,part in pairs(script.Parent:GetChildren()) do
- if part:IsA("BasePart") and part:CanSetNetworkOwnership() then
- part:SetNetworkOwner(nil)
- end
- end
- function CheckBothAlive(checktarget, target)
- if checktarget then
- if hum.Health > 0 and target and target.Humanoid and target.Humanoid.Health > 0 then
- return true
- else
- return false
- end
- else
- if hum.Health > 0 then
- return true
- else
- return false
- end
- end
- end
- function Dodge()
- if not dodgecool and CheckBothAlive(false) then
- dodgecool = true
- FindTargets(1000)
- local s = Instance.new("Smoke")
- s.Parent = root
- game:GetService("Debris"):AddItem(s, 0.15)
- local co = coroutine.create(function()
- wait(3)
- dodgecool = false
- end)
- coroutine.resume(co)
- leftdodge:Play()
- local bv = Instance.new("BodyVelocity")
- game:GetService("Debris"):AddItem(bv, 0.15)
- bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
- bv.Velocity = -root.CFrame.RightVector * 60
- bv.Parent = root
- end
- end
- function RayToTarget(origin, target)
- if CheckBothAlive(true, target) then
- local ray = Ray.new(origin.Position, (target.HumanoidRootPart.Position - origin.Position).Unit * 30)
- local part,pos = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
- if part and part.Parent and part.Parent:FindFirstChild("Humanoid") then
- if part:IsDescendantOf(target) then
- print("ray succesfull")
- return true
- end
- else
- print("failed to ray")
- return false
- end
- end
- end
- function UseMagic(target)
- if CheckBothAlive(true, target) then
- sunanim:Play()
- bg.CFrame = CFrame.new(root.Position, target.HumanoidRootPart.Position)
- imAttackingSoYield = true
- local magic = game.ServerStorage.Magic.LightBall:Clone()
- magic.Position = Vector3.new(root.Position.X + 2, root.Position.Y, root.Position.Z)
- local bv = Instance.new("BodyVelocity")
- bv.Parent = magic
- bv.Velocity = (target.PrimaryPart.Position - root.Position).unit * 50
- magic.Parent = workspace
- magic:SetNetworkOwner(nil)
- game:GetService("Debris"):AddItem(magic, 1)
- if RayToTarget(script.Parent.Head, target) then
- wait(0.3)
- damage.DealDamage(target, math.random(script.Parent.DamageMin.Value, script.Parent.DamageMax.Value))
- end
- wait(1)
- imAttackingSoYield = false
- end
- end
- function GoTo(target, targetchar)
- if not imAttackingSoYield and CheckBothAlive(true, targetchar) then
- if Comparedist(root.Position, target, attackrange) then
- UseMagic(targetchar)
- else
- local path = pathservice:CreatePath()
- path:ComputeAsync(root.Position, Vector3.new(target.X + movetorange, target.Y, target.Z))
- local waypoints = path:GetWaypoints()
- for i,waypoint in pairs(waypoints) do
- if path.Status == Enum.PathStatus.Success and not imAttackingSoYield then
- if waypoint.Action == Enum.PathWaypointAction.Jump then
- hum.Jump = true
- end
- bg.CFrame = CFrame.new(root.Position, targetchar.HumanoidRootPart.Position)
- hum:MoveTo(waypoint.Position)
- end
- end
- end
- end
- end
- function checkOverallValidity(target)
- if target and target.Parent and target.PrimaryPart and target ~= script.Parent and target.Humanoid and CheckBothAlive(true, target) then
- return true
- else
- return false
- end
- end
- function Comparedist(what, whatto, whatdist)
- if (what - whatto).Magnitude < whatdist then
- return true
- else
- return false
- end
- end
- function FindTargets(optionaldistoverride)
- if not optionaldistoverride then
- local detectionDistance = math.random(100,200)
- for i,maybetarget in pairs(game.Players:GetPlayers()) do
- if checkOverallValidity(maybetarget.Character) then
- if Comparedist(root.Position, maybetarget.Character.PrimaryPart.Position, detectionDistance) then
- detectionDistance = (root.Position - maybetarget.Character.PrimaryPart.Position).Magnitude
- GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
- local co = coroutine.create(function()
- while wait(0.3) do
- if imAttackingSoYield then
- break
- elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget.Character) then
- GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
- end
- end
- end)
- coroutine.resume(co)
- else
- end
- end
- end
- else
- local detectionDistance = optionaldistoverride
- for i,maybetarget in pairs(game.Players:GetPlayers()) do
- if checkOverallValidity(maybetarget.Character) then
- if Comparedist(root.Position, maybetarget.Character.PrimaryPart.Position, detectionDistance) then
- detectionDistance = (root.Position - maybetarget.Character.PrimaryPart.Position).Magnitude
- GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
- local co = coroutine.create(function()
- while wait(0.3) do
- if imAttackingSoYield then
- break
- elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget.Character) then
- GoTo(maybetarget.Character.PrimaryPart.Position, maybetarget.Character)
- end
- end
- end)
- coroutine.resume(co)
- else
- end
- end
- end
- end
- end
- hum.HealthChanged:Connect(function(healthsubbed)
- if hum.Health == hum.MaxHealth and hum.Health > 0 then
- return
- else
- Dodge()
- end
- end)
- while wait(2) do
- FindTargets()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement