DarkHarw

Medic auto ability

Nov 13th, 2022
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.45 KB | None | 0 0
  1. --[[Rewrote the entire auto medic because it was messy
  2. - More features, such as min. towers stunned
  3. - A LOT more optimization, should produce 0 lag
  4. - Not adding distance checks because it's
  5. Credits to
  6. Gal. Sigmanic#6607 for some functions, such as troop detection
  7. Made my MintTea#9260
  8. ]]
  9. local suc,err = pcall(function()
  10. --Defining Variables
  11. local RS, TW, RF, LPSR = game:GetService("ReplicatedStorage"), workspace:WaitForChild("Towers"), game:GetService("ReplicatedStorage"):WaitForChild("RemoteFunction"), nil
  12. local Medics, MedicIndex, MedicAbility, MedicMicro, StunnedCount, status, library = {}, 0, false, false, 0, nil,loadstring(game:HttpGet("https://raw.githubusercontent.com/Sigmanic/ROBLOX/main/ModificationWallyUi", true))()
  13. local AbilityDelay = 2 --Change to 1.5, or 1. Whichever works best for you :)
  14. local Debug = true
  15. local TowersStunnedBeforeAbility = 1 --Default option. Can be changed in the GUI
  16. --Functions
  17. local function prints(v)
  18. if Debug then
  19. warn(v)
  20. end
  21. end
  22. local function microTower(tower,statuss)
  23. if statuss then
  24. status.Text = statuss
  25. end
  26. local frame = tower.HumanoidRootPart.CFrame
  27. local tname = tower.Replicator:GetAttribute("Type")
  28. local upgrade = tower.Replicator:GetAttribute("Upgrade")
  29. --Sell tower
  30. RF:InvokeServer("Troops","Sell",{Troop = tower})
  31. --Place tower
  32. tower = RF:InvokeServer("Troops","Place",tname,{Rotation = frame.Rotation,Position = frame.Position})
  33. --Upgrade tower
  34. for i = 1, upgrade do
  35. RF:InvokeServer("Troops","Upgrade","Set",{Troop = tower})
  36. end
  37. prints("Microed tower!")
  38. return towerMedics
  39. end
  40.  
  41. local function checkStun(tower) -- checks stuns of tower
  42. local stuns = tower.Replicator.Stuns
  43. for i,v in pairs(stuns:GetAttributes()) do
  44. if v == true then
  45. prints("Detected Stun!")
  46. return true
  47. end
  48. end
  49. return false
  50. end
  51.  
  52. local function Medic()
  53. if #Medics < 1 then
  54. return "Waiting for Medic..."
  55. end
  56. MedicIndex = (MedicIndex % #Medics) + 1
  57. local selectedMedic = Medics[MedicIndex]
  58. if selectedMedic.Replicator:GetAttribute("Upgrade") < 5 then
  59. return "Waiting for lvl 5 medic..."
  60. elseif StunnedCount < 1 then
  61. return "Waiting for stun..."
  62. end
  63. -- Use Ability
  64. if MedicAbility then
  65. StunnedCount = 0
  66. wait(AbilityDelay)
  67. if #Medics < 1 then return "You sold your medic ._." end
  68. if not selectedMedic then
  69. MedicIndex = (MedicIndex % #Medics) + 1
  70. selectedMedic = Medics[MedicIndex]
  71. end
  72. local Re = RF:InvokeServer("Troops","Abilities","Activate",{Troop = selectedMedic,Name = "Cleansing"})
  73. if not Re then --Ability on cooldown, micro medic
  74. if MedicMicro then
  75. if selectedMedic.Replicator:GetAttribute("Worth") > LPSR:GetAttribute("Cash") then return "You can't afford to Micro! Waiting..." end
  76. selectedMedic = microTower(selectedMedic)
  77. RF:InvokeServer("Troops","Abilities","Activate",{Troop = selectedMedic,Name = "Cleansing"})
  78. MedicIndex = MedicIndex + 1
  79. return "Successfully Microed Medic!"
  80. else
  81. return "Ability on cooldown... Waiting..."
  82. end
  83. else
  84. MedicIndex = MedicIndex + 1
  85. return "Successfully used Ability!"
  86. end
  87. else
  88. return "Medic Ability Not turned on!"
  89. end
  90. return "An error occured..."
  91. end
  92.  
  93. local function monitorTower(tower)
  94. if tower:FindFirstChild("Owner").Value and tower:FindFirstChild("Owner").Value == game:GetService("Players").LocalPlayer.UserId and tower.Replicator:GetAttribute("Type") == "Medic" then
  95. table.insert(Medics,tower)
  96. prints("Medic found! Adding to list...")
  97. status.Text = Medic()
  98. if tower.Replicator:GetAttribute("Upgrade") < 5 then
  99. local Temp = nil
  100. Temp = tower.Replicator:GetAttributeChangedSignal("Upgrade"):Connect(function()
  101. if tower.Parent == nil then
  102. Temp:Disconnect()
  103. return
  104. end
  105. if tower.Replicator:GetAttribute("Upgrade") == 5 then
  106. prints("Medic maxed!")
  107. status.Text = Medic()
  108. Temp:Disconnect()
  109. end
  110. end)
  111. end
  112. else
  113. prints("Found tower that isn't medic! Monitoring for stun...")
  114. if checkStun(tower) then
  115. StunnedCount = StunnedCount + 1
  116. if StunnedCount == TowersStunnedBeforeAbility then
  117. status.Text = Medic()
  118. spawn(function()
  119. prints("Stunned count reached! using abi...")
  120. wait(1)
  121. status.Text = Medic()
  122. end)
  123. end
  124. end
  125. tower.Replicator.Stuns.Changed:Connect(function()
  126. if checkStun(tower) then
  127. StunnedCount = StunnedCount + 1 --detects stuns, requests medic ability
  128. if StunnedCount == TowersStunnedBeforeAbility then
  129. status.Text = Medic()
  130. spawn(function()
  131. prints("Stunned count reached! using abi...")
  132. wait(1)
  133. status.Text = Medic()
  134. end)
  135. end
  136. end
  137. end)
  138. end
  139. end
  140.  
  141. --Initialization
  142. if not game:IsLoaded() then game.Loaded:Wait() end
  143. if getgenv().AlrExecMAC then
  144. game.StarterGui:SetCore("SendNotification", {
  145. Title = "Auto Medic V2",
  146. Text = "Script Already Executed.";
  147. Duration = 6;
  148. })
  149. return
  150. elseif game.PlaceId ~= 5591597781 then
  151. game.StarterGui:SetCore("SendNotification", {
  152. Title = "Auto Medic V2",
  153. Text = "Not in game! Killing script...";
  154. Duration = 6;
  155. })
  156. return
  157. else
  158. game.StarterGui:SetCore("SendNotification", {
  159. Title = "Auto Medic V2",
  160. Text = "Script Executed! Enjoy :)";
  161. Duration = 6;
  162. })
  163. end
  164. getgenv().AlrExecMAC = true
  165. for i,v in pairs(RS.StateReplicators:GetChildren()) do
  166. if v:GetAttribute("UserId") and v:GetAttribute("UserId") == game.Players.LocalPlayer.UserId then
  167. LPSR = v
  168. end
  169. end
  170. --Main Script
  171. local w = library:CreateWindow("Auto Medic Ability V2")
  172. w:Toggle("Auto Medic Abilities", {flag='enabled'}, function() MedicAbility = w.flags.enabled end)
  173. w:Toggle("Auto Micro Medics", {flag='microing'}, function() MedicMicro = w.flags.microing end)
  174. w:Slider("Min. Stuns",{min = 1, max = 20, pricise = true, flag = w.flags.mintower},function(value)
  175. value = tonumber(value)
  176. if not value then value = 1 end
  177. TowersStunnedBeforeAbility = value
  178. end)
  179. w:Button("Delete Gui",function()
  180. --w:DestroyGui() --Can't be used due to the latest UI loadstring being obfuscated and MM isn't gonna be happy
  181. for i,v in pairs(game:GetService("CoreGui"):GetDescendants()) do
  182. if v:IsA("Frame") and v.Name == "Auto Medic Ability V2" then
  183. v.Parent.Parent:Destroy()
  184. end
  185. end
  186. getgenv().TowerAddedM:Disconnect()
  187. getgenv().TowerRemovedM:Disconnect()
  188. StatusTable = nil
  189. getgenv().AlrExecMAC = false
  190. end)
  191. w:Section('Loading...')
  192. for i,v in pairs(game:GetService("CoreGui"):GetDescendants()) do
  193. if v:IsA("TextLabel") and v.Text == "Loading..." then
  194. status = v
  195. end
  196. end
  197.  
  198. for i,v in pairs(game:GetService("Workspace").Towers:GetChildren()) do
  199. monitorTower(v)
  200. end
  201.  
  202. getgenv().TowerAddedM = game:GetService("Workspace").Towers.ChildAdded:Connect(function(v)
  203. wait(.25)
  204. if not v:FindFirstChild("Replicator") then
  205. repeat wait() until v:FindFirstChild("Replicator")
  206. end
  207. monitorTower(v)
  208. end)
  209.  
  210. getgenv().TowerRemovedM = game:GetService("Workspace").Towers.ChildRemoved:Connect(function(v)
  211. if v:FindFirstChild("Owner").Value and v:FindFirstChild("Owner").Value == game:GetService("Players").LocalPlayer.UserId and v.Replicator:GetAttribute("Type") == "Medic" then
  212. for i,t in next,Medics do
  213. if t == v then
  214. table.remove(Medics,i)
  215. spawn(function()
  216. status.Text = "Medic Removed!"
  217. wait(1)
  218. status.Text = Medic()
  219. end)
  220. end
  221. end
  222. end
  223. end)
  224. status.Text = Medic()
  225. end)
  226. if not suc then warn(err) end
Add Comment
Please, Sign In to add comment