Advertisement
Aethielbx

Universal Silent Aim Script [ROBLOX]

Jun 29th, 2022 (edited)
77,415
4
Never
3
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.37 KB | None | 4 0
  1. -- init
  2. if not game:IsLoaded() then
  3. game.Loaded:Wait()
  4. end
  5.  
  6. if not syn or not protectgui then
  7. getgenv().protectgui = function() end
  8. end
  9.  
  10. local SilentAimSettings = {
  11. Enabled = false,
  12.  
  13. ClassName = "Universal Silent Aim - Aethiel",
  14. ToggleKey = "RightAlt",
  15.  
  16. TeamCheck = false,
  17. VisibleCheck = false,
  18. TargetPart = "HumanoidRootPart",
  19. SilentAimMethod = "Raycast",
  20.  
  21. FOVRadius = 130,
  22. FOVVisible = false,
  23. ShowSilentAimTarget = false,
  24.  
  25. MouseHitPrediction = false,
  26. MouseHitPredictionAmount = 0.165,
  27. HitChance = 100
  28. }
  29.  
  30. -- variables
  31. getgenv().SilentAimSettings = Settings
  32. local MainFileName = "UniversalSilentAim"
  33. local SelectedFile, FileToSave = "", ""
  34.  
  35. local Camera = workspace.CurrentCamera
  36. local Players = game:GetService("Players")
  37. local RunService = game:GetService("RunService")
  38. local GuiService = game:GetService("GuiService")
  39. local UserInputService = game:GetService("UserInputService")
  40. local HttpService = game:GetService("HttpService")
  41.  
  42. local LocalPlayer = Players.LocalPlayer
  43. local Mouse = LocalPlayer:GetMouse()
  44.  
  45. local GetChildren = game.GetChildren
  46. local GetPlayers = Players.GetPlayers
  47. local WorldToScreen = Camera.WorldToScreenPoint
  48. local WorldToViewportPoint = Camera.WorldToViewportPoint
  49. local GetPartsObscuringTarget = Camera.GetPartsObscuringTarget
  50. local FindFirstChild = game.FindFirstChild
  51. local RenderStepped = RunService.RenderStepped
  52. local GuiInset = GuiService.GetGuiInset
  53. local GetMouseLocation = UserInputService.GetMouseLocation
  54.  
  55. local resume = coroutine.resume
  56. local create = coroutine.create
  57.  
  58. local ValidTargetParts = {"Head", "HumanoidRootPart"}
  59. local PredictionAmount = 0.165
  60.  
  61. local mouse_box = Drawing.new("Square")
  62. mouse_box.Visible = true
  63. mouse_box.ZIndex = 999
  64. mouse_box.Color = Color3.fromRGB(54, 57, 241)
  65. mouse_box.Thickness = 20
  66. mouse_box.Size = Vector2.new(20, 20)
  67. mouse_box.Filled = true
  68.  
  69. local fov_circle = Drawing.new("Circle")
  70. fov_circle.Thickness = 1
  71. fov_circle.NumSides = 100
  72. fov_circle.Radius = 180
  73. fov_circle.Filled = false
  74. fov_circle.Visible = false
  75. fov_circle.ZIndex = 999
  76. fov_circle.Transparency = 1
  77. fov_circle.Color = Color3.fromRGB(54, 57, 241)
  78.  
  79. local ExpectedArguments = {
  80. FindPartOnRayWithIgnoreList = {
  81. ArgCountRequired = 3,
  82. Args = {
  83. "Instance", "Ray", "table", "boolean", "boolean"
  84. }
  85. },
  86. FindPartOnRayWithWhitelist = {
  87. ArgCountRequired = 3,
  88. Args = {
  89. "Instance", "Ray", "table", "boolean"
  90. }
  91. },
  92. FindPartOnRay = {
  93. ArgCountRequired = 2,
  94. Args = {
  95. "Instance", "Ray", "Instance", "boolean", "boolean"
  96. }
  97. },
  98. Raycast = {
  99. ArgCountRequired = 3,
  100. Args = {
  101. "Instance", "Vector3", "Vector3", "RaycastParams"
  102. }
  103. }
  104. }
  105.  
  106. function CalculateChance(Percentage)
  107. -- // Floor the percentage
  108. Percentage = math.floor(Percentage)
  109.  
  110. -- // Get the chance
  111. local chance = math.floor(Random.new().NextNumber(Random.new(), 0, 1) * 100) / 100
  112.  
  113. -- // Return
  114. return chance <= Percentage / 100
  115. end
  116.  
  117.  
  118. --[[file handling]] do
  119. if not isfolder(MainFileName) then
  120. makefolder(MainFileName);
  121. end
  122.  
  123. if not isfolder(string.format("%s/%s", MainFileName, tostring(game.PlaceId))) then
  124. makefolder(string.format("%s/%s", MainFileName, tostring(game.PlaceId)))
  125. end
  126. end
  127.  
  128. local Files = listfiles(string.format("%s/%s", "UniversalSilentAim", tostring(game.PlaceId)))
  129.  
  130. -- functions
  131. local function GetFiles() -- credits to the linoria lib for this function, listfiles returns the files full path and its annoying
  132. local out = {}
  133. for i = 1, #Files do
  134. local file = Files[i]
  135. if file:sub(-4) == '.lua' then
  136. -- i hate this but it has to be done ...
  137.  
  138. local pos = file:find('.lua', 1, true)
  139. local start = pos
  140.  
  141. local char = file:sub(pos, pos)
  142. while char ~= '/' and char ~= '\\' and char ~= '' do
  143. pos = pos - 1
  144. char = file:sub(pos, pos)
  145. end
  146.  
  147. if char == '/' or char == '\\' then
  148. table.insert(out, file:sub(pos + 1, start - 1))
  149. end
  150. end
  151. end
  152.  
  153. return out
  154. end
  155.  
  156. local function UpdateFile(FileName)
  157. assert(FileName or FileName == "string", "oopsies");
  158. writefile(string.format("%s/%s/%s.lua", MainFileName, tostring(game.PlaceId), FileName), HttpService:JSONEncode(SilentAimSettings))
  159. end
  160.  
  161. local function LoadFile(FileName)
  162. assert(FileName or FileName == "string", "oopsies");
  163.  
  164. local File = string.format("%s/%s/%s.lua", MainFileName, tostring(game.PlaceId), FileName)
  165. local ConfigData = HttpService:JSONDecode(readfile(File))
  166. for Index, Value in next, ConfigData do
  167. SilentAimSettings[Index] = Value
  168. end
  169. end
  170.  
  171. local function getPositionOnScreen(Vector)
  172. local Vec3, OnScreen = WorldToScreen(Camera, Vector)
  173. return Vector2.new(Vec3.X, Vec3.Y), OnScreen
  174. end
  175.  
  176. local function ValidateArguments(Args, RayMethod)
  177. local Matches = 0
  178. if #Args < RayMethod.ArgCountRequired then
  179. return false
  180. end
  181. for Pos, Argument in next, Args do
  182. if typeof(Argument) == RayMethod.Args[Pos] then
  183. Matches = Matches + 1
  184. end
  185. end
  186. return Matches >= RayMethod.ArgCountRequired
  187. end
  188.  
  189. local function getDirection(Origin, Position)
  190. return (Position - Origin).Unit * 1000
  191. end
  192.  
  193. local function getMousePosition()
  194. return GetMouseLocation(UserInputService)
  195. end
  196.  
  197. local function IsPlayerVisible(Player)
  198. local PlayerCharacter = Player.Character
  199. local LocalPlayerCharacter = LocalPlayer.Character
  200.  
  201. if not (PlayerCharacter or LocalPlayerCharacter) then return end
  202.  
  203. local PlayerRoot = FindFirstChild(PlayerCharacter, Options.TargetPart.Value) or FindFirstChild(PlayerCharacter, "HumanoidRootPart")
  204.  
  205. if not PlayerRoot then return end
  206.  
  207. local CastPoints, IgnoreList = {PlayerRoot.Position, LocalPlayerCharacter, PlayerCharacter}, {LocalPlayerCharacter, PlayerCharacter}
  208. local ObscuringObjects = #GetPartsObscuringTarget(Camera, CastPoints, IgnoreList)
  209.  
  210. return ((ObscuringObjects == 0 and true) or (ObscuringObjects > 0 and false))
  211. end
  212.  
  213. local function getClosestPlayer()
  214. if not Options.TargetPart.Value then return end
  215. local Closest
  216. local DistanceToMouse
  217. for _, Player in next, GetPlayers(Players) do
  218. if Player == LocalPlayer then continue end
  219. if Toggles.TeamCheck.Value and Player.Team == LocalPlayer.Team then continue end
  220.  
  221. local Character = Player.Character
  222. if not Character then continue end
  223.  
  224. if Toggles.VisibleCheck.Value and not IsPlayerVisible(Player) then continue end
  225.  
  226. local HumanoidRootPart = FindFirstChild(Character, "HumanoidRootPart")
  227. local Humanoid = FindFirstChild(Character, "Humanoid")
  228. if not HumanoidRootPart or not Humanoid or Humanoid and Humanoid.Health <= 0 then continue end
  229.  
  230. local ScreenPosition, OnScreen = getPositionOnScreen(HumanoidRootPart.Position)
  231. if not OnScreen then continue end
  232.  
  233. local Distance = (getMousePosition() - ScreenPosition).Magnitude
  234. if Distance <= (DistanceToMouse or Options.Radius.Value or 2000) then
  235. Closest = ((Options.TargetPart.Value == "Random" and Character[ValidTargetParts[math.random(1, #ValidTargetParts)]]) or Character[Options.TargetPart.Value])
  236. DistanceToMouse = Distance
  237. end
  238. end
  239. return Closest
  240. end
  241.  
  242. -- ui creating & handling
  243. local Library = loadstring(game:HttpGet("https://raw.githubusercontent.com/violin-suzutsuki/LinoriaLib/main/Library.lua"))()
  244.  
  245. local Window = Library:CreateWindow("Universal Silent Aim, by Averiias, xaxa, and Stefanuk12")
  246. local GeneralTab = Window:AddTab("General")
  247. local MainBOX = GeneralTab:AddLeftTabbox("Main") do
  248. local Main = MainBOX:AddTab("Main")
  249.  
  250. Main:AddToggle("aim_Enabled", {Text = "Enabled"}):AddKeyPicker("aim_Enabled_KeyPicker", {Default = "RightAlt", SyncToggleState = true, Mode = "Toggle", Text = "Enabled", NoUI = false});
  251. Options.aim_Enabled_KeyPicker:OnClick(function()
  252. SilentAimSettings.Enabled = not SilentAimSettings.Enabled
  253.  
  254. Toggles.aim_Enabled.Value = SilentAimSettings.Enabled
  255. Toggles.aim_Enabled:SetValue(SilentAimSettings.Enabled)
  256.  
  257. mouse_box.Visible = SilentAimSettings.Enabled
  258. end)
  259.  
  260. Main:AddToggle("TeamCheck", {Text = "Team Check", Default = SilentAimSettings.TeamCheck}):OnChanged(function()
  261. SilentAimSettings.TeamCheck = Toggles.TeamCheck.Value
  262. end)
  263. Main:AddToggle("VisibleCheck", {Text = "Visible Check", Default = SilentAimSettings.VisibleCheck}):OnChanged(function()
  264. SilentAimSettings.VisibleCheck = Toggles.VisibleCheck.Value
  265. end)
  266. Main:AddDropdown("TargetPart", {AllowNull = true, Text = "Target Part", Default = SilentAimSettings.TargetPart, Values = {"Head", "HumanoidRootPart", "Random"}}):OnChanged(function()
  267. SilentAimSettings.TargetPart = Options.TargetPart.Value
  268. end)
  269. Main:AddDropdown("Method", {AllowNull = true, Text = "Silent Aim Method", Default = SilentAimSettings.SilentAimMethod, Values = {
  270. "Raycast","FindPartOnRay",
  271. "FindPartOnRayWithWhitelist",
  272. "FindPartOnRayWithIgnoreList",
  273. "Mouse.Hit/Target"
  274. }}):OnChanged(function()
  275. SilentAimSettings.SilentAimMethod = Options.Method.Value
  276. end)
  277. Main:AddSlider('HitChance', {
  278. Text = 'Hit chance',
  279. Default = 100,
  280. Min = 0,
  281. Max = 100,
  282. Rounding = 1,
  283.  
  284. Compact = false,
  285. })
  286. Options.HitChance:OnChanged(function()
  287. SilentAimSettings.HitChance = Options.HitChance.Value
  288. end)
  289. end
  290.  
  291. local MiscellaneousBOX = GeneralTab:AddLeftTabbox("Miscellaneous")
  292. local FieldOfViewBOX = GeneralTab:AddLeftTabbox("Field Of View") do
  293. local Main = FieldOfViewBOX:AddTab("Visuals")
  294.  
  295. Main:AddToggle("Visible", {Text = "Show FOV Circle"}):AddColorPicker("Color", {Default = Color3.fromRGB(54, 57, 241)}):OnChanged(function()
  296. fov_circle.Visible = Toggles.Visible.Value
  297. SilentAimSettings.FOVVisible = Toggles.Visible.Value
  298. end)
  299. Main:AddSlider("Radius", {Text = "FOV Circle Radius", Min = 0, Max = 360, Default = 130, Rounding = 0}):OnChanged(function()
  300. fov_circle.Radius = Options.Radius.Value
  301. SilentAimSettings.FOVRadius = Options.Radius.Value
  302. end)
  303. Main:AddToggle("MousePosition", {Text = "Show Silent Aim Target"}):AddColorPicker("MouseVisualizeColor", {Default = Color3.fromRGB(54, 57, 241)}):OnChanged(function()
  304. mouse_box.Visible = Toggles.MousePosition.Value
  305. SilentAimSettings.ShowSilentAimTarget = Toggles.MousePosition.Value
  306. end)
  307. local PredictionTab = MiscellaneousBOX:AddTab("Prediction")
  308. PredictionTab:AddToggle("Prediction", {Text = "Mouse.Hit/Target Prediction"}):OnChanged(function()
  309. SilentAimSettings.MouseHitPrediction = Toggles.Prediction.Value
  310. end)
  311. PredictionTab:AddSlider("Amount", {Text = "Prediction Amount", Min = 0.165, Max = 1, Default = 0.165, Rounding = 3}):OnChanged(function()
  312. PredictionAmount = Options.Amount.Value
  313. SilentAimSettings.MouseHitPredictionAmount = Options.Amount.Value
  314. end)
  315. end
  316.  
  317. local CreateConfigurationBOX = GeneralTab:AddRightTabbox("Create Configuration") do
  318. local Main = CreateConfigurationBOX:AddTab("Create Configuration")
  319.  
  320. Main:AddInput("CreateConfigTextBox", {Default = "", Numeric = false, Finished = false, Text = "Create Configuration to Create", Tooltip = "Creates a configuration file containing settings you can save and load", Placeholder = "File Name here"}):OnChanged(function()
  321. if Options.CreateConfigTextBox.Value and string.len(Options.CreateConfigTextBox.Value) ~= "" then
  322. FileToSave = Options.CreateConfigTextBox.Value
  323. end
  324. end)
  325.  
  326. Main:AddButton("Create Configuration File", function()
  327. if FileToSave ~= "" or FileToSave ~= nil then
  328. UpdateFile(FileToSave)
  329. end
  330. end)
  331. end
  332.  
  333. local SaveConfigurationBOX = GeneralTab:AddRightTabbox("Save Configuration") do
  334. local Main = SaveConfigurationBOX:AddTab("Save Configuration")
  335. Main:AddDropdown("SaveConfigurationDropdown", {AllowNull = true, Values = GetFiles(), Text = "Choose Configuration to Save"})
  336. Main:AddButton("Save Configuration", function()
  337. if Options.SaveConfigurationDropdown.Value then
  338. UpdateFile(Options.SaveConfigurationDropdown.Value)
  339. end
  340. end)
  341. end
  342.  
  343. local LoadConfigurationBOX = GeneralTab:AddRightTabbox("Load Configuration") do
  344. local Main = LoadConfigurationBOX:AddTab("Load Configuration")
  345.  
  346. Main:AddDropdown("LoadConfigurationDropdown", {AllowNull = true, Values = GetFiles(), Text = "Choose Configuration to Load"})
  347. Main:AddButton("Load Configuration", function()
  348. if table.find(GetFiles(), Options.LoadConfigurationDropdown.Value) then
  349. LoadFile(Options.LoadConfigurationDropdown.Value)
  350.  
  351. Toggles.TeamCheck:SetValue(SilentAimSettings.TeamCheck)
  352. Toggles.VisibleCheck:SetValue(SilentAimSettings.VisibleCheck)
  353. Options.TargetPart:SetValue(SilentAimSettings.TargetPart)
  354. Options.Method:SetValue(SilentAimSettings.SilentAimMethod)
  355. Toggles.Visible:SetValue(SilentAimSettings.FOVVisible)
  356. Options.Radius:SetValue(SilentAimSettings.FOVRadius)
  357. Toggles.MousePosition:SetValue(SilentAimSettings.ShowSilentAimTarget)
  358. Toggles.Prediction:SetValue(SilentAimSettings.MouseHitPrediction)
  359. Options.Amount:SetValue(SilentAimSettings.MouseHitPredictionAmount)
  360. Options.HitChance:SetValue(SilentAimSettings.HitChance)
  361. end
  362. end)
  363. end
  364.  
  365. resume(create(function()
  366. RenderStepped:Connect(function()
  367. if Toggles.MousePosition.Value and Toggles.aim_Enabled.Value then
  368. if getClosestPlayer() then
  369. local Root = getClosestPlayer().Parent.PrimaryPart or getClosestPlayer()
  370. local RootToViewportPoint, IsOnScreen = WorldToViewportPoint(Camera, Root.Position);
  371. -- using PrimaryPart instead because if your Target Part is "Random" it will flicker the square between the Target's Head and HumanoidRootPart (its annoying)
  372.  
  373. mouse_box.Visible = IsOnScreen
  374. mouse_box.Position = Vector2.new(RootToViewportPoint.X, RootToViewportPoint.Y)
  375. else
  376. mouse_box.Visible = false
  377. mouse_box.Position = Vector2.new()
  378. end
  379. end
  380.  
  381. if Toggles.Visible.Value then
  382. fov_circle.Visible = Toggles.Visible.Value
  383. fov_circle.Color = Options.Color.Value
  384. fov_circle.Position = getMousePosition()
  385. end
  386. end)
  387. end))
  388.  
  389. -- hooks
  390. local oldNamecall
  391. oldNamecall = hookmetamethod(game, "__namecall", newcclosure(function(...)
  392. local Method = getnamecallmethod()
  393. local Arguments = {...}
  394. local self = Arguments[1]
  395. local chance = CalculateChance(SilentAimSettings.HitChance)
  396. if Toggles.aim_Enabled.Value and self == workspace and not checkcaller() and chance == true then
  397. if Method == "FindPartOnRayWithIgnoreList" and Options.Method.Value == Method then
  398. if ValidateArguments(Arguments, ExpectedArguments.FindPartOnRayWithIgnoreList) then
  399. local A_Ray = Arguments[2]
  400.  
  401. local HitPart = getClosestPlayer()
  402. if HitPart then
  403. local Origin = A_Ray.Origin
  404. local Direction = getDirection(Origin, HitPart.Position)
  405. Arguments[2] = Ray.new(Origin, Direction)
  406.  
  407. return oldNamecall(unpack(Arguments))
  408. end
  409. end
  410. elseif Method == "FindPartOnRayWithWhitelist" and Options.Method.Value == Method then
  411. if ValidateArguments(Arguments, ExpectedArguments.FindPartOnRayWithWhitelist) then
  412. local A_Ray = Arguments[2]
  413.  
  414. local HitPart = getClosestPlayer()
  415. if HitPart then
  416. local Origin = A_Ray.Origin
  417. local Direction = getDirection(Origin, HitPart.Position)
  418. Arguments[2] = Ray.new(Origin, Direction)
  419.  
  420. return oldNamecall(unpack(Arguments))
  421. end
  422. end
  423. elseif (Method == "FindPartOnRay" or Method == "findPartOnRay") and Options.Method.Value:lower() == Method:lower() then
  424. if ValidateArguments(Arguments, ExpectedArguments.FindPartOnRay) then
  425. local A_Ray = Arguments[2]
  426.  
  427. local HitPart = getClosestPlayer()
  428. if HitPart then
  429. local Origin = A_Ray.Origin
  430. local Direction = getDirection(Origin, HitPart.Position)
  431. Arguments[2] = Ray.new(Origin, Direction)
  432.  
  433. return oldNamecall(unpack(Arguments))
  434. end
  435. end
  436. elseif Method == "Raycast" and Options.Method.Value == Method then
  437. if ValidateArguments(Arguments, ExpectedArguments.Raycast) then
  438. local A_Origin = Arguments[2]
  439.  
  440. local HitPart = getClosestPlayer()
  441. if HitPart then
  442. Arguments[3] = getDirection(A_Origin, HitPart.Position)
  443.  
  444. return oldNamecall(unpack(Arguments))
  445. end
  446. end
  447. end
  448. end
  449. return oldNamecall(...)
  450. end))
  451.  
  452. local oldIndex = nil
  453. oldIndex = hookmetamethod(game, "__index", newcclosure(function(self, Index)
  454. if self == Mouse and not checkcaller() and Toggles.aim_Enabled.Value and Options.Method.Value == "Mouse.Hit/Target" and getClosestPlayer() then
  455. local HitPart = getClosestPlayer()
  456.  
  457. if Index == "Target" or Index == "target" then
  458. return HitPart
  459. elseif Index == "Hit" or Index == "hit" then
  460. return ((Toggles.Prediction.Value and (HitPart.CFrame + (HitPart.Velocity * PredictionAmount))) or (not Toggles.Prediction.Value and HitPart.CFrame))
  461. elseif Index == "X" or Index == "x" then
  462. return self.X
  463. elseif Index == "Y" or Index == "y" then
  464. return self.Y
  465. elseif Index == "UnitRay" then
  466. return Ray.new(self.Origin, (self.Hit - self.Origin).Unit)
  467. end
  468. end
  469.  
  470. return oldIndex(self, Index)
  471. end))
Advertisement
Comments
Add Comment
Please, Sign In to add comment
Advertisement