Advertisement
eruaaaaaaa

fff

Apr 5th, 2022 (edited)
1,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.65 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.                     if self.InvisibleCheck then
  305.                         local head = FindFirstChild(charac, "Head")
  306.  
  307.                         if not head or head.Transparency >= 1 then
  308.                             continue
  309.                         end
  310.                     end
  311.  
  312.                     local filtered = GetChildrenWhichIsA(charac, "BasePart")
  313.                     local lfiltered = #filtered
  314.  
  315.                     table.move(filtered, 1, lfiltered, lparts, parts)
  316.                     lparts = lparts + lfiltered
  317.                 end
  318.             end
  319.  
  320.             local target, silent = self:GetBestPartFromViewportPoint(pos, parts, true)
  321.  
  322.             if target then
  323.                 return target, silent
  324.             end
  325.         end
  326.     end
  327. end
  328.  
  329. --//Begins aimbot
  330. function Aimbot:Start()
  331.     self.Enabled = true
  332.  
  333.     local relative
  334.     local holding = false
  335.     local mspoof
  336.    
  337.     local lastframe = getclock()
  338.  
  339.     if not self.RenderStep then
  340.         self.RenderStep = Connect(RunService.RenderStepped, function()
  341.             if self.Enabled and relative then
  342.                 mousemoverel(relative.X, relative.Y)
  343.             end
  344.         end)
  345.     end
  346.  
  347.     if not self.Heartbeat then
  348.         self.Heartbeat = Connect(RunService.Heartbeat, function()
  349.             relative = nil
  350.            
  351.             local tim = getclock()
  352.             local factor = (tim - lastframe) * 60
  353.            
  354.             lastframe = tim
  355.            
  356.             if self.Enabled then
  357.                 local camera = self.Camera
  358.  
  359.                 if camera then
  360.                     local mpos = self:GetMouseViewportPoint()
  361.                     local target, silent = self:GetBestPlayerTargetFromViewportPoint(mpos)
  362.                        
  363.                     if target then
  364.                         local charac = target.Parent
  365.                         local lcharac = LocalPlayer.Character
  366.                         local cignore = GetChildrenWhichIsNotA(charac, "BasePart")
  367.                        
  368.                         table.insert(cignore, lcharac)
  369.                        
  370.                         local mtarget = self:GetTargetFromViewportPoint(mpos, 5000, cignore)
  371.                         if silent and self.TriggerBot and lcharac and IsDescendantOf(self:GetBlockingPart((FindFirstChild(lcharac, "Head") or FindFirstChild(lcharac, "HumanoidRootPart")).Position, target.Position, cignore), charac) then
  372.                             if not holding then
  373.                                 holding = true
  374.                                 mouse1press()
  375.                             end
  376.                         elseif holding then
  377.                             holding = false
  378.                             mouse1release()
  379.                         end
  380.  
  381.                         if mtarget and IsDescendantOf(mtarget, charac) then
  382.                             mspoof = nil
  383.                            
  384.                             if not self.TargetPart then
  385.                                 return
  386.                             end
  387.                         elseif silent then
  388.                             mspoof = self:GetClosestEdgeFromViewportPoint(mpos, target)
  389.                         else
  390.                             mspoof = nil
  391.                         end
  392.                        
  393.                         target = (self.TargetPart and FindFirstChild(charac, self.TargetPart)) or target
  394.                         local pos, onscreen = WorldToViewportPoint(camera, target.Position)
  395.                        
  396.                         if onscreen then
  397.                             relative = (Vector2.new(pos.X, pos.Y) - mpos) / Vector2.new(self.XSmoothingPercent * self.WidthFactor * factor, self.YSmoothingPercent * self.WidthFactor * factor)
  398.                         end
  399.                     else
  400.                         if holding then
  401.                             holding = false
  402.                             mouse1release()
  403.                         end
  404.                        
  405.                         mspoof = nil
  406.                     end
  407.                 else
  408.                     if holding then
  409.                         holding = false
  410.                         mouse1release()
  411.                     end
  412.                        
  413.                     mspoof = nil
  414.                 end
  415.             else
  416.                 if holding then
  417.                     holding = false
  418.                     mouse1release()
  419.                 end
  420.                        
  421.                 mspoof = nil
  422.             end
  423.         end)
  424.     end
  425.    
  426.     local old; old = hookmetamethod(game, "__index", function(i,v)
  427.         if i == Mouse and v == "Hit" or v == "hit" and not checkcaller() and mspoof then
  428.             return CFrame.new(mspoof);
  429.         end
  430.         return old(i,v);
  431.     end)
  432.    
  433.     local getml
  434.     getml = hookfunction(UserInputService.GetMouseLocation, newcclosure(function(self2)
  435.         if not checkcaller() and self.Enabled and self2 == UserInputService and mspoof then
  436.             local cam = self.Camera
  437.            
  438.             if cam then
  439.                 local pos = WorldToViewportPoint(cam, mspoof)
  440.                 return Vector2.new(pos.X, pos.Y)
  441.             end
  442.         end
  443.        
  444.         return getml(self2)
  445.     end))
  446. end
  447.  
  448. --//Completely kills aimbot, as opposed to enabled = false
  449. function Aimbot:Kill()
  450.     self.Enabled = false
  451.  
  452.     if self.RenderStep then
  453.         Disconnect(self.RenderStep)
  454.         self.RenderStep = nil
  455.     end
  456.  
  457.     if self.Heartbeat then
  458.         Disconnect(self.Heartbeat)
  459.         self.Heartbeat = nil
  460.     end
  461. end
  462.  
  463. --//Constructor
  464. function Aimbot.new(presets)
  465.     presets = presets or {}
  466.     UpdateTable(presets, Aimbot.DefaultSettings)
  467.  
  468.     local WallCheckParams = RaycastParams.new()
  469.     WallCheckParams.FilterType = Enum.RaycastFilterType.Blacklist
  470.     WallCheckParams.IgnoreWater = presets.IgnoreWater
  471.     WallCheckParams.FilterDescendantsInstances = presets.DefaultIgnore
  472.  
  473.     presets.WallCheckParams = WallCheckParams
  474.     return setmetatable(presets, Aimbot)
  475. end
  476.  
  477. --//Return with default settings
  478. return Aimbot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement