Advertisement
Guest User

Master Wizard

a guest
Jan 23rd, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.56 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 collapsingsun = hum:LoadAnimation(script.Parent.CollapsingSun)
  7. local leftdodge = hum:LoadAnimation(script.Parent.LeftEvade)
  8. local healanim = hum:LoadAnimation(script.Parent.Heal)
  9. local bg = root.Aim
  10. local attackrange = 50
  11. local movetorange = 10
  12. local mana = 100
  13. local collapsingStarMana = 80
  14. local useMagicMana = 25
  15. local imAttackingSoYield = false
  16. local dodgecool = false
  17. local oldHealth = 1
  18. local allies = {script.Parent, "allyname"}
  19.  
  20. for i,part in pairs(script.Parent:GetChildren()) do
  21.     if part:IsA("BasePart") and part:CanSetNetworkOwnership() then
  22.         part:SetNetworkOwner(nil)
  23.     end
  24. end
  25.  
  26. function CheckBothAlive(checktarget, target)
  27.     if checktarget then
  28.         if hum.Health > 0 and target and target.Humanoid and target.Humanoid.Health > 0 then
  29.             return true
  30.         else
  31.             return false
  32.         end
  33.     else
  34.         if hum.Health > 0 then
  35.             return true
  36.         else
  37.             return false
  38.         end
  39.     end
  40. end
  41.  
  42. function Heal(amount)
  43.     if CheckBothAlive(false) then
  44.         healanim:Play()
  45.         local healball = game.ServerStorage.Magic.HealBall:Clone()
  46.         healball.Position = script.Parent.sunStaff.OrbAttach.WorldPosition
  47.         local weld = Instance.new("WeldConstraint")
  48.         weld.Parent = healball
  49.         weld.Part0 = script.Parent.sunStaff
  50.         weld.Part1 = healball
  51.         healball.Parent = workspace
  52.         game:GetService("Debris"):AddItem(healball, 0.5)
  53.         game:GetService("TweenService"):Create(healball, TweenInfo.new(0.3), {Size = Vector3.new(0.3,0.3,0.3)}):Play()
  54.         local heallight = game.ServerStorage.Magic.HealingLight:Clone()
  55.         game:GetService("Debris"):AddItem(heallight, 0.5)
  56.         local healingparticles = game.ServerStorage.Magic.HealingParticles:Clone()
  57.         game:GetService("Debris"):AddItem(healingparticles, 0.5)
  58.         heallight.Parent = root
  59.         game:GetService("TweenService"):Create(heallight, TweenInfo.new(0.5, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Range = 10}):Play()
  60.         healingparticles.Parent = root
  61.         healingparticles:Emit(150)
  62.         damage.HealDamage(hum.Parent, amount)
  63.     end
  64. end
  65.  
  66. function Dodge()
  67.     if not dodgecool and CheckBothAlive(false) then
  68.         dodgecool = true
  69.         FindTargets(1000)
  70.         local s = Instance.new("Smoke")
  71.         s.Parent = root
  72.         game:GetService("Debris"):AddItem(s, 0.15)
  73.         local co = coroutine.create(function()
  74.             wait(3)
  75.             dodgecool = false
  76.         end)
  77.         coroutine.resume(co)
  78.         leftdodge:Play()
  79.         local bv = Instance.new("BodyVelocity")
  80.         game:GetService("Debris"):AddItem(bv, 0.15)
  81.         bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
  82.         bv.Velocity = -root.CFrame.RightVector * 60
  83.         bv.Parent = root
  84.         if CheckBothAlive(false) then
  85.             Heal(oldHealth * 0.15)
  86.         end
  87.     end
  88. end
  89.  
  90. function RayToTarget(origin, target)
  91.     if CheckBothAlive(true, target) then
  92.         local ray = Ray.new(origin.Position, (target.HumanoidRootPart.Position - origin.Position).Unit * 30)
  93.         local part,pos = workspace:FindPartOnRayWithIgnoreList(ray, {script.Parent})
  94.         if part and part.Parent and part.Parent:FindFirstChild("Humanoid") then
  95.             if part:IsDescendantOf(target) then
  96.                 return true
  97.             end
  98.         else
  99.             return false
  100.         end
  101.     end
  102. end
  103.  
  104. function UseMagic(target)
  105.     if CheckBothAlive(true, target) then
  106.         sunanim:Play()
  107.         bg.CFrame = CFrame.new(root.Position, target.HumanoidRootPart.Position)
  108.         imAttackingSoYield = true
  109.         local magic = game.ServerStorage.Magic.LightBall:Clone()
  110.         magic.Position = Vector3.new(root.Position.X + 2, root.Position.Y, root.Position.Z)
  111.         game:GetService("TweenService"):Create(magic, TweenInfo.new(0.4, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = target.HumanoidRootPart.Position}):Play()
  112.         magic.Parent = workspace
  113.         magic:SetNetworkOwner(nil)
  114.         game:GetService("Debris"):AddItem(magic, 1)
  115.         if RayToTarget(script.Parent.Head, target) then
  116.             wait(0.3)
  117.             damage.DealDamage(target, math.random(script.Parent.DamageMin.Value, script.Parent.DamageMax.Value))
  118.         end
  119.         wait(1)
  120.         imAttackingSoYield = false
  121.     else
  122.        
  123.     end
  124. end
  125.  
  126. function CollapsingSun(target)
  127.     if CheckBothAlive(true, target) then
  128.         collapsingsun:Play()
  129.         bg.CFrame = CFrame.new(root.Position, target.HumanoidRootPart.Position)
  130.         imAttackingSoYield = true
  131.         local magic = game.ServerStorage.Magic.CollapsedSun:Clone()
  132.         magic.Position = Vector3.new(root.Position.X + 2, root.Position.Y + 11, root.Position.Z)
  133.         game:GetService("TweenService"):Create(magic, TweenInfo.new(0.55, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Position = target.HumanoidRootPart.Position}):Play()
  134.         magic.Parent = workspace
  135.         magic:SetNetworkOwner(nil)
  136.         game:GetService("Debris"):AddItem(magic, 1)
  137.         if RayToTarget(script.Parent.Head, target) then
  138.             wait(0.55)
  139.             damage.DealDamage(target, math.random(script.Parent.DamageMin.Value * 2, script.Parent.DamageMax.Value * 2))
  140.             local sunaoe = game.ServerStorage.Magic.SunAOE:Clone()
  141.             sunaoe.Position = target.HumanoidRootPart.Position
  142.             sunaoe.Parent = workspace
  143.             game:GetService("TweenService"):Create(sunaoe, TweenInfo.new(0.7, Enum.EasingStyle.Sine, Enum.EasingDirection.InOut), {Size = Vector3.new(30,30,30), Transparency = 1}):Play()
  144.             game:GetService("Debris"):AddItem(sunaoe, 2)
  145.         end
  146.         wait(3)
  147.         imAttackingSoYield = false
  148.     else
  149.        
  150.     end
  151. end
  152.  
  153. function GoTo(target, targetchar)
  154.     if not imAttackingSoYield and CheckBothAlive(true, targetchar) then
  155.         if Comparedist(root.Position, target, attackrange) then
  156.             if mana > collapsingStarMana then
  157.                 CollapsingSun(targetchar)
  158.                 mana = mana - 80
  159.             elseif mana > useMagicMana and mana < collapsingStarMana then
  160.                 UseMagic(targetchar)
  161.                 mana = mana - 25
  162.             end
  163.         else
  164.             local path = pathservice:CreatePath()
  165.        
  166.             path:ComputeAsync(root.Position, Vector3.new(target.X + movetorange, target.Y, target.Z))
  167.            
  168.             local waypoints = path:GetWaypoints()
  169.        
  170.             for i,waypoint in pairs(waypoints) do
  171.                 if path.Status == Enum.PathStatus.Success and not imAttackingSoYield then
  172.                     if waypoint.Action == Enum.PathWaypointAction.Jump then
  173.                         hum.Jump = true
  174.                     end
  175.                     bg.CFrame = CFrame.new(root.Position, targetchar.HumanoidRootPart.Position)
  176.                     hum:MoveTo(waypoint.Position)
  177.                 end
  178.             end
  179.         end
  180.     end
  181. end
  182.  
  183. function checkOverallValidity(target)
  184.     if target and target:FindFirstChild("Humanoid") and not table.find(allies, target.Name) and not table.find(allies, target) then
  185.         return true
  186.     else
  187.         return false
  188.     end
  189. end
  190.  
  191. function Comparedist(what, whatto, whatdist)
  192.     if (what - whatto).Magnitude < whatdist then
  193.         return true
  194.     else
  195.         return false
  196.     end
  197. end
  198.  
  199. function FindTargets(optionaldistoverride)
  200.     if not optionaldistoverride then
  201.         local detectionDistance = math.random(100,200)
  202.         for i,maybetarget in pairs(workspace:GetChildren()) do
  203.             if checkOverallValidity(maybetarget) then
  204.                 if Comparedist(root.Position, maybetarget.PrimaryPart.Position, detectionDistance) then
  205.                     detectionDistance = (root.Position - maybetarget.PrimaryPart.Position).Magnitude
  206.                     local co = coroutine.create(function()
  207.                         while wait(0.3) do
  208.                             if imAttackingSoYield then
  209.                                 break
  210.                             elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget) then
  211.                                 GoTo(maybetarget.PrimaryPart.Position, maybetarget)
  212.                             end
  213.                         end
  214.                     end)
  215.                     coroutine.resume(co)
  216.                 else
  217.                    
  218.                 end
  219.             end
  220.         end
  221.     else
  222.         local detectionDistance = optionaldistoverride
  223.         for i,maybetarget in pairs(workspace:GetChildren()) do
  224.             if checkOverallValidity(maybetarget) then
  225.                 if Comparedist(root.Position, maybetarget.PrimaryPart.Position, detectionDistance) then
  226.                     detectionDistance = (root.Position - maybetarget.PrimaryPart.Position).Magnitude
  227.                     local co = coroutine.create(function()
  228.                         while wait(0.3) do
  229.                             if imAttackingSoYield then
  230.                                 break
  231.                             elseif not imAttackingSoYield and CheckBothAlive(true, maybetarget) then
  232.                                 GoTo(maybetarget.PrimaryPart.Position, maybetarget)
  233.                             end
  234.                         end
  235.                     end)
  236.                     coroutine.resume(co)
  237.                 else
  238.                    
  239.                 end
  240.             end
  241.         end
  242.     end
  243. end
  244.  
  245. hum.HealthChanged:Connect(function(newhealth)
  246.     if hum.Health == hum.MaxHealth and hum.Health < 0 then
  247.         return
  248.     elseif oldHealth > newhealth then
  249.         Dodge()
  250.     end
  251. end)
  252.  
  253. while wait(2) do
  254.     oldHealth = hum.Health
  255.     FindTargets()
  256.     if mana < 100 then
  257.         mana = mana + 40
  258.     elseif mana > 100 then
  259.         mana = 100 
  260.     end
  261.     if not imAttackingSoYield and hum.Health ~= hum.MaxHealth then
  262.         Heal(math.random(script.Parent.DamageMin.Value * 0.20, script.Parent.DamageMax.Value * 0.50))
  263.     end
  264. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement