RandomMagics

Star Wars: Battleground Silent AIm

Jun 21st, 2022
2,123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. local players = game:GetService('Players')
  2. local input = game:GetService('UserInputService')
  3. local replicated = game:GetService("ReplicatedStorage")
  4. local localPlayer = players.LocalPlayer
  5. local camera = workspace.CurrentCamera
  6. local mouse = localPlayer:GetMouse()
  7.  
  8. local function nearestTarget(bone : string)
  9. local info = {
  10. distance = math.huge,
  11. player = nil,
  12. character = nil,
  13. bone = nil
  14. }
  15.  
  16. for _, player in next, players.GetPlayers(players) do
  17. if player == localPlayer then continue end
  18. local areFriendly = player.Team == localPlayer.Team
  19. local character = player.Character
  20.  
  21. local bone = character and character.FindFirstChild(character, bone)
  22. local humanoid = character and character.FindFirstChild(character, 'Humanoid')
  23. if areFriendly or not bone or not humanoid or humanoid.Health <= 0 then continue end
  24.  
  25. local screenPoint, onScreen = camera.WorldToScreenPoint(camera, bone.Position)
  26. if not onScreen then continue end
  27. local mousePosition = input.GetMouseLocation(input)
  28. local distance = (Vector2.new(screenPoint.x, screenPoint.y) - mousePosition).magnitude
  29. if distance > info.distance then continue end
  30.  
  31. info = {
  32. distance = distance,
  33. player = player,
  34. character = character,
  35. point = screenPoint,
  36. bone = bone
  37. }
  38.  
  39. end
  40.  
  41. return info
  42. end
  43.  
  44. local index
  45. index = hookmetamethod(game, '__index', function(self, key)
  46. if self == mouse and key == 'X' or key == 'Y' then
  47. local nearest = nearestTarget('Head')
  48. if nearest.point then
  49. return nearest.point[key]
  50. end
  51. end
  52. return index(self, key)
  53. end)
  54.  
  55. for i, v in next, replicated.Remote.Weapon:GetChildren() do
  56. v.Changed:Connect(function()
  57. v.Name = i
  58. end)
  59. end
  60.  
  61.  
  62. local namecall
  63. namecall = hookmetamethod(game, '__namecall', function(self, ...)
  64. local args = {...}
  65. local method = getnamecallmethod()
  66. local name = self.Name
  67.  
  68. if name == 'ReportDeployed' then
  69. return
  70. end
  71.  
  72. if name == 'Render' then
  73. --table.insert(args[3], workspace.Map)
  74. local nearest = nearestTarget('Head')
  75. if nearest.bone then
  76. replicated.Remote.Weapon['9']:FireServer(nearest.player, workspace.Camera.CFrame.p, nearest.bone.Position) -- dunno if its even doing anything but yeah
  77. end
  78. end
  79.  
  80. return namecall(self, table.unpack(args))
  81. end)
Advertisement
Add Comment
Please, Sign In to add comment