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 collapsingsun = hum:LoadAnimation(script.Parent.CollapsingSun)
- local leftdodge = hum:LoadAnimation(script.Parent.LeftEvade)
- local healanim = hum:LoadAnimation(script.Parent.Heal)
- local bg = root.Aim
- local attackrange = 50
- local movetorange = 10
- local mana = 100
- local collapsingStarMana = 80
- local useMagicMana = 25
- local imAttackingSoYield = false
- local dodgecool = false
- local oldHealth = 1
- local allies = {script.Parent, "allyname"}
- 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 Heal(amount)
- if CheckBothAlive(false) then
- healanim:Play()
- local healball = game.ServerStorage.Magic.HealBall:Clone()
- healball.Position = script.Parent.sunStaff.OrbAttach.WorldPosition
- local weld = Instance.new("WeldConstraint")
- weld.Parent = healball
- weld.Part0 = script.Parent.sunStaff
- weld.Part1 = healball
- healball.Parent = workspace
- game:GetService("Debris"):AddItem(healball, 0.5)
- game:GetService("TweenService"):Create(healball, TweenInfo.new(0.3), {Size = Vector3.new(0.3,0.3,0.3)}):Play()
- local heallight = game.ServerStorage.Magic.HealingLight:Clone()
- game:GetService("Debris"):AddItem(heallight, 0.5)
- local healingparticles = game.ServerStorage.Magic.HealingParticles:Clone()
- game:GetService("Debris"):AddItem(healingparticles, 0.5)
- heallight.Parent = root
- game:GetService("TweenService"):Create(heallight, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Range = 10}):Play()
- healingparticles.Parent = root
- healingparticles:Emit(150)
- damage.HealDamage(hum.Parent, amount)
- 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
- if CheckBothAlive(false) then
- Heal(oldHealth * 0.15)
- end
- 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
- return true
- end
- else
- 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)
- game:GetService("TweenService"):Create(magic, TweenInfo.new(0.4, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = target.HumanoidRootPart.Position}):Play()
- 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
- else
- end
- end
- function CollapsingSun(target)
- if CheckBothAlive(true, target) then
- collapsingsun:Play()
- bg.CFrame = CFrame.new(root.Position, target.HumanoidRootPart.Position)
- imAttackingSoYield = true
- local magic = game.ServerStorage.Magic.CollapsedSun:Clone()
- magic.Position = Vector3.new(root.Position.X + 2, root.Position.Y + 11, root.Position.Z)
- game:GetService("TweenService"):Create(magic, TweenInfo.new(0.55, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = target.HumanoidRootPart.Position}):Play()
- magic.Parent = workspace
- magic:SetNetworkOwner(nil)
- game:GetService("Debris"):AddItem(magic, 1)
- if RayToTarget(script.Parent.Head, target) then
- wait(0.55)
- damage.DealDamage(target, math.random(script.Parent.DamageMin.Value * 2, script.Parent.DamageMax.Value * 2))
- local sunaoe = game.ServerStorage.Magic.SunAOE:Clone()
- sunaoe.Position = target.HumanoidRootPart.Position
- sunaoe.Parent = workspace
- game:GetService("TweenService"):Create(sunaoe, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Size = Vector3.new(30,30,30), Transparency = 1}):Play()
- game:GetService("Debris"):AddItem(sunaoe, 2)
- end
- wait(3)
- imAttackingSoYield = false
- else
- end
- end
- function GoTo(target, targetchar)
- if not imAttackingSoYield and CheckBothAlive(true, targetchar) then
- if Comparedist(root.Position, target, attackrange) then
- if mana > collapsingStarMana then
- CollapsingSun(targetchar)
- mana = mana - 80
- elseif mana > useMagicMana and mana < collapsingStarMana then
- UseMagic(targetchar)
- mana = mana - 25
- end
- 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:FindFirstChild("Humanoid") and not table.find(allies, target.Name) and not table.find(allies, 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(workspace:GetChildren()) do
- if checkOverallValidity(maybetarget) then
- if Comparedist(root.Position, maybetarget.PrimaryPart.Position, detectionDistance) then
- detectionDistance = (root.Position - maybetarget.PrimaryPart.Position).Magnitude
- local co = coroutine.create(function()
- while wait(0.3) do
- if imAttackingSoYield then
- break
- elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget) then
- GoTo(maybetarget.PrimaryPart.Position, maybetarget)
- end
- end
- end)
- coroutine.resume(co)
- else
- end
- end
- end
- else
- local detectionDistance = optionaldistoverride
- for i,maybetarget in pairs(workspace:GetChildren()) do
- if checkOverallValidity(maybetarget) then
- if Comparedist(root.Position, maybetarget.PrimaryPart.Position, detectionDistance) then
- detectionDistance = (root.Position - maybetarget.PrimaryPart.Position).Magnitude
- local co = coroutine.create(function()
- while wait(0.3) do
- if imAttackingSoYield then
- break
- elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget) then
- GoTo(maybetarget.PrimaryPart.Position, maybetarget)
- end
- end
- end)
- coroutine.resume(co)
- else
- end
- end
- end
- end
- end
- hum.HealthChanged:Connect(function(newhealth)
- if hum.Health == hum.MaxHealth and hum.Health < 0 then
- return
- elseif oldHealth > newhealth then
- Dodge()
- end
- end)
- while wait(2) do
- oldHealth = hum.Health
- FindTargets()
- if mana < 100 then
- mana = mana + 40
- elseif mana > 100 then
- mana = 100
- end
- if not imAttackingSoYield and hum.Health ~= hum.MaxHealth then
- Heal(math.random(script.Parent.DamageMin.Value * 0.20, script.Parent.DamageMax.Value * 0.50))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement