Advertisement
CriShoux

SA cursor

Oct 6th, 2019
1,975
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.95 KB | None | 0 0
  1. local localPlayer = game:GetService("Players").LocalPlayer
  2. local currentCamera = game:GetService("Workspace").CurrentCamera
  3. local mouse = localPlayer:GetMouse()
  4. local teamCheck = true
  5.  
  6. local function getClosestPlayerToCursor()
  7. local closestPlayer = nil
  8. local shortestDistance = math.huge
  9.  
  10. for i, v in pairs(game:GetService("Players"):GetPlayers()) do
  11. if v.Name ~= localPlayer.Name then
  12. if v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Head") and teamCheck and v.Team ~= localPlayer.Team then
  13. local pos = currentCamera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
  14. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
  15.  
  16. if magnitude < shortestDistance then
  17. closestPlayer = v
  18. shortestDistance = magnitude
  19. end
  20. elseif v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Head") and not teamCheck then
  21. local pos = currentCamera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
  22. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
  23.  
  24. if magnitude < shortestDistance then
  25. closestPlayer = v
  26. shortestDistance = magnitude
  27. end
  28. end
  29. end
  30. end
  31.  
  32. return closestPlayer
  33. end
  34.  
  35. game:GetService("UserInputService").InputBegan:Connect(function(input, onGui)
  36. if not onGui and input.KeyCode == Enum.KeyCode.T then
  37. teamCheck = not teamCheck
  38. end
  39. end)
  40.  
  41. local mt = getrawmetatable(game)
  42. local oldIndex = mt.__index
  43. local oldNamecall = mt.__namecall
  44. if setreadonly then setreadonly(mt, false) else make_writeable(mt, true) end
  45. local nameCallMethod = getnamecallmethod or get_namecall_method
  46. local newClose = newcclosure or function(f) return f end
  47.  
  48. mt.__index = newClose(function(t, k)
  49. if t == mouse and tostring(k) == "Hit" and getClosestPlayerToCursor() and getClosestPlayerToCursor().Character:FindFirstChild("Head") then
  50. return getClosestPlayerToCursor().Character.Head.CFrame
  51. end
  52.  
  53. return oldIndex(t, k)
  54. end)
  55.  
  56. mt.__namecall = newClose(function(...)
  57. local method = nameCallMethod()
  58. local args = {...}
  59.  
  60. if tostring(method) == "FindPartOnRayWithIgnoreList" and getClosestPlayerToCursor() and getClosestPlayerToCursor().Character then
  61. return oldNamecall(args[1], args[2], {game:GetService("Workspace").IgnoreThese, game:GetService("Players").LocalPlayer.Character, game:GetService("Workspace").BuildStuff, game:GetService("Workspace").Map})
  62. end
  63.  
  64. return oldNamecall(...)
  65. end)
  66.  
  67. if setreadonly then setreadonly(mt, true) else make_writeable(mt, false) end
  68.  
  69. local oldFunc
  70.  
  71. oldFunc = hookfunction(workspace.FindPartOnRayWithIgnoreList, function(...)
  72. local args = {...}
  73.  
  74. args[3] = {game:GetService("Workspace").IgnoreThese, game:GetService("Players").LocalPlayer.Character, game:GetService("Workspace").BuildStuff, game:GetService("Workspace").Map}
  75.  
  76. return oldFunc(unpack(args))
  77. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement