Advertisement
Aethielbx

[New] Silent Aim for Roblox

Apr 16th, 2023
23,800
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.64 KB | None | 0 0
  1. --[[
  2. Information:
  3.  
  4. - Inspired by https://github.com/Averiias/Universal-SilentAim/blob/main/main.lua
  5.  
  6. You can combine methods. Simply seperate them with a comma. For example: "Target,UnitRay"
  7. -> Make sure you use the supported methods exactly (Capitalisation matters!)
  8. ]]
  9.  
  10. -- // Dependencies
  11. local Library, AimingTab, _ = loadstring(game:HttpGet("https://raw.githubusercontent.com/Stefanuk12/Aiming/main/GUI.lua"))()
  12. local Aiming = loadstring(game:HttpGet("https://raw.githubusercontent.com/Stefanuk12/Aiming/main/Load.lua"))()("Module")
  13. local AimingChecks = Aiming.Checks
  14. local AimingSelected = Aiming.Selected
  15. local AimingSettingsIgnored = Aiming.Settings.Ignored
  16. local AimingSettingsIgnoredPlayers = Aiming.Settings.Ignored.Players
  17. local AimingSettingsIgnoredWhitelistMode = AimingSettingsIgnored.WhitelistMode
  18.  
  19. -- // Services
  20. local UserInputService = game:GetService("UserInputService")
  21.  
  22. -- // Config
  23. local Configuration = {
  24. -- // The ones under this you may change - if you are a normal user
  25. Enabled = true,
  26. Method = "FindPartOnRay",
  27. FocusMode = false, -- // Stays locked on to that player only. If true then uses the silent aim keybind, if a input type is entered, then that is used
  28. ToggleBind = false, -- // true = Toggle, false = Hold (to enable)
  29. Keybind = Enum.UserInputType.MouseButton2, -- // You can also have Enum.KeyCode.E, etc.
  30.  
  31. -- // Do not change anything below here - if you are not a normal user
  32. CurrentlyFocused = nil,
  33.  
  34. MethodResolve = {
  35. -- // __namecall methods
  36. raycast = {
  37. Real = "Raycast",
  38. Metamethod = "__namecall",
  39. Aliases = {"raycast"}
  40. },
  41. findpartonray = {
  42. Real = "FindPartOnRay",
  43. Metamethod = "__namecall",
  44. Aliases = {"findPartOnRay"}
  45. },
  46. findpartonraywithwhitelist = {
  47. Real = "FindPartOnRayWithWhitelist",
  48. Metamethod = "__namecall",
  49. Aliases = {"findPartOnRayWithWhitelist"}
  50. },
  51. findpartonraywithignorelist = {
  52. Real = "FindPartOnRayWithIgnoreList",
  53. Metamethod = "__namecall",
  54. Aliases = {"findPartOnRayWithIgnoreList"}
  55. },
  56.  
  57. -- // __index methods
  58. target = {
  59. Real = "Target",
  60. Metamethod = "__index",
  61. Aliases = {"target"}
  62. },
  63. hit = {
  64. Real = "Hit",
  65. Metamethod = "__index",
  66. Aliases = {"hit"}
  67. },
  68. x = {
  69. Real = "X",
  70. Metamethod = "__index",
  71. Aliases = {"x"}
  72. },
  73. y = {
  74. Real = "Y",
  75. Metamethod = "__index",
  76. Aliases = {"y"}
  77. },
  78. unitray = {
  79. Real = "UnitRay",
  80. Metamethod = "__index",
  81. Aliases = {"unitray"}
  82. },
  83. },
  84.  
  85. ExpectedArguments = {
  86. FindPartOnRayWithIgnoreList = {
  87. ArgCountRequired = 3,
  88. Args = {
  89. "Instance", "Ray", "table", "boolean", "boolean"
  90. }
  91. },
  92. FindPartOnRayWithWhitelist = {
  93. ArgCountRequired = 3,
  94. Args = {
  95. "Instance", "Ray", "table", "boolean"
  96. }
  97. },
  98. FindPartOnRay = {
  99. ArgCountRequired = 2,
  100. Args = {
  101. "Instance", "Ray", "Instance", "boolean", "boolean"
  102. }
  103. },
  104. Raycast = {
  105. ArgCountRequired = 3,
  106. Args = {
  107. "Instance", "Vector3", "Vector3", "RaycastParams"
  108. }
  109. }
  110. }
  111. }
  112. local IsToggled = false
  113. Aiming.SilentAim = Configuration
  114.  
  115. -- // Functions
  116. local function CalculateDirection(Origin, Destination, Length)
  117. return (Destination - Origin).Unit * Length
  118. end
  119.  
  120. -- // Validate arguments passed through namecall
  121. local function ValidateArguments(Args, Method)
  122. --// Get Type Information from Method
  123. local TypeInformation = Configuration.ExpectedArguments[Method]
  124. if (not TypeInformation) then
  125. return false
  126. end
  127.  
  128. --// Make new table for successful matches
  129. local Matches = 0
  130.  
  131. -- // Go through every argument passed
  132. for ArgumentPosition, Argument in pairs(Args) do
  133. -- // Check if argument type is a certain type
  134. if (typeof(Argument) == TypeInformation.Args[ArgumentPosition]) then
  135. Matches = Matches + 1
  136. end
  137. end
  138.  
  139. -- // Get information
  140. local ExpectedValid = #Args
  141. local GotValid = Matches
  142.  
  143. -- // Return whether or not arguments are valid
  144. return ExpectedValid == GotValid
  145. end
  146.  
  147. -- // Additional checks you can add yourself, e.g. upvalue checks
  148. function Configuration.AdditionalCheck(metamethod, method, callingscript, ...)
  149. return true
  150. end
  151.  
  152. -- // Checks if a certain method is enabled
  153. local stringsplit = string.split
  154. local stringlower = string.lower
  155. local tablefind = table.find
  156. local function IsMethodEnabled(Method, Given, PossibleMethods)
  157. -- // Split it all up
  158. PossibleMethods = PossibleMethods or stringsplit(Configuration.Method, ",")
  159. Given = Given or Method
  160.  
  161. -- // Vars
  162. local LoweredMethod = stringlower(Method)
  163. local MethodData = Configuration.MethodResolve[LoweredMethod]
  164. if (not MethodData) then
  165. return false, nil
  166. end
  167.  
  168. -- //
  169. local Matches = LoweredMethod == stringlower(Given)
  170. local RealMethod = MethodData.Real
  171. local Found = tablefind(PossibleMethods, RealMethod)
  172.  
  173. -- // Return
  174. return (Matches and Found), RealMethod
  175. end
  176.  
  177. -- // Allows you to easily toggle multiple methods on and off
  178. function Configuration.ToggleMethod(Method, State)
  179. -- // Vars
  180. local EnabledMethods = Configuration.Method:split(",")
  181. local FoundI = table.find(EnabledMethods, Method)
  182.  
  183. -- //
  184. if (State) then
  185. if (not FoundI) then
  186. table.insert(EnabledMethods, Method)
  187. end
  188. else
  189. if (FoundI) then
  190. table.remove(EnabledMethods, FoundI)
  191. end
  192. end
  193.  
  194. -- // Set
  195. Configuration.Method = table.concat(EnabledMethods, ",")
  196. end
  197.  
  198. -- // Modify the position/cframe, add prediction yourself (use Aiming.Selected)
  199. function Configuration.ModifyCFrame(OnScreen)
  200. return OnScreen and AimingSelected.Position or AimingSelected.Part.CFrame
  201. end
  202.  
  203. -- // Focuses a player
  204. local Backup = {table.unpack(AimingSettingsIgnoredPlayers)}
  205. function Configuration.FocusPlayer(Player)
  206. table.insert(AimingSettingsIgnoredPlayers, Player)
  207. AimingSettingsIgnoredWhitelistMode.Players = true
  208. end
  209.  
  210. -- // Unfocuses a player
  211. function Configuration.Unfocus(Player)
  212. -- // Find it within ignored, and remove if found
  213. local PlayerI = table.find(AimingSettingsIgnoredPlayers, Player)
  214. if (PlayerI) then
  215. table.remove(AimingSettingsIgnoredPlayers, PlayerI)
  216. end
  217.  
  218. -- // Disable whitelist mode
  219. AimingSettingsIgnoredWhitelistMode.Players = false
  220. end
  221.  
  222. -- // Unfocuses everything
  223. function Configuration.UnfocusAll(Replacement)
  224. Replacement = Replacement or Backup
  225. AimingSettingsIgnored.Players = Replacement
  226. AimingSettingsIgnoredWhitelistMode.Players = false
  227. end
  228.  
  229. -- //
  230. function Configuration.FocusHandler()
  231. if (Configuration.CurrentlyFocused) then
  232. Configuration.Unfocus(Configuration.CurrentlyFocused)
  233. Configuration.CurrentlyFocused = nil
  234. return
  235. end
  236.  
  237. if (AimingChecks.IsAvailable()) then
  238. Configuration.FocusPlayer(AimingSelected.Instance)
  239. Configuration.CurrentlyFocused = AimingSelected.Instance
  240. end
  241. end
  242.  
  243. -- // For the toggle and stuff
  244. local function CheckInput(Input, Expected)
  245. local InputType = Expected.EnumType == Enum.KeyCode and "KeyCode" or "UserInputType"
  246. return Input[InputType] == Expected
  247. end
  248.  
  249. UserInputService.InputBegan:Connect(function(Input, GameProcessedEvent)
  250. -- // Make sure is not processed
  251. if (GameProcessedEvent) then
  252. return
  253. end
  254.  
  255. -- // Check if matches bind
  256. local FocusMode = Configuration.FocusMode
  257. if (CheckInput(Input, Configuration.Keybind)) then
  258. if (Configuration.ToggleBind) then
  259. IsToggled = not IsToggled
  260. else
  261. IsToggled = true
  262. end
  263.  
  264. if (FocusMode == true) then
  265. Configuration.FocusHandler()
  266. end
  267. end
  268.  
  269. -- // FocusMode check
  270. if (typeof(FocusMode) == "Enum" and CheckInput(Input, FocusMode)) then
  271. Configuration.FocusHandler()
  272. end
  273. end)
  274. UserInputService.InputEnded:Connect(function(Input, GameProcessedEvent)
  275. -- // Make sure is not processed
  276. if (GameProcessedEvent) then
  277. return
  278. end
  279.  
  280. -- // Check if matches bind
  281. if (CheckInput(Input, Configuration.Keybind) and not Configuration.ToggleBind) then
  282. IsToggled = false
  283. end
  284. end)
  285.  
  286. -- // Hooks
  287. local __index
  288. __index = hookmetamethod(game, "__index", function(t, k)
  289. -- // Vars
  290. local callingscript = getcallingscript()
  291.  
  292. -- // Make sure everything is in order
  293. if (t:IsA("Mouse") and not checkcaller() and IsToggled and Configuration.Enabled and AimingChecks.IsAvailable()) then
  294. -- // Vars
  295. local MethodEnabled, RealMethod = IsMethodEnabled(k)
  296.  
  297. -- // Make sure everything is in order 2
  298. if (not MethodEnabled or not Configuration.AdditionalCheck("__index", nil, callingscript, t, RealMethod)) then
  299. return __index(t, k)
  300. end
  301.  
  302. -- // Target
  303. if (RealMethod == "Target") then
  304. return AimingSelected.Part
  305. end
  306.  
  307. -- // Hit
  308. if (RealMethod == "Hit") then
  309. return Configuration.ModifyCFrame(false)
  310. end
  311.  
  312. -- // X/Y
  313. if (RealMethod == "X" or RealMethod == "Y") then
  314. return Configuration.ModifyCFrame(true)[k]
  315. end
  316.  
  317. -- // UnitRay
  318. if (RealMethod == "UnitRay") then
  319. local Origin = __index(t, k).Origin
  320. local Direction = CalculateDirection(Origin, Configuration.ModifyCFrame(false).Position)
  321. return Ray.new(Origin, Direction)
  322. end
  323. end
  324.  
  325. -- // Return
  326. return __index(t, k)
  327. end)
  328.  
  329. local __namecall
  330. __namecall = hookmetamethod(game, "__namecall", function(...)
  331. -- // Vars
  332. local args = {...}
  333. local self = args[1]
  334. local method = getnamecallmethod()
  335. local callingscript = getcallingscript()
  336.  
  337. -- // Make sure everything is in order
  338. if (self == workspace and not checkcaller() and IsToggled and Configuration.Enabled and AimingChecks.IsAvailable()) then
  339. -- // Vars
  340. local MethodEnabled, RealMethod = IsMethodEnabled(method)
  341.  
  342. -- // Make sure all is in order 2
  343. if (not MethodEnabled or not ValidateArguments(args, RealMethod) and Configuration.AdditionalCheck("__namecall", RealMethod, callingscript, ...)) then
  344. return __namecall(...)
  345. end
  346.  
  347. -- // Raycast
  348. if (RealMethod == "Raycast") then
  349. -- // Modify args
  350. args[3] = CalculateDirection(args[2], Configuration.ModifyCFrame(false).Position, 1000)
  351.  
  352. -- // Return
  353. return __namecall(unpack(args))
  354. end
  355.  
  356. -- // The rest pretty much, modify args
  357. local Origin = args[2].Origin
  358. local Direction = CalculateDirection(Origin, __index(AimingSelected.Part, "Position"), 1000)
  359. args[2] = Ray.new(Origin, Direction)
  360.  
  361. -- // Return
  362. return __namecall(unpack(args))
  363. end
  364.  
  365. -- //
  366. return __namecall(...)
  367. end)
  368.  
  369.  
  370. -- // GUI
  371. local SilentAimGroupBox = AimingTab:AddLeftTabbox("Silent Aim")
  372. local MainTab = SilentAimGroupBox:AddTab("Main")
  373. local MethodsTab = SilentAimGroupBox:AddTab("Methods")
  374.  
  375. MainTab:AddToggle("SilentAimEnabled", {
  376. Text = "Enabled",
  377. Default = Configuration.Enabled,
  378. Tooltip = "Toggle the Silent Aim on and off",
  379. Callback = function(Value)
  380. Configuration.Enabled = Value
  381. end
  382. }):AddKeyPicker("SilentAimEnabledKey", {
  383. Default = Configuration.Keybind,
  384. SyncToggleState = false,
  385. Mode = Configuration.ToggleBind and "Toggle" or "Hold",
  386. Text = "Silent Aim",
  387. NoUI = false,
  388. ChangedCallback = function(Key)
  389. Configuration.Keybind = Key
  390. end
  391. })
  392. MainTab:AddToggle("SilentAimEnabledToggle", {
  393. Text = "Toggle Mode",
  394. Default = Configuration.ToggleBind,
  395. Tooltip = "When disabled, it is hold to activate.",
  396. Callback = function(Value)
  397. Configuration.ToggleBind = Value
  398.  
  399. Options.SilentAimEnabledKey.Mode = Value and "Toggle" or "Hold"
  400. Options.SilentAimEnabledKey:Update()
  401. end
  402. })
  403.  
  404. MainTab:AddToggle("SilentAimFocusMode", {
  405. Text = "Focus Mode",
  406. Default = Configuration.Enabled,
  407. Tooltip = "Only targets the current targetted player",
  408. Callback = function(Value)
  409. Configuration.FocusMode = Value
  410. end
  411. }):AddKeyPicker("SilentAimFocusModeKey", {
  412. Default = Configuration.Keybind,
  413. SyncToggleState = false,
  414. Text = "Focus Mode",
  415. NoUI = false,
  416. ChangedCallback = function(Key)
  417. Configuration.FocusMode = Key
  418. end
  419. })
  420.  
  421. -- // Adding each method
  422. local Methods = {}
  423. for _, method in pairs(Configuration.MethodResolve) do
  424. table.insert(Methods, method.Real)
  425. end
  426.  
  427. -- //
  428. local function GetDictKeys(Dictionary)
  429. local Keys = {}
  430. for key, _ in pairs(Dictionary) do
  431. table.insert(Keys, key)
  432. end
  433. return Keys
  434. end
  435. MethodsTab:AddDropdown("SilentAimMethods", {
  436. Values = Methods,
  437. Default = Configuration.Method:split(","),
  438. Multi = true,
  439. Text = "Methods",
  440. Tooltip = "The possible silent aim methods to enable",
  441. Callback = function(Value)
  442. Configuration.Method = table.concat(GetDictKeys(Value), ",")
  443. end
  444. })
  445.  
  446. Library.KeybindFrame.Visible = true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement