eruaaaaaaa

Untitled

Sep 5th, 2022
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.04 KB | None | 0 0
  1. local Aimbot = {}
  2. Aimbot.__index = Aimbot
  3.  
  4. --//Localization
  5. local Instance = Instance
  6. local game = game
  7. local math = math
  8. local setmetatable = setmetatable
  9. local workspace = workspace
  10. local CFrame = CFrame
  11. local Vector3 = Vector3
  12. local Vector2 = Vector2
  13. local Random = Random
  14. local RaycastParams = RaycastParams
  15. local pairs = pairs
  16. local string = string
  17. local table = table
  18. local Enum = Enum
  19. local getrawmetatable = getrawmetatable
  20. local replaceclosure = replaceclosure
  21. local setreadonly = setreadonly
  22. local checkcaller = checkcaller
  23. local getclock = os.clock
  24. local mouse1press = mouse1press
  25. local mouse1release = mouse1release
  26. local mousemoverel = mousemoverel
  27. local hookfunction = hookfunction
  28. local newcclosure = newcclosure
  29.  
  30. --//Instance methods
  31. local Raycast = workspace.Raycast
  32. local GetPropertyChangedSignal = game.GetPropertyChangedSignal
  33. local Connect = game.ChildAdded.Connect
  34. local Destroy = game.Destroy
  35. local GetService = game.GetService
  36. local FindFirstChildOfClass = game.FindFirstChildOfClass
  37. local FindFirstChild = game.FindFirstChild
  38. local GetChildren = game.GetChildren
  39. local IsA = game.IsA
  40. local IsDescendantOf = game.IsDescendantOf
  41.  
  42. --//Services
  43. local Players = GetService(game, "Players")
  44. local UserInputService = GetService(game, "UserInputService")
  45. local RunService = GetService(game, "RunService")
  46. local GuiService = GetService(game, "GuiService")
  47.  
  48. --//Temporary instances
  49. local tempcam = Instance.new("Camera")
  50. local tempconn = Connect(game.AncestryChanged, function() end)
  51.  
  52. --//Other instance methods
  53. local WorldToViewportPoint = tempcam.WorldToViewportPoint
  54. local WorldToScreenPoint = tempcam.WorldToScreenPoint
  55. local GetPlayers = Players.GetPlayers
  56. local GetMouseLocation = UserInputService.GetMouseLocation
  57. local ViewportPointToRay = tempcam.ViewportPointToRay
  58. local Disconnect = tempconn.Disconnect
  59. local Lerp2D = Vector2.new().Lerp
  60.  
  61. --//Cleanup
  62. Destroy(tempcam)
  63. Disconnect(tempconn)
  64.  
  65. --//Local functions and constant variables
  66. Aimbot.DefaultSettings = {
  67. RadiusPercentAt1 = 130, --//Radius percent of screen width at 1 stud for aimbot
  68. XSmoothingPercent = .125,
  69. YSmoothingPercent = .15, --//Slows down mouse movement by a percentage of screen width
  70. DistanceBias = 1, --//Raises sensitivity of distance from camera when choosing target
  71. Offset = Vector2.new(0, 0), --//Mouse offset in pixels
  72. SilentRadiusPercentAt1 = 130, --//Radius percent of screen width at 1 stud for silent aim
  73. IgnoreTransparent = true, --//Whether to ignore transparent parts above the threshold or not in wallcheck
  74. IgnoreWater = false, --//Whether to ignore water in wallcheck
  75. TransparencyThreshold = .5, --//Threshold for what transparency or greater counts as ignorable
  76. DefaultIgnore = {}, --//List for what the aimbot should ignore during wallcheck
  77. IsAliveCheck = true, --//Ignore dead players
  78. TeamCheck = true,
  79. TriggerBot = true
  80. }
  81.  
  82. local LocalPlayer = Players.LocalPlayer
  83. local Mouse = LocalPlayer.GetMouse(LocalPlayer)
  84. local GuiInset = GuiService.GetGuiInset(GuiService)
  85. local GameMeta = getrawmetatable(game)
  86.  
  87. local function OnCameraChange()
  88. local cam = workspace.CurrentCamera
  89.  
  90. Aimbot.Camera = cam
  91. Aimbot.ViewportSize = cam.ViewportSize
  92. Aimbot.WidthFactor = cam.ViewportSize.X / 100
  93. end
  94.  
  95. local function UpdateTable(tab, update)
  96. for name, value in pairs(update) do
  97. if tab[name] == nil then
  98. tab[name] = value
  99. end
  100. end
  101. end
  102.  
  103. local function GetChildrenWhichIsA(part, baseclass)
  104. local parts = GetChildren(part)
  105. local len = #parts
  106.  
  107. local filtered = {}
  108.  
  109. if len > 0 then
  110. for i = 1, len do
  111. local p = parts[i]
  112.  
  113. if IsA(p, baseclass) then
  114. table.insert(filtered, p)
  115. end
  116. end
  117. end
  118.  
  119. return filtered
  120. end
  121.  
  122.  
  123. local function GetChildrenWhichIsNotA(part, baseclass)
  124. local parts = GetChildren(part)
  125. local len = #parts
  126.  
  127. local filtered = {}
  128.  
  129. if len > 0 then
  130. for i = 1, len do
  131. local p = parts[i]
  132.  
  133. if not IsA(p, baseclass) then
  134. table.insert(filtered, p)
  135. end
  136. end
  137. end
  138.  
  139. return filtered
  140. end
  141.  
  142. if workspace.CurrentCamera then
  143. OnCameraChange()
  144. end
  145.  
  146. Connect(GetPropertyChangedSignal(workspace, "CurrentCamera"), OnCameraChange)
  147.  
  148. --//Methods
  149.  
  150. --//Gets bias value at a given distance
  151. function Aimbot:GetBiasAtDistance(distance)
  152. if self.Camera then
  153. return distance * self.DistanceBias * self.WidthFactor
  154. end
  155. end
  156.  
  157. --//Gets circle radius at a given distance
  158. function Aimbot:GetRadiusAtDistance(rpercent, distance)
  159. if self.Camera then
  160. return rpercent / distance * self.WidthFactor
  161. end
  162. end
  163.  
  164. --//Checks for parts obscuring camera, including terrain - unlike Camera:GetPartsObscuringTarget
  165. function Aimbot:GetBlockingPart(origin, position, ignore)
  166. self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore --//Incase it got updated
  167.  
  168. local dir = position - origin
  169. local thisignore = self.WallCheckParams.FilterDescendantsInstances --//Copies table for you essentially
  170.  
  171. if ignore then
  172. table.move(ignore, 1, #ignore, #thisignore + 1, thisignore)
  173. end
  174.  
  175. while true do
  176. self.WallCheckParams.FilterDescendantsInstances = thisignore --//Copies
  177. local result = Raycast(workspace, origin, dir, self.WallCheckParams)
  178.  
  179. if result then
  180. if self.IgnoreTransparent and result.Instance.ClassName ~= "Terrain" and result.Instance.Transparency >= self.TransparencyThreshold then
  181. table.insert(thisignore, result.Instance)
  182. continue
  183. end
  184.  
  185. self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore
  186. return result.Instance
  187. end
  188.  
  189. self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore
  190. return nil
  191. end
  192. end
  193.  
  194. --//Gets target from viewport point
  195. function Aimbot:GetTargetFromViewportPoint(point, distance, ignore)
  196. local camera = self.Camera
  197.  
  198. if camera then
  199. local ray = ViewportPointToRay(camera, point.X, point.Y)
  200. return self:GetBlockingPart(ray.Origin, ray.Origin + ray.Direction * distance, ignore)
  201. end
  202. end
  203.  
  204. --//Gets closest edge on part from viewport point
  205. function Aimbot:GetClosestEdgeFromViewportPoint(point, part)
  206. local camera = self.Camera
  207.  
  208. if camera then
  209. local ray = ViewportPointToRay(camera, point.X, point.Y)
  210. local ppos = part.Position
  211.  
  212. local dist = (ray.Origin - ppos).Magnitude
  213. local dir = (ray.Origin + ray.Direction * dist - ppos).Unit
  214.  
  215. local size = part.Size
  216.  
  217. local half = size / 2
  218. local final = dir * size
  219.  
  220. return ppos + Vector3.new(
  221. final.X < 0 and math.max(final.X, -half.X + size.X / 10) or math.min(final.X, half.X - size.X / 10),
  222. final.Y < 0 and math.max(final.Y, -half.Y + size.Y / 10) or math.min(final.Y, half.Y - size.Y / 10),
  223. final.Z < 0 and math.max(final.Z, -half.Z + size.Z / 10) or math.min(final.Z, half.Z - size.Z / 10)
  224. )
  225. end
  226. end
  227.  
  228. --//Gets mouse location with offset accounted for
  229. function Aimbot:GetMouseViewportPoint()
  230. return GetMouseLocation(UserInputService) + self.Offset
  231. end
  232.  
  233. --//Gets best target from a list of parts and a viewport point, ignoreparent specifies whether to filter the entire parent
  234. function Aimbot:GetBestPartFromViewportPoint(position, parts, ignoreparent, ignore)
  235. local camera = self.Camera
  236.  
  237. if camera then
  238. local len = #parts
  239.  
  240. if len > 0 then
  241. local leastbias, leastwdist, leastpdist, part = math.huge, math.huge, math.huge, nil
  242. local campos = camera.CFrame.Position
  243.  
  244. ignore = ignore or {}
  245. local ipos = #ignore + 1
  246.  
  247. for i = 1, len do
  248. local cpart = parts[i]
  249. local cpos = cpart.Position
  250.  
  251. local point, onscreen = WorldToViewportPoint(camera, cpos)
  252. ignore[ipos] = ignoreparent and cpart.Parent or cpart
  253.  
  254. if onscreen and not self:GetBlockingPart(campos, cpos, ignore) then
  255. local pdist = (position - Vector2.new(point.X, point.Y)).Magnitude --//Pixel Distance
  256. local wdist = (campos - cpos).Magnitude --//World Distance
  257.  
  258. if pdist <= self:GetRadiusAtDistance(self.RadiusPercentAt1, wdist) then
  259. local bias = self:GetBiasAtDistance(wdist) + pdist
  260.  
  261. if bias < leastbias or (bias == leastbias and wdist < leastwdist) then
  262. leastbias = bias
  263. leastwdist = wdist
  264. leastpdist = pdist
  265. part = cpart
  266. end
  267. end
  268. end
  269. end
  270.  
  271. ignore[ipos] = nil
  272. return part, part and leastpdist <= self:GetRadiusAtDistance(self.SilentRadiusPercentAt1, leastwdist)
  273. end
  274. end
  275. end
  276.  
  277. --//Gets best player to target based on a viewport point
  278. function Aimbot:GetBestPlayerTargetFromViewportPoint(pos)
  279. if self.Camera then
  280. local plrs = GetPlayers(Players)
  281. local len = #plrs
  282.  
  283. if len > 0 then
  284. local parts = {}
  285. local lparts = 1
  286.  
  287. for i = 1, len do
  288. local plr = plrs[i]
  289. local charac = plr.Character
  290.  
  291. if plr ~= LocalPlayer and charac then
  292. if self.TeamCheck and not plr.Neutral and plr.Team == LocalPlayer.Team then
  293. continue
  294. end
  295.  
  296. if self.IsAliveCheck then
  297. local hum = FindFirstChildOfClass(charac, "Humanoid")
  298.  
  299. if not hum or hum.Health <= 0 then
  300. continue
  301. end
  302. end
  303.  
  304. local filtered = GetChildrenWhichIsA(charac, "BasePart")
  305. local lfiltered = #filtered
  306.  
  307. table.move(filtered, 1, lfiltered, lparts, parts)
  308. lparts = lparts + lfiltered
  309. end
  310. end
  311.  
  312. local target, silent = self:GetBestPartFromViewportPoint(pos, parts, true)
  313.  
  314. if target then
  315. return target, silent
  316. end
  317. end
  318. end
  319. end
  320.  
  321. --//Begins aimbot
  322. function Aimbot:Start()
  323. self.Enabled = true
  324.  
  325. local relative
  326. local holding = false
  327. local mspoof
  328.  
  329. local lastframe = getclock()
  330.  
  331. if not self.RenderStep then
  332. local lastt = 0
  333. local fdelt = 0.016666666666666666
  334.  
  335. self.RenderStep = Connect(RunService.RenderStepped, function(delta)
  336. local timee = tick()
  337. if self.Enabled and relative and timee > lastt + fdelt or (1 / delta < 60) then
  338. lastt = timee
  339. mousemoverel(relative.X, relative.Y)
  340. end
  341. end)
  342. end
  343.  
  344. if not self.Heartbeat then
  345. local lastt = 0
  346. local fdelt = 0.016666666666666666
  347.  
  348. self.Heartbeat = Connect(RunService.Heartbeat, function(delta)
  349. local timee = tick()
  350. relative = nil
  351.  
  352. if self.Enabled and timee > lastt + fdelt or (1 / delta < 60) then
  353. lastt = timee
  354. relative = nil
  355. local camera = self.Camera
  356.  
  357. if camera then
  358. local mpos = self:GetMouseViewportPoint()
  359. local target, silent = self:GetBestPlayerTargetFromViewportPoint(mpos)
  360.  
  361. if target then
  362. local charac = target.Parent
  363. local lcharac = LocalPlayer.Character
  364. local cignore = GetChildrenWhichIsNotA(charac, "BasePart")
  365.  
  366. table.insert(cignore, lcharac)
  367.  
  368. local mtarget = self:GetTargetFromViewportPoint(mpos, 5000, cignore)
  369.  
  370. if silent and self.TriggerBot and lcharac and IsDescendantOf(self:GetBlockingPart((FindFirstChild(lcharac, "Head") or FindFirstChild(lcharac, "HumanoidRootPart")).Position, target.Position, cignore), charac) then
  371. if not holding then
  372. holding = true
  373. mouse1press()
  374. end
  375. elseif holding then
  376. holding = false
  377. mouse1release()
  378. end
  379.  
  380. if mtarget and IsDescendantOf(mtarget, charac) then
  381. mspoof = nil
  382.  
  383. if not self.TargetPart then
  384. return
  385. end
  386. elseif silent then
  387. mspoof = self:GetClosestEdgeFromViewportPoint(mpos, target)
  388. else
  389. mspoof = nil
  390. end
  391.  
  392. target = (self.TargetPart and FindFirstChild(charac, self.TargetPart)) or target
  393. local pos, onscreen = WorldToViewportPoint(camera, target.Position)
  394.  
  395. if onscreen then
  396. relative = (Vector2.new(pos.X, pos.Y) - mpos) / Vector2.new(self.XSmoothingPercent * self.WidthFactor, self.YSmoothingPercent * self.WidthFactor)
  397. end
  398. else
  399. if holding then
  400. holding = false
  401. mouse1release()
  402. end
  403.  
  404. mspoof = nil
  405. end
  406. else
  407. if holding then
  408. holding = false
  409. mouse1release()
  410. end
  411.  
  412. mspoof = nil
  413. end
  414. else
  415. if holding then
  416. holding = false
  417. mouse1release()
  418. end
  419.  
  420. mspoof = nil
  421. end
  422. end)
  423. end
  424.  
  425. setreadonly(GameMeta, false)
  426.  
  427. local index
  428. index = replaceclosure(GameMeta.__index, function(self2, indice)
  429. if not checkcaller() and self.Enabled and self2 == Mouse and mspoof then
  430. local lc = string.lower(indice)
  431. local cam = self.Camera
  432.  
  433. if lc == "hit" then
  434. return CFrame.new(mspoof)
  435. elseif lc == "x" and cam then
  436. return WorldToScreenPoint(cam, mspoof).X
  437. elseif lc == "y" and cam then
  438. return WorldToScreenPoint(cam, mspoof).Y
  439. end
  440. end
  441.  
  442. return index(self2, indice)
  443. end)
  444.  
  445. setreadonly(GameMeta, true)
  446.  
  447. local getml
  448. getml = hookfunction(UserInputService.GetMouseLocation, newcclosure(function(self2)
  449. if not checkcaller() and self.Enabled and self2 == UserInputService and mspoof then
  450. local cam = self.Camera
  451.  
  452. if cam then
  453. local pos = WorldToViewportPoint(cam, mspoof)
  454. return Vector2.new(pos.X, pos.Y)
  455. end
  456. end
  457.  
  458. return getml(self2)
  459. end))
  460. end
  461.  
  462. --//Completely kills aimbot, as opposed to enabled = false
  463. function Aimbot:Kill()
  464. self.Enabled = false
  465.  
  466. if self.RenderStep then
  467. Disconnect(self.RenderStep)
  468. self.RenderStep = nil
  469. end
  470.  
  471. if self.Heartbeat then
  472. Disconnect(self.Heartbeat)
  473. self.Heartbeat = nil
  474. end
  475. end
  476.  
  477. --//Constructor
  478. function Aimbot.new(presets)
  479. presets = presets or {}
  480. UpdateTable(presets, Aimbot.DefaultSettings)
  481.  
  482. local WallCheckParams = RaycastParams.new()
  483. WallCheckParams.FilterType = Enum.RaycastFilterType.Blacklist
  484. WallCheckParams.IgnoreWater = presets.IgnoreWater
  485. WallCheckParams.FilterDescendantsInstances = presets.DefaultIgnore
  486.  
  487. presets.WallCheckParams = WallCheckParams
  488. return setmetatable(presets, Aimbot)
  489. end
  490.  
  491. --//Return with default settings
  492. return Aimbot
Advertisement
Add Comment
Please, Sign In to add comment