Advertisement
NoTextForSpeech

tds auto medic

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