Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Aimbot = {}
- Aimbot.__index = Aimbot
- --//Localization
- local Instance = Instance
- local game = game
- local math = math
- local setmetatable = setmetatable
- local workspace = workspace
- local CFrame = CFrame
- local Vector3 = Vector3
- local Vector2 = Vector2
- local Random = Random
- local RaycastParams = RaycastParams
- local pairs = pairs
- local string = string
- local table = table
- local Enum = Enum
- local getrawmetatable = getrawmetatable
- local replaceclosure = replaceclosure
- local setreadonly = setreadonly
- local checkcaller = checkcaller
- local getclock = os.clock
- local mouse1press = mouse1press
- local mouse1release = mouse1release
- local mousemoverel = mousemoverel
- local hookfunction = hookfunction
- local newcclosure = newcclosure
- --//Instance methods
- local Raycast = workspace.Raycast
- local GetPropertyChangedSignal = game.GetPropertyChangedSignal
- local Connect = game.ChildAdded.Connect
- local Destroy = game.Destroy
- local GetService = game.GetService
- local FindFirstChildOfClass = game.FindFirstChildOfClass
- local FindFirstChild = game.FindFirstChild
- local GetChildren = game.GetChildren
- local IsA = game.IsA
- local IsDescendantOf = game.IsDescendantOf
- --//Services
- local Players = GetService(game, "Players")
- local UserInputService = GetService(game, "UserInputService")
- local RunService = GetService(game, "RunService")
- local GuiService = GetService(game, "GuiService")
- --//Temporary instances
- local tempcam = Instance.new("Camera")
- local tempconn = Connect(game.AncestryChanged, function() end)
- --//Other instance methods
- local WorldToViewportPoint = tempcam.WorldToViewportPoint
- local WorldToScreenPoint = tempcam.WorldToScreenPoint
- local GetPlayers = Players.GetPlayers
- local GetMouseLocation = UserInputService.GetMouseLocation
- local ViewportPointToRay = tempcam.ViewportPointToRay
- local Disconnect = tempconn.Disconnect
- local Lerp2D = Vector2.new().Lerp
- --//Cleanup
- Destroy(tempcam)
- Disconnect(tempconn)
- --//Local functions and constant variables
- Aimbot.DefaultSettings = {
- RadiusPercentAt1 = 130, --//Radius percent of screen width at 1 stud for aimbot
- XSmoothingPercent = .125,
- YSmoothingPercent = .15, --//Slows down mouse movement by a percentage of screen width
- DistanceBias = 1, --//Raises sensitivity of distance from camera when choosing target
- Offset = Vector2.new(0, 0), --//Mouse offset in pixels
- SilentRadiusPercentAt1 = 130, --//Radius percent of screen width at 1 stud for silent aim
- IgnoreTransparent = true, --//Whether to ignore transparent parts above the threshold or not in wallcheck
- IgnoreWater = false, --//Whether to ignore water in wallcheck
- TransparencyThreshold = .5, --//Threshold for what transparency or greater counts as ignorable
- DefaultIgnore = {}, --//List for what the aimbot should ignore during wallcheck
- IsAliveCheck = true, --//Ignore dead players
- TeamCheck = true,
- TriggerBot = true
- }
- local LocalPlayer = Players.LocalPlayer
- local Mouse = LocalPlayer.GetMouse(LocalPlayer)
- local GuiInset = GuiService.GetGuiInset(GuiService)
- local GameMeta = getrawmetatable(game)
- local function OnCameraChange()
- local cam = workspace.CurrentCamera
- Aimbot.Camera = cam
- Aimbot.ViewportSize = cam.ViewportSize
- Aimbot.WidthFactor = cam.ViewportSize.X / 100
- end
- local function UpdateTable(tab, update)
- for name, value in pairs(update) do
- if tab[name] == nil then
- tab[name] = value
- end
- end
- end
- local function GetChildrenWhichIsA(part, baseclass)
- local parts = GetChildren(part)
- local len = #parts
- local filtered = {}
- if len > 0 then
- for i = 1, len do
- local p = parts[i]
- if IsA(p, baseclass) then
- table.insert(filtered, p)
- end
- end
- end
- return filtered
- end
- local function GetChildrenWhichIsNotA(part, baseclass)
- local parts = GetChildren(part)
- local len = #parts
- local filtered = {}
- if len > 0 then
- for i = 1, len do
- local p = parts[i]
- if not IsA(p, baseclass) then
- table.insert(filtered, p)
- end
- end
- end
- return filtered
- end
- if workspace.CurrentCamera then
- OnCameraChange()
- end
- Connect(GetPropertyChangedSignal(workspace, "CurrentCamera"), OnCameraChange)
- --//Methods
- --//Gets bias value at a given distance
- function Aimbot:GetBiasAtDistance(distance)
- if self.Camera then
- return distance * self.DistanceBias * self.WidthFactor
- end
- end
- --//Gets circle radius at a given distance
- function Aimbot:GetRadiusAtDistance(rpercent, distance)
- if self.Camera then
- return rpercent / distance * self.WidthFactor
- end
- end
- --//Checks for parts obscuring camera, including terrain - unlike Camera:GetPartsObscuringTarget
- function Aimbot:GetBlockingPart(origin, position, ignore)
- self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore --//Incase it got updated
- local dir = position - origin
- local thisignore = self.WallCheckParams.FilterDescendantsInstances --//Copies table for you essentially
- if ignore then
- table.move(ignore, 1, #ignore, #thisignore + 1, thisignore)
- end
- while true do
- self.WallCheckParams.FilterDescendantsInstances = thisignore --//Copies
- local result = Raycast(workspace, origin, dir, self.WallCheckParams)
- if result then
- if self.IgnoreTransparent and result.Instance.ClassName ~= "Terrain" and result.Instance.Transparency >= self.TransparencyThreshold then
- table.insert(thisignore, result.Instance)
- continue
- end
- self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore
- return result.Instance
- end
- self.WallCheckParams.FilterDescendantsInstances = self.DefaultIgnore
- return nil
- end
- end
- --//Gets target from viewport point
- function Aimbot:GetTargetFromViewportPoint(point, distance, ignore)
- local camera = self.Camera
- if camera then
- local ray = ViewportPointToRay(camera, point.X, point.Y)
- return self:GetBlockingPart(ray.Origin, ray.Origin + ray.Direction * distance, ignore)
- end
- end
- --//Gets closest edge on part from viewport point
- function Aimbot:GetClosestEdgeFromViewportPoint(point, part)
- local camera = self.Camera
- if camera then
- local ray = ViewportPointToRay(camera, point.X, point.Y)
- local ppos = part.Position
- local dist = (ray.Origin - ppos).Magnitude
- local dir = (ray.Origin + ray.Direction * dist - ppos).Unit
- local size = part.Size
- local half = size / 2
- local final = dir * size
- return ppos + Vector3.new(
- final.X < 0 and math.max(final.X, -half.X + size.X / 10) or math.min(final.X, half.X - size.X / 10),
- final.Y < 0 and math.max(final.Y, -half.Y + size.Y / 10) or math.min(final.Y, half.Y - size.Y / 10),
- final.Z < 0 and math.max(final.Z, -half.Z + size.Z / 10) or math.min(final.Z, half.Z - size.Z / 10)
- )
- end
- end
- --//Gets mouse location with offset accounted for
- function Aimbot:GetMouseViewportPoint()
- return GetMouseLocation(UserInputService) + self.Offset
- end
- --//Gets best target from a list of parts and a viewport point, ignoreparent specifies whether to filter the entire parent
- function Aimbot:GetBestPartFromViewportPoint(position, parts, ignoreparent, ignore)
- local camera = self.Camera
- if camera then
- local len = #parts
- if len > 0 then
- local leastbias, leastwdist, leastpdist, part = math.huge, math.huge, math.huge, nil
- local campos = camera.CFrame.Position
- ignore = ignore or {}
- local ipos = #ignore + 1
- for i = 1, len do
- local cpart = parts[i]
- local cpos = cpart.Position
- local point, onscreen = WorldToViewportPoint(camera, cpos)
- ignore[ipos] = ignoreparent and cpart.Parent or cpart
- if onscreen and not self:GetBlockingPart(campos, cpos, ignore) then
- local pdist = (position - Vector2.new(point.X, point.Y)).Magnitude --//Pixel Distance
- local wdist = (campos - cpos).Magnitude --//World Distance
- if pdist <= self:GetRadiusAtDistance(self.RadiusPercentAt1, wdist) then
- local bias = self:GetBiasAtDistance(wdist) + pdist
- if bias < leastbias or (bias == leastbias and wdist < leastwdist) then
- leastbias = bias
- leastwdist = wdist
- leastpdist = pdist
- part = cpart
- end
- end
- end
- end
- ignore[ipos] = nil
- return part, part and leastpdist <= self:GetRadiusAtDistance(self.SilentRadiusPercentAt1, leastwdist)
- end
- end
- end
- --//Gets best player to target based on a viewport point
- function Aimbot:GetBestPlayerTargetFromViewportPoint(pos)
- if self.Camera then
- local plrs = GetPlayers(Players)
- local len = #plrs
- if len > 0 then
- local parts = {}
- local lparts = 1
- for i = 1, len do
- local plr = plrs[i]
- local charac = plr.Character
- if plr ~= LocalPlayer and charac then
- if self.TeamCheck and not plr.Neutral and plr.Team == LocalPlayer.Team then
- continue
- end
- if self.IsAliveCheck then
- local hum = FindFirstChildOfClass(charac, "Humanoid")
- if not hum or hum.Health <= 0 then
- continue
- end
- end
- if self.InvisibleCheck then
- local head = FindFirstChild(charac, "Head")
- if not head or head.Transparency >= 1 then
- continue
- end
- end
- local filtered = GetChildrenWhichIsA(charac, "BasePart")
- local lfiltered = #filtered
- table.move(filtered, 1, lfiltered, lparts, parts)
- lparts = lparts + lfiltered
- end
- end
- local target, silent = self:GetBestPartFromViewportPoint(pos, parts, true)
- if target then
- return target, silent
- end
- end
- end
- end
- --//Begins aimbot
- function Aimbot:Start()
- self.Enabled = true
- local relative
- local holding = false
- local mspoof
- local lastframe = getclock()
- if not self.RenderStep then
- self.RenderStep = Connect(RunService.RenderStepped, function()
- if self.Enabled and relative then
- mousemoverel(relative.X, relative.Y)
- end
- end)
- end
- if not self.Heartbeat then
- self.Heartbeat = Connect(RunService.Heartbeat, function()
- relative = nil
- local tim = getclock()
- local factor = (tim - lastframe) * 60
- lastframe = tim
- if self.Enabled then
- local camera = self.Camera
- if camera then
- local mpos = self:GetMouseViewportPoint()
- local target, silent = self:GetBestPlayerTargetFromViewportPoint(mpos)
- if target then
- local charac = target.Parent
- local lcharac = LocalPlayer.Character
- local cignore = GetChildrenWhichIsNotA(charac, "BasePart")
- table.insert(cignore, lcharac)
- local mtarget = self:GetTargetFromViewportPoint(mpos, 5000, cignore)
- if silent and self.TriggerBot and lcharac and IsDescendantOf(self:GetBlockingPart((FindFirstChild(lcharac, "Head") or FindFirstChild(lcharac, "HumanoidRootPart")).Position, target.Position, cignore), charac) then
- if not holding then
- holding = true
- mouse1press()
- end
- elseif holding then
- holding = false
- mouse1release()
- end
- if mtarget and IsDescendantOf(mtarget, charac) then
- mspoof = nil
- if not self.TargetPart then
- return
- end
- elseif silent then
- mspoof = self:GetClosestEdgeFromViewportPoint(mpos, target)
- else
- mspoof = nil
- end
- target = (self.TargetPart and FindFirstChild(charac, self.TargetPart)) or target
- local pos, onscreen = WorldToViewportPoint(camera, target.Position)
- if onscreen then
- relative = (Vector2.new(pos.X, pos.Y) - mpos) / Vector2.new(self.XSmoothingPercent * self.WidthFactor * factor, self.YSmoothingPercent * self.WidthFactor * factor)
- end
- else
- if holding then
- holding = false
- mouse1release()
- end
- mspoof = nil
- end
- else
- if holding then
- holding = false
- mouse1release()
- end
- mspoof = nil
- end
- else
- if holding then
- holding = false
- mouse1release()
- end
- mspoof = nil
- end
- end)
- end
- local old; old = hookmetamethod(game, "__index", function(i,v)
- if i == Mouse and v == "Hit" or v == "hit" and not checkcaller() and mspoof then
- return CFrame.new(mspoof);
- end
- return old(i,v);
- end)
- local getml
- getml = hookfunction(UserInputService.GetMouseLocation, newcclosure(function(self2)
- if not checkcaller() and self.Enabled and self2 == UserInputService and mspoof then
- local cam = self.Camera
- if cam then
- local pos = WorldToViewportPoint(cam, mspoof)
- return Vector2.new(pos.X, pos.Y)
- end
- end
- return getml(self2)
- end))
- end
- --//Completely kills aimbot, as opposed to enabled = false
- function Aimbot:Kill()
- self.Enabled = false
- if self.RenderStep then
- Disconnect(self.RenderStep)
- self.RenderStep = nil
- end
- if self.Heartbeat then
- Disconnect(self.Heartbeat)
- self.Heartbeat = nil
- end
- end
- --//Constructor
- function Aimbot.new(presets)
- presets = presets or {}
- UpdateTable(presets, Aimbot.DefaultSettings)
- local WallCheckParams = RaycastParams.new()
- WallCheckParams.FilterType = Enum.RaycastFilterType.Blacklist
- WallCheckParams.IgnoreWater = presets.IgnoreWater
- WallCheckParams.FilterDescendantsInstances = presets.DefaultIgnore
- presets.WallCheckParams = WallCheckParams
- return setmetatable(presets, Aimbot)
- end
- --//Return with default settings
- return Aimbot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement