Advertisement
M0nkePr0

silent aim

Jul 9th, 2022
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. local players = game:GetService("Players") --// players
  2. local local_player = players.LocalPlayer --// localplayer
  3. local mouse = local_player:GetMouse() --// mouse
  4. local user_input_service = game:GetService("UserInputService") --// userinputservice
  5. local current_camera = game:GetService("Workspace").CurrentCamera --// currentcamera
  6.  
  7. local global_module = require(game:GetService("ReplicatedStorage").SharedModules.Global) --// global module
  8.  
  9. local hitboxes = {"Head", "HumanoidRootPart", "LowerTorso", "UpperTorso"} --// hitboxes
  10.  
  11. local field_of_view = 150 --// field of view
  12.  
  13. --// our fov circle
  14. local circle = Drawing.new("Circle")
  15. circle.Visible = true
  16. circle.Radius = field_of_view
  17. circle.Filled = false
  18. circle.Thickness = 1
  19. circle.Color = Color3.new(1, 1, 1)
  20.  
  21. --// functions
  22. --@Param hitboxes Array ["Head", "Torso"]
  23. --// get closest entity to cursor
  24. local function closest_to_cursor(hitboxes)
  25. local target, part = nil, nil
  26. local max_distance, max_part_distance = math.huge, math.huge
  27. if not next(hitboxes) then
  28. return
  29. end
  30. for i, v in next, players:GetPlayers() do
  31. if v ~= local_player and v.Character and v.Character:FindFirstChild("HumanoidRootPart") then
  32. local position, on_screen = current_camera:WorldToScreenPoint(v.Character.HumanoidRootPart.Position)
  33. local distance = (Vector2.new(position.x, position.y) - Vector2.new(mouse.x, mouse.y)).Magnitude
  34. if distance < max_distance then
  35. target, max_distance = v, distance
  36. end
  37. end
  38. end
  39. if target then
  40. for i, v in next, target.Character:GetChildren() do
  41. if table.find(hitboxes, v.Name) then
  42. local world_to_screen, on_screen = current_camera:WorldToScreenPoint(v.Position)
  43. local distance = (Vector2.new(world_to_screen.x, world_to_screen.y) - Vector2.new(mouse.x, mouse.y)).magnitude
  44. if distance < max_part_distance and on_screen and distance < field_of_view then
  45. part, max_part_distance = v, distance
  46. end
  47. end
  48. end
  49. end
  50. return {target, part}
  51. end
  52. --// end of functions
  53.  
  54. do --// events
  55. do --// input changed
  56.  
  57. -- this is just to center the circle
  58. user_input_service.InputChanged:connect(function(input)
  59. if input.UserInputType == Enum.UserInputType.MouseMovement and circle.Position ~= Vector2.new(current_camera.ViewportSize.x / 2, current_camera.ViewportSize.y / 2) then
  60. circle.Position = Vector2.new(current_camera.ViewportSize.x / 2, current_camera.ViewportSize.y / 2)
  61. end
  62. end)
  63. end
  64. end
  65.  
  66. do --// silent aim
  67. local old = global_module.Utils.GetMouseHit
  68. global_module.Utils.GetMouseHit = function(...)
  69. if closest_to_cursor(hitboxes)[1] and closest_to_cursor(hitboxes)[2] then
  70. return closest_to_cursor(hitboxes)[2].Position
  71. else
  72. return old(...)
  73. end
  74. end
  75. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement