Advertisement
DuyOnline101

auto medic main

Aug 14th, 2023 (edited)
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.27 KB | None | 0 0
  1. --Locals
  2. local RS, TW, RF, LPSR = game:GetService("ReplicatedStorage"), workspace:WaitForChild("Towers"), game:GetService("ReplicatedStorage"):WaitForChild("RemoteFunction"), nil
  3. local Medics, MedicIndex, MedicAbility, MedicMicro, StunnedCount, status, library = {}, 0, false, true, 0, nil,loadstring(game:HttpGet("https://pastebin.com/N4mZbPUU", true))()
  4. local AbilityDelay = 2 --Change to 1.5, or 1. Whichever works best
  5. local Debounce = false
  6. local Debug = true
  7. local TowersStunnedBeforeAbility = 8 --Can be changed.
  8. local EngineMode = getgenv().EngineMode or false
  9. local FuncTable
  10. --Functions
  11. local function prints(v)
  12.     if Debug then
  13.         warn(v)
  14.     end
  15. end
  16. local function getStatus()
  17.     if status then
  18.         return status.Text
  19.     else
  20.         return ""
  21.     end
  22. end
  23. local function setStatus(v)
  24.     if status then
  25.         status.Text = v
  26.     else
  27.         warn(v)
  28.     end
  29. end
  30. local function microTower(tower)
  31.     setStatus("Microing Medic...")
  32.     local frame = tower.HumanoidRootPart.CFrame
  33.     local tname = tower.Replicator:GetAttribute("Type")
  34.     local upgrade = tower.Replicator:GetAttribute("Upgrade")
  35.     --Sell tower
  36.     RF:InvokeServer("Troops","Sell",{Troop = tower})
  37.     --Place tower
  38.     tower = RF:InvokeServer("Troops","Place",tname,{Rotation = frame.Rotation,Position = frame.Position})
  39.     --Upgrade tower
  40.     for i = 1, upgrade do
  41.         RF:InvokeServer("Troops","Upgrade","Set",{Troop = tower})
  42.     end
  43.     prints("Microed tower!")
  44.     return tower
  45. end
  46.  
  47. local function checkStun(tower) -- checks stuns of tower
  48.     local repl = tower:FindFirstChild("Replicator")
  49.     if not repl then return false end
  50.     local stuns = repl.Stuns
  51.     for i,v in pairs(stuns:GetAttributes()) do
  52.         if v == true then
  53.             prints("Detected Stun!")
  54.             return true
  55.         end
  56.     end
  57.     return false
  58. end
  59. local function refreshStun(medic)
  60.     local st = 0
  61.     for i,v in pairs(workspace.Towers:GetChildren()) do
  62.         if (medic.HumanoidRootPart.Position-v.HumanoidRootPart.Position).Magnitude <= medic.Replicator:GetAttribute("Range") and checkStun(v) then
  63.             st = st + 1
  64.         end
  65.     end
  66.     return st
  67. end
  68. local function Medic1()
  69.     if #Medics < 1 then
  70.         return "Waiting for Medic..."
  71.     end
  72.     MedicIndex = (MedicIndex % #Medics) + 1
  73.     local selectedMedic = Medics[MedicIndex]
  74.     if selectedMedic.Replicator:GetAttribute("Upgrade") < 5 then
  75.         return "Waiting for lvl 5 medic..."
  76.     elseif StunnedCount < 1 then
  77.         return "Waiting for stun..."
  78.     end
  79.         -- Use Ability
  80.     if MedicAbility then
  81.         wait(AbilityDelay)
  82.         if #Medics < 1 then return "You sold your medic ._." end
  83.         if not selectedMedic then
  84.             MedicIndex = (MedicIndex % #Medics) + 1
  85.             selectedMedic = Medics[MedicIndex]  
  86.         end
  87.         StunnedCount = refreshStun(selectedMedic)
  88.         MedicIndex = MedicIndex + 1
  89.         if selectedMedic.Replicator:GetAttribute("Upgrade") < 5 then
  90.             return "Waiting for lvl 5 medic..."
  91.         elseif StunnedCount < 1 then
  92.             return "Waiting for stun..."
  93.         end
  94.         local Re = RF:InvokeServer("Troops","Abilities","Activate",{Troop = selectedMedic,Name = "Cleansing"})
  95.         if not Re then --Ability on cooldown, micro medic
  96.             if MedicMicro then
  97.                 if selectedMedic.Replicator:GetAttribute("Worth") > LPSR:GetAttribute("Cash") then return "You can't afford to Micro! Waiting..." end
  98.                 selectedMedic = microTower(selectedMedic)
  99.                 RF:InvokeServer("Troops","Abilities","Activate",{Troop = selectedMedic,Name = "Cleansing"})      
  100.                 StunnedCount = refreshStun(selectedMedic)
  101.                 return "Used Ability!"
  102.             else
  103.                 return "Ability on cooldown... Waiting..."
  104.             end
  105.         else
  106.             StunnedCount = refreshStun(selectedMedic)
  107.             return "Used Ability!"
  108.         end
  109.     else
  110.         return "Medic Ability Not turned on!"
  111.     end
  112.     return "An error occured..."
  113. end
  114. local function Medic()
  115.     if not Debounce then
  116.         Debounce = true
  117.         local re = Medic1()
  118.         Debounce = false
  119.         return re or "An error occured..."
  120.     else
  121.         return getStatus()
  122.     end
  123. end
  124.  
  125. local function monitorTower(tower)
  126.     if tower:FindFirstChild("Owner").Value and tower:FindFirstChild("Owner").Value == game:GetService("Players").LocalPlayer.UserId and tower.Replicator:GetAttribute("Type") == "Medic" then
  127.         table.insert(Medics,tower)
  128.         prints("Medic found! Adding to list...")
  129.         setStatus(Medic())
  130.         if tower.Replicator:GetAttribute("Upgrade") < 5 then
  131.             local Temp = nil
  132.             Temp = tower.Replicator:GetAttributeChangedSignal("Upgrade"):Connect(function()
  133.                 if tower.Parent == nil then
  134.                     Temp:Disconnect()
  135.                     return
  136.                 end
  137.                 if tower.Replicator:GetAttribute("Upgrade") == 5 then
  138.                     prints("Medic maxed!")
  139.                     setStatus(Medic())
  140.                     Temp:Disconnect()
  141.                 end
  142.             end)
  143.         end
  144.     else  
  145.         prints("Found tower that isn't medic! Monitoring for stun...")
  146.         if checkStun(tower) then
  147.             StunnedCount = StunnedCount + 1
  148.             if StunnedCount >= TowersStunnedBeforeAbility then
  149.                 setStatus(Medic())
  150.                 prints("Stunned count reached! using abi...")
  151.             end
  152.         end
  153.         local stuns = tower.Replicator:WaitForChild("Stuns")
  154.         stuns.Changed:Connect(function()
  155.             if checkStun(tower) then
  156.                 StunnedCount = StunnedCount + 1 --detects stuns, requests medic ability
  157.                 if StunnedCount >= TowersStunnedBeforeAbility then
  158.                     setStatus(Medic())
  159.                     prints("Stunned count reached! using abi...")
  160.                 end
  161.             end
  162.         end)
  163.     end
  164. end
  165.  
  166. --Initialization
  167. if not game:IsLoaded() then game.Loaded:Wait() end
  168. if getgenv().AlrExec then
  169.     game.StarterGui:SetCore("SendNotification", {
  170.         Title = "Auto Medic",
  171.         Text = "Script Already Executed.";
  172.         Duration = 6;
  173.     })
  174.     return
  175. elseif game.PlaceId ~= 5591597781 then
  176.     game.StarterGui:SetCore("SendNotification", {
  177.         Title = "Auto Medic",
  178.         Text = "Not in game! Killing script...";
  179.         Duration = 6;
  180.     })
  181.     return
  182. else
  183.     game.StarterGui:SetCore("SendNotification", {
  184.         Title = "Auto Medic",
  185.         Text = "Script Executed! Enjoy :)";
  186.         Duration = 6;
  187.     })
  188. end
  189. getgenv().AlrExec = true
  190. for i,v in pairs(RS.StateReplicators:GetChildren()) do
  191.     if v:GetAttribute("UserId") and v:GetAttribute("UserId") == game.Players.LocalPlayer.UserId then
  192.         LPSR = v
  193.     end
  194. end
  195. --Main
  196. if EngineMode then
  197.     FuncTable = {
  198.         Enabled = function(v)
  199.             MedicAbility = v
  200.         end,
  201.         Micro = function(v)
  202.             MedicMicro = v
  203.         end,
  204.         MinStuns = function(v)
  205.             TowersStunnedBeforeAbility = v
  206.         end
  207.     }
  208. else
  209.     local w = library:CreateWindow("Auto Medic Ability V3")
  210.     w:Toggle("Auto Medic Abilities", {default = true, flag='enabled'}, function() MedicAbility = w.flags.enabled end)
  211.     w:Toggle("Auto Micro Medics", {flag='microing'}, function() MedicMicro = w.flags.microing end)
  212.     w:Slider("Min. Stuns",{min = 1, max = 20, default=5, precise = false, flag = w.flags.mintower},function(value)
  213.         value = tonumber(value)
  214.         if not value then value = 1 end
  215.         TowersStunnedBeforeAbility = value
  216.     end)
  217.     w:Button("Delete Gui",function()
  218.         --w:DestroyGui() --MM IS A NERD
  219.         for i,v in pairs(game:GetService("CoreGui"):GetDescendants()) do
  220.             if v:IsA("Frame") and v.Name == "Auto Medic Ability V3" then
  221.                 v.Parent.Parent:Destroy()
  222.             end
  223.         end
  224.         getgenv().TowerAddedM:Disconnect()
  225.         getgenv().TowerRemovedM:Disconnect()
  226.         StatusTable = nil
  227.         getgenv().AlrExecMAC = false
  228.     end)
  229.     w:Section('Loading...')
  230.     for i,v in pairs(game:GetService("CoreGui"):GetDescendants()) do
  231.         if v:IsA("TextLabel") and v.Text == "Loading..." then
  232.             status = v
  233.         end
  234.     end
  235. end
  236.  
  237. for i,v in pairs(game:GetService("Workspace").Towers:GetChildren()) do
  238.    monitorTower(v)
  239. end
  240.  
  241. getgenv().TowerAddedM = game:GetService("Workspace").Towers.ChildAdded:Connect(function(v)
  242.     wait(.25)
  243.     if not v:FindFirstChild("Replicator") then
  244.         repeat wait() until v:FindFirstChild("Replicator")
  245.     end
  246.     monitorTower(v)
  247. end)
  248.  
  249. getgenv().TowerRemovedM = game:GetService("Workspace").Towers.ChildRemoved:Connect(function(v)
  250.     if v:FindFirstChild("Owner").Value and v:FindFirstChild("Owner").Value == game:GetService("Players").LocalPlayer.UserId and v.Replicator:GetAttribute("Type") == "Medic" then
  251.         for i,t in next,Medics do
  252.             if t == v then
  253.                 table.remove(Medics,i)
  254.                 spawn(function()
  255.                     setStatus("Medic Removed!")
  256.                     wait(1)
  257.                     setStatus(Medic())
  258.                 end)            
  259.             end
  260.         end
  261.     end
  262. end)
  263. setStatus(Medic())
  264. if EngineMode then return FuncTable end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement