Advertisement
Guest User

aimlock and silent aim

a guest
Feb 12th, 2022
3,230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.63 KB | None | 0 0
  1. --[[
  2. This source is free to use and hopefully a good source for new script developers to learn how to make an aimlock or silent aim.
  3. * If this is used in any script, please credit me for it.
  4. * Please do not use this in a paid script.
  5.  
  6. Sorry for the really ugly code, I didn't think I would be releasing the source, lmao.
  7. --]]
  8.  
  9. -- *NOTE: If the script doesn't start, remove the code in line 70.
  10. -- Aka: repeat wait() until LP.Character:FindFirstChild("FULLY_LOADED_CHAR");
  11.  
  12.  
  13. --// Settings
  14.  
  15. local Settings = {
  16. Aimlock = {
  17. AimPart = "LowerTorso",
  18. AimlockKey = "Q",
  19. Prediction = 0.143,
  20.  
  21. FOVEnabled = false,
  22. FOVShow = false,
  23. FOVSize = 30,
  24.  
  25. Enabled = false
  26. },
  27. SilentAim = {
  28. Key = "C",
  29. AimAt = "LowerTorso",
  30. PredictionAmount = 0.139,
  31.  
  32. FOVEnabled = false,
  33. FOVShow = false,
  34. FOVSize = 0,
  35.  
  36. Enabled = false,
  37. KeyToLockOn = false
  38. },
  39. CFSpeed = {
  40. Speed = 2,
  41.  
  42. Enabled = false,
  43. Toggled = false,
  44.  
  45. Key = "Z"
  46. }
  47. }
  48.  
  49. --// Variables (Service)
  50.  
  51. local Players = game:GetService("Players")
  52. local RS = game:GetService("RunService")
  53. local WS = game:GetService("Workspace")
  54. local GS = game:GetService("GuiService")
  55. local SG = game:GetService("StarterGui")
  56. local UIS = game:GetService("UserInputService")
  57.  
  58. --// Variables (regular)
  59.  
  60. local LP = Players.LocalPlayer
  61. local Mouse = LP:GetMouse()
  62. local Camera = WS.CurrentCamera
  63. local GetGuiInset = GS.GetGuiInset
  64.  
  65. local AimlockState = false
  66. local aimLocked
  67. local lockVictim
  68.  
  69. --// Anti-Cheat
  70.  
  71. repeat wait() until LP.Character:FindFirstChild("FULLY_LOADED_CHAR");
  72.  
  73. for _,ac in pairs(LP.Character:GetChildren()) do
  74. if (ac:IsA("Script") and ac.Name ~= "Animate" and ac.Name ~= "Health") then
  75. ac:Destroy();
  76. end;
  77. end;
  78.  
  79. LP.Character.ChildAdded:Connect(function(child)
  80. if (child:IsA("Script") and child.Name ~= "Animate" and ac.Name ~= "Health") then
  81. child:Destroy();
  82. end;
  83. end);
  84.  
  85. --// CFrame Speed
  86.  
  87. local userInput = game:GetService('UserInputService')
  88. local runService = game:GetService('RunService')
  89.  
  90. Mouse.KeyDown:connect(function(Key)
  91. local cfKey = Settings.CFSpeed.Key:lower()
  92. if (Key == cfKey) then
  93. if (Settings.CFSpeed.Toggled) then
  94. Settings.CFSpeed.Enabled = not Settings.CFSpeed.Enabled
  95. if (Settings.CFSpeed.Enabled == true) then
  96. repeat
  97. game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame + game.Players.LocalPlayer.Character.Humanoid.MoveDirection * Settings.CFSpeed.Speed
  98. game:GetService("RunService").Stepped:wait()
  99. until Settings.CFSpeed.Enabled == false
  100. end
  101. end
  102. end
  103. end)
  104.  
  105. --// FOV Circle
  106.  
  107. local fov = Drawing.new("Circle")
  108. fov.Filled = false
  109. fov.Transparency = 1
  110. fov.Thickness = 1
  111. fov.Color = Color3.fromRGB(255, 255, 0)
  112.  
  113. --// Functions
  114.  
  115. function updateLock()
  116. if Settings.Aimlock.FOVEnabled == true and Settings.Aimlock.FOVShow == true then
  117. if fov then
  118. fov.Radius = Settings.Aimlock.FOVSize * 2
  119. fov.Visible = Settings.Aimlock.FOVShow
  120. fov.Position = Vector2.new(Mouse.X, Mouse.Y + GetGuiInset(GS).Y)
  121.  
  122. return fov
  123. end
  124. else
  125. Settings.Aimlock.FOVShow = false
  126. fov.Visible = false
  127. end
  128. end
  129.  
  130. function WTVP(arg)
  131. return Camera:WorldToViewportPoint(arg)
  132. end
  133.  
  134. function WTSP(arg)
  135. return Camera.WorldToScreenPoint(Camera, arg)
  136. end
  137.  
  138. function getClosest()
  139. local closestPlayer
  140. local shortestDistance = math.huge
  141.  
  142. for i, v in pairs(game.Players:GetPlayers()) do
  143. local notKO = v.Character:WaitForChild("BodyEffects")["K.O"].Value ~= true
  144. local notGrabbed = v.Character:FindFirstChild("GRABBING_COINSTRAINT") == nil
  145.  
  146. if v ~= game.Players.LocalPlayer and v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild(Settings.Aimlock.AimPart) and notKO and notGrabbed then
  147. local pos = Camera:WorldToViewportPoint(v.Character.PrimaryPart.Position)
  148. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(Mouse.X, Mouse.Y)).magnitude
  149.  
  150. if (Settings.Aimlock.FOVEnabled) then
  151. if (fov.Radius > magnitude and magnitude < shortestDistance) then
  152. closestPlayer = v
  153. shortestDistance = magnitude
  154. end
  155. else
  156. if (magnitude < shortestDistance) then
  157. closestPlayer = v
  158. shortestDistance = magnitude
  159. end
  160. end
  161. end
  162. end
  163. return closestPlayer
  164. end
  165.  
  166. function sendNotification(text)
  167. game.StarterGui:SetCore("SendNotification", {
  168. Title = "hakan.software",
  169. Text = text,
  170. Duration = 5
  171. })
  172. end
  173.  
  174. --// Checks if key is down
  175.  
  176. Mouse.KeyDown:Connect(function(k)
  177. local actualKey = Settings.Aimlock.AimlockKey:lower()
  178. if (k == actualKey) then
  179. if Settings.Aimlock.Enabled == true then
  180. aimLocked = not aimLocked
  181. if aimLocked then
  182. lockVictim = getClosest()
  183.  
  184. sendNotification("Locked onto: "..tostring(lockVictim.Character.Humanoid.DisplayName))
  185. else
  186. if lockVictim ~= nil then
  187. lockVictim = nil
  188.  
  189. sendNotification("Unlocked!")
  190. end
  191. end
  192. end
  193. end
  194. end)
  195.  
  196. --// Loop update FOV and loop camera lock onto target
  197.  
  198. local localPlayer = game:GetService("Players").LocalPlayer
  199. local currentCamera = game:GetService("Workspace").CurrentCamera
  200. local guiService = game:GetService("GuiService")
  201. local runService = game:GetService("RunService")
  202.  
  203. local getGuiInset = guiService.GetGuiInset
  204. local mouse = localPlayer:GetMouse()
  205.  
  206. local silentAimed = false
  207. local silentVictim
  208. local victimMan
  209.  
  210. local FOVCircle = Drawing.new("Circle")
  211. FOVCircle.Filled = false
  212. FOVCircle.Transparency = 1
  213. FOVCircle.Thickness = 2
  214. FOVCircle.Color = Color3.fromRGB(200, 255, 128)
  215. function updateFOV()
  216. if (FOVCircle) then
  217. if (Settings.SilentAim.FOVEnabled) then
  218. FOVCircle.Radius = Settings.SilentAim.FOVSize * 2
  219. FOVCircle.Visible = Settings.SilentAim.FOVShow
  220. FOVCircle.Position = Vector2.new(mouse.X, mouse.Y + getGuiInset(guiService).Y)
  221.  
  222. return FOVCircle
  223. elseif (not Settings.SilentAim.FOVEnabled) then
  224. FOVCircle.Visible = false
  225. end
  226. end
  227. end
  228.  
  229. function getClosestPlayerToCursor()
  230. local closestPlayer
  231. local shortestDistance = math.huge
  232.  
  233. for i, v in pairs(game.Players:GetPlayers()) do
  234. if v ~= game.Players.LocalPlayer and v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild(Settings.SilentAim.AimAt) then
  235. local pos = currentCamera:WorldToViewportPoint(v.Character.PrimaryPart.Position)
  236. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
  237.  
  238. if (Settings.SilentAim.FOVEnabled == true) then
  239. if (FOVCircle.Radius > magnitude and magnitude < shortestDistance) then
  240. closestPlayer = v
  241. shortestDistance = magnitude
  242. end
  243. else
  244. if (magnitude < shortestDistance) then
  245. closestPlayer = v
  246. shortestDistance = magnitude
  247. end
  248. end
  249. end
  250. end
  251. return closestPlayer
  252. end
  253.  
  254. Mouse.KeyDown:Connect(function(k)
  255. local actualKey = Settings.SilentAim.Key:lower()
  256. if (k == actualKey) then
  257. if (Settings.SilentAim.KeyToLockOn == false) then
  258. return
  259. end
  260. if (Settings.SilentAim.Enabled) then
  261. silentAimed = not silentAimed
  262.  
  263. if silentAimed then
  264. silentVictim = getClosestPlayerToCursor()
  265. sendNotification("Locked onto: " .. tostring(silentVictim.Character.Humanoid.DisplayName))
  266. elseif not silentAimed and silentVictim ~= nil then
  267. silentVictim = nil
  268.  
  269. sendNotification('Unlocked')
  270. end
  271. end
  272. end
  273. end)
  274.  
  275. runService.RenderStepped:Connect(function()
  276. updateFOV()
  277. updateLock()
  278. victimMan = getClosestPlayerToCursor()
  279. if Settings.Aimlock.Enabled == true then
  280. if lockVictim ~= nil then
  281. Camera.CFrame = CFrame.new(Camera.CFrame.p, lockVictim.Character[Settings.Aimlock.AimPart].Position + lockVictim.Character[Settings.Aimlock.AimPart].Velocity*Settings.Aimlock.Prediction)
  282. end
  283. end
  284. end)
  285.  
  286. local mt = getrawmetatable(game)
  287. local old = mt.__namecall
  288. setreadonly(mt, false)
  289. mt.__namecall = newcclosure(function(...)
  290. local args = {...}
  291.  
  292. if Settings.SilentAim.Enabled and Settings.SilentAim.KeyToLockOn and silentAimed and getnamecallmethod() == "FireServer" and args[2] == "UpdateMousePos" then
  293. args[3] = silentVictim.Character[Settings.SilentAim.AimAt].Position+(silentVictim.Character[Settings.SilentAim.AimAt].Velocity*Settings.SilentAim.PredictionAmount)
  294. return old(unpack(args))
  295. elseif Settings.SilentAim.Enabled and not Settings.SilentAim.KeyToLockOn and getnamecallmethod() == "FireServer" and args[2] == "UpdateMousePos" then
  296. args[3] = victimMan.Character[Settings.SilentAim.AimAt].Position+(victimMan.Character[Settings.SilentAim.AimAt].Velocity*Settings.SilentAim.PredictionAmount)
  297. return old(unpack(args))
  298. end
  299.  
  300. return old(...)
  301. end)
  302.  
  303. ----------------------------------------
  304. local lib = loadstring(game:HttpGet("https://pastebin.com/raw/mSwV3R8V"))()
  305. local main = lib:Init()
  306. ----------------------------------------
  307.  
  308. ----------------------------------------
  309. local Home = main:CreateTab("Home")
  310. local Config = main:CreateTab("Config", "rbxassetid://6793572208")
  311. local Misc = main:CreateTab("Misc", "rbxassetid://3192519002")
  312. ----------------------------------------
  313.  
  314. ----------------------------------------
  315. Home:CreateLabel("Welcome back!", false)
  316. ----------------------------------------
  317.  
  318. ----------------------------------------
  319. Config:CreateLabel("Config - Aimlock", true)
  320. Config:CreateToggle("Enabled", function(state)
  321. Settings.Aimlock.Enabled = state
  322. end)
  323. Config:CreateBox("Prediction", 0.143, function(arg)
  324. Settings.Aimlock.Prediction = tonumber(arg)
  325. end)
  326. Config:CreateDropdown("AimPart", {'Head', 'UpperTorso', 'HumanoidRootPart', 'LowerTorso'}, 'LowerTorso', function(arg)
  327. Settings.Aimlock.AimPart = tostring(arg)
  328. end)
  329. Config:CreateToggle("FOV", function(state)
  330. Settings.Aimlock.FOVEnabled = state
  331. end)
  332. Config:CreateToggle("Show FOV", function(state)
  333. Settings.Aimlock.FOVShow = state
  334. end)
  335. Config:CreateSlider("FOV Size", 30, 0, 400, 1, function(arg)
  336. Settings.Aimlock.FOVSize = tonumber(arg)
  337. end)
  338. Config:CreateBind("Keybind", Enum.KeyCode.Q, function(arg)
  339. Settings.Aimlock.AimlockKey = arg
  340. end)
  341. ----------------------------------------
  342.  
  343. ----------------------------------------
  344. Config:CreateLabel("Config - Silent", false)
  345. Config:CreateToggle("Enabled", function(state)
  346. Settings.SilentAim.Enabled = state
  347. end)
  348. Config:CreateToggle("Key to lock on", function(state)
  349. Settings.SilentAim.KeyToLockOn = state
  350. end)
  351. Config:CreateBox("Prediction", 0.143, function(arg)
  352. Settings.SilentAim.PredictionAmount = tonumber(arg)
  353. end)
  354. Config:CreateDropdown("AimPart", {'Head', 'UpperTorso', 'HumanoidRootPart', 'LowerTorso'}, 'LowerTorso', function(arg)
  355. Settings.SilentAim.AimAt = tostring(arg)
  356. end)
  357. Config:CreateToggle("FOV", function(state)
  358. Settings.SilentAim.FOVEnabled = state
  359. end)
  360. Config:CreateToggle("Show FOV", function(state)
  361. Settings.SilentAim.FOVShow = state
  362. end)
  363. Config:CreateSlider("FOV Size", 30, 0, 400, 1, function(arg)
  364. Settings.SilentAim.FOVSize = tonumber(arg)
  365. end)
  366. Config:CreateBind("Keybind", Enum.KeyCode.Q, function(arg)
  367. Settings.SilentAim.Key = arg
  368. end)
  369. ----------------------------------------
  370.  
  371. ----------------------------------------
  372. Misc:CreateLabel("Miscellaneous", false)
  373. Misc:CreateToggle("CFS State", function(state)
  374. Settings.CFSpeed.Toggled = state
  375. end)
  376. Misc:CreateSlider("CFrame Speed", 2, 0, 10, 0.1, function(arg)
  377. Settings.CFSpeed.Speed = tonumber(arg)
  378. end)
  379. Misc:CreateBind("CFS Key", Enum.KeyCode.Z, function(arg)
  380. Settings.CFSpeed.Key = arg
  381. end)
  382. ----------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement