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 task = task
- local string = string
- local table = table
- local require = require
- 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 WaitForChild = game.WaitForChild
- local GetChildren = game.GetChildren
- local GetDescendants = game.GetDescendants
- 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 temphum = Instance.new("Humanoid")
- local tempconn = Connect(game.AncestryChanged, function() end)
- --//Other instance methods
- local WorldToViewportPoint = tempcam.WorldToViewportPoint
- local WorldToScreenPoint = tempcam.WorldToScreenPoint
- local GetPlayers = Players.GetPlayers
- local GetPlayerFromCharacter = Players.GetPlayerFromCharacter
- local GetMouseLocation = UserInputService.GetMouseLocation
- local ViewportPointToRay = tempcam.ViewportPointToRay
- local ScreenPointToRay = tempcam.ScreenPointToRay
- local GetGuiInset = GuiService.GetGuiInset
- local Disconnect = tempconn.Disconnect
- local MoveTo = temphum.MoveTo
- local Lerp2D = Vector2.new().Lerp
- --//Cleanup
- Destroy(temphum)
- Destroy(tempcam)
- Disconnect(tempconn)
- --//Local functions and constant variables
- Aimbot.DefaultSettings = {
- Tracking = {
- RadiusPercentAt1 = 145,
- RadiusCap = 300,
- XSmoothingPercent = 1,
- YSmoothingPercent = 1,
- };
- Flicking = {
- RadiusPercentAt1 = 145,
- RadiusCap = 300,
- XSmoothingPercent = 1,
- YSmoothingPercent = 1,
- };
- SilentAim = {
- RadiusPercentAt1 = 145,
- };
- Deadzone = {
- Enabled = false,
- XSmoothingPercent = .5,
- YSmoothingPercent = .5,
- };
- Checks = {
- Size = true,
- Invisible = true,
- Team = true,
- Wall = {
- TransparencyThreshold = .4, -- 0 would disable Wallcheck
- DefaultIgnore = {},
- };
- };
- Other = {
- DistanceBias = 1.4,
- Offset = Vector2.new(0, 0)
- }
- }
- Aimbot.Targets = setmetatable({}, {__index = function(a, b)
- a[b] = false; return false
- end})
- -- Main
- local LocalPlayer = Players.LocalPlayer
- local Mouse = LocalPlayer.GetMouse(LocalPlayer)
- 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 GetDescendantsWhichIsA(part, baseclass)
- local parts = GetDescendants(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
- function Aimbot:GetBiasAtDistance(distance)
- if self.Camera then
- return distance * self.Other.DistanceBias * self.WidthFactor
- end
- end
- function Aimbot:GetRadiusAtDistance(rpercent, distance)
- if self.Camera then
- if rpercent == self.Tracking.RadiusPercentAt1 and distance >= self.Tracking.RadiusCap then
- distance = self.Tracking.RadiusCap
- elseif rpercent == self.Flicking.RadiusPercentAt1 and distance >= self.Flicking.RadiusCap then
- distance = self.Flicking.RadiusCap
- end
- if rpercent ~= self.SilentAim.RadiusPercentAt1 and self.Visuals.FOV then
- self:DrawFOV(rpercent / distance * self.WidthFactor)
- end
- return rpercent / distance * self.WidthFactor
- end
- end
- function Aimbot:GetBlockingPart(origin, position, ignore)
- self.WallCheckParams.FilterDescendantsInstances = self.Checks.Wall.DefaultIgnore
- local direction = position - origin
- local thisignore = self.WallCheckParams.FilterDescendantsInstances
- if ignore then
- table.move(ignore, 1, #ignore, #thisignore + 1, thisignore)
- end
- while true do
- self.WallCheckParams.FilterDescendantsInstances = thisignore
- local result = Raycast(workspace, origin, direction, self.WallCheckParams)
- if result then
- if result.Instance.ClassName ~= "Terrain" and result.Instance.Transparency >= self.Checks.Wall.TransparencyThreshold then
- table.insert(thisignore, result.Instance)
- continue
- end
- self.WallCheckParams.FilterDescendantsInstances = self.Checks.Wall.DefaultIgnore
- return result.Instance, (result.Position - result.Instance.Position).Magnitude
- end
- self.WallCheckParams.FilterDescendantsInstances = self.Checks.Wall.DefaultIgnore
- return nil
- end
- end
- function Aimbot:GetTargetFromViewportPoint(point, distance, ignore)
- local camera, ray = self.Camera, nil
- if camera then
- local ray = ViewportPointToRay(camera, point.X, point.Y)
- return self:GetBlockingPart(ray.Origin, ray.Origin + ray.Direction * distance, ignore)
- end
- end
- function Aimbot:GetClosestEdgeFromViewportPoint(point, part)
- local camera = self.Camera
- if camera then
- local ray = ViewportPointToRay(camera, point.X, point.Y)
- local partposition = part.Position
- local distance = (ray.Origin - partposition).Magnitude
- local direction = (ray.Origin + ray.Direction * distance - partposition).Unit
- local size = part.Size
- local half = size / 2
- local final = direction * size
- return partposition + 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
- function Aimbot:GetMouseViewportPoint()
- return GetMouseLocation(UserInputService) + self.Other.Offset
- end
- function Aimbot:GetBestPartFromViewportPoint(position, parts, ignoreparent, ignore)
- local camera = self.Camera
- if camera then
- local length = #parts
- if length > 0 then
- local leastbias, leastworlddistance, leastpixeldistance, part = math.huge, math.huge, math.huge, nil
- local cameraposition = camera.CFrame.Position
- ignore = ignore or {}
- local ipos = #ignore + 1
- for i = 1, length 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(cameraposition, cpos, ignore) then
- local playerobject = GetPlayerFromCharacter(Players, cpart.Parent)
- local pixeldistance = (position - Vector2.new(point.X, point.Y)).Magnitude
- local worlddistance = (cameraposition - cpos).Magnitude
- if playerobject then
- local radius = self.Targets[playerobject] and self.Tracking.RadiusPercentAt1 or self.Flicking.RadiusPercentAt1
- if pixeldistance <= self:GetRadiusAtDistance(radius, worlddistance) then
- local bias = self:GetBiasAtDistance(worlddistance) + pixeldistance
- if bias < leastbias or (bias == leastbias and worlddistance < leastworlddistance) then
- leastbias = bias
- leastworlddistance = worlddistance
- leastpixeldistance = pixeldistance
- part = cpart
- end
- end
- end
- end
- end
- ignore[ipos] = nil
- return part, part and leastpixeldistance <= self:GetRadiusAtDistance(self.SilentAim.RadiusPercentAt1, leastworlddistance)
- end
- end
- end
- function Aimbot:GetBestPlayerTargetFromViewportPoint(pos)
- local camera = self.Camera
- if camera then
- local plrs = GetPlayers(Players)
- local length = #plrs
- if length > 0 then
- local maxPlr = {}
- local parts = {}
- local lparts = 1
- for i = 1, length do
- local plr = plrs[i]
- local charac = plr.Character
- if plr ~= LocalPlayer and charac then
- if self.Checks.Team and not plr.Neutral and plr.Team == LocalPlayer.Team then
- continue
- end
- if self.Checks.Invisible then
- local head = FindFirstChild(charac, "Head")
- if not head or head.Transparency >= 1 then
- continue
- end
- end
- if self.Checks.Size then
- local root = FindFirstChild(charac, "HumanoidRootPart")
- if not root or root.Size.X < 2 or root.Size.Y < 2 or root.Size.Z < 1 then
- continue
- end
- end
- local humanoid = FindFirstChildOfClass(charac, "Humanoid")
- if not humanoid or humanoid.Health <= 0 then
- continue
- 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, false) -- true
- local playerobject = target and GetPlayerFromCharacter(Players, target.Parent)
- for player, _ in pairs(self.Targets) do
- if player ~= playerobject then
- self.Targets[player] = false
- end
- end
- if target then
- return target, silent
- end
- end
- end
- end
- Aimbot.FOVDrawing = Drawing.new("Circle")
- Aimbot.TracerDrawing = Drawing.new("Line")
- function Aimbot:DrawFOV(radius)
- if not self.Visuals.FOV then self.FOVDrawing.Visible = false end
- self.FOVDrawing.Visible = true
- self.FOVDrawing.Thickness = 2
- self.FOVDrawing.NumSides = 12
- self.FOVDrawing.Radius = radius
- self.FOVDrawing.Filled = false
- self.FOVDrawing.Position = self:GetMouseViewportPoint()
- end
- function Aimbot:DrawTracer(rel)
- if self.Visuals.Tracer then
- if rel then
- self.TracerDrawing.Color = Color3.fromRGB(255, 0, 0)
- self.TracerDrawing.Thickness = 1
- self.TracerDrawing.From = self:GetMouseViewportPoint()
- self.TracerDrawing.To = rel
- self.TracerDrawing.Visible = true
- else
- self.TracerDrawing.Visible = false
- end
- else
- self.TracerDrawing.Visible = false
- end
- end
- function Aimbot:Start()
- self.Enabled = true
- local relative, fdelta, x = nil, 0.016666666666666666, nil
- if not self.RenderStep then
- local last = 0
- self.RenderStep = Connect(RunService.RenderStepped, function(delta)
- local ltime = tick()
- if ltime > last + fdelta or (1 / delta < 60) then
- last = ltime
- if self.Enabled and relative then
- Aimbot.FOVDrawing.Color = Color3.fromRGB(0, 255, 0)
- self:DrawTracer(Vector2.new(x.X, x.Y))
- mousemoverel(relative.X, relative.Y)
- else
- Aimbot.FOVDrawing.Color = Color3.fromRGB(255, 0, 0)
- self:DrawTracer()
- end
- end
- end)
- end
- if not self.Heartbeat then
- local last = 0
- self.Heartbeat = Connect(RunService.Heartbeat, function(delta)
- local ltime = tick()
- if ltime > last + fdelta or (1 / delta < 60) then
- last = ltime
- relative = nil
- 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 playerobject = GetPlayerFromCharacter(Players, charac)
- local cignore = GetChildrenWhichIsNotA(charac, "BasePart")
- local lcharac = LocalPlayer.Character
- table.insert(cignore, lcharac)
- local mtarget = self:GetTargetFromViewportPoint(mpos, 5000, {lcharac})
- if mtarget and IsDescendantOf(mtarget, charac) then
- self.mspoof = nil
- self.Targets[playerobject] = true
- else
- if silent then
- self.mspoof = self:GetClosestEdgeFromViewportPoint(mpos, target)
- else
- self.mspoof = nil
- end
- end
- if self.Targets[playerobject] then
- if self.Deadzone.Enabled then
- local pos, onscreen = WorldToViewportPoint(camera, target.Position)
- if onscreen then
- local g = (Vector2.new(pos.X, pos.Y) - mpos) / Vector2.new(self.Deadzone.XSmoothingPercent * self.WidthFactor, self.Deadzone.YSmoothingPercent * self.WidthFactor)
- mousemoverel(g.X, g.Y)
- end
- end
- end
- local pos, onscreen = WorldToViewportPoint(camera, target.Position)
- x = pos
- print(mtarget)
- if onscreen then
- if not (mtarget and IsDescendantOf(mtarget, charac)) then
- if self.Targets[playerobject] then
- local displ = (Vector2.new(pos.X, pos.Y) - mpos)
- local rel = Vector2.new(displ.X, displ.Y) / Vector2.new(self.Tracking.XSmoothingPercent * self.WidthFactor, self.Tracking.YSmoothingPercent * self.WidthFactor)
- local rX = (displ.X >= 1 and rel.X < 1) and 1 or rel.X
- local rY = (displ.Y >= 1 and rel.Y < 1) and 1 or rel.Y
- relative = Vector2.new(rX, rY)
- else
- local displ = (Vector2.new(pos.X, pos.Y) - mpos)
- local rel = Vector2.new(displ.X, displ.Y) / Vector2.new(self.Flicking.XSmoothingPercent * self.WidthFactor, self.Flicking.YSmoothingPercent * self.WidthFactor)
- local rX = (displ.X >= 1 and rel.X < 1) and 1 or rel.X
- local rY = (displ.Y >= 1 and rel.Y < 1) and 1 or rel.Y
- relative = Vector2.new(rX, rY)
- end
- end
- end
- end
- end
- end
- end
- end)
- end
- end
- function Aimbot.new(presets)
- presets = presets or {}
- UpdateTable(presets, Aimbot.DefaultSettings)
- local WallCheckParams = RaycastParams.new()
- WallCheckParams.FilterType = Enum.RaycastFilterType.Blacklist
- WallCheckParams.IgnoreWater = true
- WallCheckParams.FilterDescendantsInstances = presets.Checks.Wall.DefaultIgnore
- presets.WallCheckParams = WallCheckParams
- return setmetatable(presets, Aimbot)
- end
- return Aimbot
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement