Advertisement
CriShoux

wild cursor firearms

Oct 6th, 2019
2,229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. local localPlayer = game:GetService("Players").LocalPlayer
  2. local currentCamera = game:GetService("Workspace").CurrentCamera
  3. local mouse = localPlayer:GetMouse()
  4.  
  5. function getClosestPlayerToCursor()
  6. local closestPlayer = nil
  7. local shortestDistance = math.huge
  8.  
  9. for i, v in pairs(game:GetService("Players"):GetPlayers()) do
  10. if v ~= localPlayer and v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Head") and v.Character.Head.HeadTag.Label.TextColor3 ~= Color3.fromRGB(0, 255, 0) then
  11. local pos = currentCamera:WorldToViewportPoint(v.Character.HumanoidRootPart.Position)
  12. local magnitude = (Vector2.new(pos.X, pos.Y) - Vector2.new(mouse.X, mouse.Y)).magnitude
  13.  
  14. if magnitude < shortestDistance then
  15. closestPlayer = v
  16. shortestDistance = magnitude
  17. end
  18. end
  19. end
  20.  
  21. return closestPlayer or localPlayer
  22. end
  23.  
  24. local mt = getrawmetatable(game)
  25. local oldNamecall = mt.__namecall
  26. if setreadonly then setreadonly(mt, false) else make_writeable(mt, true) end
  27. local namecallMethod = getnamecallmethod or get_namecall_method
  28. local newClose = newcclosure or function(f) return f end
  29.  
  30. mt.__namecall = newClose(function(...)
  31. local method = namecallMethod()
  32. local args = {...}
  33.  
  34. if tostring(method) == "FireServer" and tostring(args[1]) == "GunFired" then
  35. args[2]["HitPart"] = getClosestPlayerToCursor().Character.Head
  36. args[2]["HitPosition"] = getClosestPlayerToCursor().Character.Head.Position
  37.  
  38. return oldNamecall(unpack(args))
  39. end
  40.  
  41. return oldNamecall(...)
  42. end)
  43.  
  44. if setreadonly then setreadonly(mt, true) else make_writeable(mt, false) end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement