Advertisement
elzotes

kinewupdated

Oct 11th, 2021 (edited)
2,137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.23 KB | None | 0 0
  1. if getgenv().Aiming then return getgenv().Aiming end
  2.  
  3. -- // Services
  4. local Players = game:GetService("Players")
  5. local Workspace = game:GetService("Workspace")
  6. local GuiService = game:GetService("GuiService")
  7. local RunService = game:GetService("RunService")
  8.  
  9. -- // Vars
  10. local Heartbeat = RunService.Heartbeat
  11. local LocalPlayer = Players.LocalPlayer
  12. local CurrentCamera = Workspace.CurrentCamera
  13. local Mouse = LocalPlayer:GetMouse()
  14.  
  15. -- // Optimisation Vars (ugly)
  16. local Drawingnew = Drawing.new
  17. local Color3fromRGB = Color3.fromRGB
  18. local Vector2new = Vector2.new
  19. local GetGuiInset = GuiService.GetGuiInset
  20. local Randomnew = Random.new
  21. local mathfloor = math.floor
  22. local CharacterAdded = LocalPlayer.CharacterAdded
  23. local CharacterAddedWait = CharacterAdded.Wait
  24. local WorldToViewportPoint = CurrentCamera.WorldToViewportPoint
  25. local RaycastParamsnew = RaycastParams.new
  26. local EnumRaycastFilterTypeBlacklist = Enum.RaycastFilterType.Blacklist
  27. local Raycast = Workspace.Raycast
  28. local GetPlayers = Players.GetPlayers
  29. local Instancenew = Instance.new
  30. local IsDescendantOf = Instancenew("Part").IsDescendantOf
  31. local FindFirstChildWhichIsA = Instancenew("Part").FindFirstChildWhichIsA
  32. local FindFirstChild = Instancenew("Part").FindFirstChild
  33. local tableremove = table.remove
  34. local tableinsert = table.insert
  35.  
  36. -- // Silent Aim Vars
  37. getgenv().Aiming = {
  38.     Enabled = true,
  39.     ShowFOV = false,
  40.     FOVSides = 12,
  41.     FOVColour = Color3fromRGB(231, 84, 128),
  42.     VisibleCheck = true,
  43.     FOV = 21,
  44.     HitChance = 150,
  45.     Selected = LocalPlayer,
  46.     SelectedPart = nil,
  47.     TargetPart = {"UpperTorso", "UpperTorso"},
  48.     Ignored = {
  49.         Teams = {
  50.             {
  51.                 Team = LocalPlayer.Team,
  52.                 TeamColor = LocalPlayer.TeamColor,
  53.             },
  54.         },
  55.         Players = {
  56.             LocalPlayer,
  57.             606915557
  58.         }
  59.     }
  60. }
  61. local Aiming = getgenv().Aiming
  62.  
  63. -- // Show FOV
  64. local circle = Drawingnew("Circle")
  65. circle.Transparency = 1
  66. circle.Thickness = 2
  67. circle.Color = Aiming.FOVColour
  68. circle.Filled = false
  69. function Aiming.UpdateFOV()
  70.     if (circle) then
  71.         -- // Set Circle Properties
  72.         circle.Visible = Aiming.ShowFOV
  73.         circle.Radius = (Aiming.FOV * 3)
  74.         circle.Position = Vector2new(Mouse.X, Mouse.Y + GetGuiInset(GuiService).Y)
  75.         circle.NumSides = Aiming.FOVSides
  76.         circle.Color = Aiming.FOVColour
  77.  
  78.         -- // Return circle
  79.         return circle
  80.     end
  81. end
  82.  
  83. -- // Custom Functions
  84. local CalcChance = function(percentage)
  85.     percentage = mathfloor(percentage)
  86.     local chance = mathfloor(Randomnew().NextNumber(Randomnew(), 0, 1) * 150) / 150
  87.     return chance <= percentage / 150
  88. end
  89.  
  90. -- // Customisable Checking Functions: Is a part visible
  91. function Aiming.IsPartVisible(Part, PartDescendant)
  92.     -- // Vars
  93.     local Character = LocalPlayer.Character or CharacterAddedWait(CharacterAdded)
  94.     local Origin = CurrentCamera.CFrame.Position
  95.     local _, OnScreen = WorldToViewportPoint(CurrentCamera, Part.Position)
  96.  
  97.     -- // If Part is on the screen
  98.     if (OnScreen) then
  99.         -- // Vars: Calculating if is visible
  100.         local raycastParams = RaycastParamsnew()
  101.         raycastParams.FilterType = EnumRaycastFilterTypeBlacklist
  102.         raycastParams.FilterDescendantsInstances = {Character, CurrentCamera}
  103.  
  104.         local Result = Raycast(Workspace, Origin, Part.Position - Origin, raycastParams)
  105.         if (Result) then
  106.             local PartHit = Result.Instance
  107.             local Visible = (not PartHit or IsDescendantOf(PartHit, PartDescendant))
  108.  
  109.             -- // Return
  110.             return Visible
  111.         end
  112.     end
  113.  
  114.     -- // Return
  115.     return false
  116. end
  117.  
  118. -- // Ignore player
  119. function Aiming.IgnorePlayer(Player)
  120.     -- // Vars
  121.     local Ignored = Aiming.Ignored
  122.     local IgnoredPlayers = Ignored.Players
  123.  
  124.     -- // Find player in table
  125.     for i = 1, #IgnoredPlayers do
  126.         local IgnoredPlayer = IgnoredPlayers[i]
  127.  
  128.         if (IgnoredPlayer == Player) then
  129.             return false
  130.         end
  131.     end
  132.  
  133.     -- // Blacklist player
  134.     tableinsert(IgnoredPlayers, Player)
  135.     return true
  136. end
  137.  
  138. -- // Unignore Player
  139. function Aiming.UnIgnorePlayer(Player)
  140.     -- // Vars
  141.     local Ignored = Aiming.Ignored
  142.     local IgnoredPlayers = Ignored.Players
  143.  
  144.     -- // Find player in table
  145.     for i = 1, #IgnoredPlayers do
  146.         local IgnoredPlayer = IgnoredPlayers[i]
  147.  
  148.         if (IgnoredPlayer == Player) then
  149.             tableremove(IgnoredPlayers, i)
  150.             return true
  151.         end
  152.     end
  153.  
  154.     -- //
  155.     return false
  156. end
  157.  
  158. -- // Ignore team
  159. function Aiming.IgnoreTeam(Team, TeamColor)
  160.     -- // Vars
  161.     local Ignored = Aiming.Ignored
  162.     local IgnoredTeams = Ignored.Teams
  163.  
  164.     -- // Find team in table
  165.     for i = 1, #IgnoredTeams do
  166.         local IgnoredTeam = IgnoredTeams[i]
  167.  
  168.         if (IgnoredTeam.Team == Team and IgnoredTeam.TeamColor == TeamColor) then
  169.             return false
  170.         end
  171.     end
  172.  
  173.     -- // Ignore team
  174.     tableinsert(IgnoredTeams, {Team, TeamColor})
  175.     return true
  176. end
  177.  
  178. -- // Unignore team
  179. function Aiming.UnIgnoreTeam(Team, TeamColor)
  180.     -- // Vars
  181.     local Ignored = Aiming.Ignored
  182.     local IgnoredTeams = Ignored.Teams
  183.  
  184.     -- // Find team in table
  185.     for i = 1, #IgnoredTeams do
  186.         local IgnoredTeam = IgnoredTeams[i]
  187.  
  188.         if (IgnoredTeam.Team == Team and IgnoredTeam.TeamColor == TeamColor) then
  189.             -- // Remove
  190.             tableremove(IgnoredTeams, i)
  191.             return true
  192.         end
  193.     end
  194.  
  195.     -- // Return
  196.     return false
  197. end
  198.  
  199. -- //  Toggle team check
  200. function Aiming.TeamCheck(Toggle)
  201.     if (Toggle) then
  202.         return Aiming.IgnoreTeam(LocalPlayer.Team, LocalPlayer.TeamColor)
  203.     end
  204.  
  205.     return Aiming.UnIgnoreTeam(LocalPlayer.Team, LocalPlayer.TeamColor)
  206. end
  207.  
  208. -- // Check teams
  209. function Aiming.IsIgnoredTeam(Player)
  210.     -- // Vars
  211.     local Ignored = Aiming.Ignored
  212.     local IgnoredTeams = Ignored.Teams
  213.  
  214.     -- // Check if team is ignored
  215.     for i = 1, #IgnoredTeams do
  216.         local IgnoredTeam = IgnoredTeams[i]
  217.  
  218.         if (Player.Team == IgnoredTeam.Team and Player.TeamColor == IgnoredTeam.TeamColor) then
  219.             return true
  220.         end
  221.     end
  222.  
  223.     -- // Return
  224.     return false
  225. end
  226.  
  227. -- // Check if player (and team) is ignored
  228. function Aiming.IsIgnored(Player)
  229.     -- // Vars
  230.     local Ignored = Aiming.Ignored
  231.     local IgnoredPlayers = Ignored.Players
  232.  
  233.     -- // Loop
  234.     for i = 1, #IgnoredPlayers do
  235.         local IgnoredPlayer = IgnoredPlayers[i]
  236.  
  237.         -- // Check if Player Id
  238.         if (typeof(IgnoredPlayer) == "number") then
  239.             if (Player.UserId == IgnoredPlayer) then
  240.                 return true
  241.             end
  242.         end
  243.  
  244.         -- // Normal Player Instance
  245.         if (IgnoredPlayer == Player) then
  246.             return true
  247.         end
  248.     end
  249.  
  250.     -- // Team check
  251.     return Aiming.IsIgnoredTeam(Player)
  252. end
  253.  
  254. -- // Get the Direction, Normal and Material
  255. function Aiming.Raycast(Origin, Destination, UnitMultiplier)
  256.     if (typeof(Origin) == "Vector3" and typeof(Destination) == "Vector3") then
  257.         -- // Handling
  258.         if (not UnitMultiplier) then UnitMultiplier = 1 end
  259.  
  260.         -- // Vars
  261.         local Direction = (Destination - Origin).Unit * UnitMultiplier
  262.         local RaycastResult = Raycast(Workspace, Origin, Direction)
  263.  
  264.         if (RaycastResult ~= nil) then
  265.             local Normal = RaycastResult.Normal
  266.             local Material = RaycastResult.Material
  267.  
  268.             return Direction, Normal, Material
  269.         end
  270.     end
  271.  
  272.     -- // Return
  273.     return nil
  274. end
  275.  
  276. -- // Get Character
  277. function Aiming.Character(Player)
  278.     return Player.Character
  279. end
  280.  
  281. -- // Check Health
  282. function Aiming.CheckHealth(Player)
  283.     local Character = Aiming.Character(Player)
  284.     local Humanoid = FindFirstChildWhichIsA(Character, "Humanoid")
  285.  
  286.     local Health = (Humanoid and Humanoid.Health or 0)
  287.     return Health > 0
  288. end
  289.  
  290. -- // Check if silent aim can used
  291. function Aiming.Check()
  292.     return (Aiming.Enabled == true and Aiming.Selected ~= LocalPlayer and Aiming.SelectedPart ~= nil)
  293. end
  294. Aiming.checkSilentAim = Aiming.Check
  295.  
  296. -- // Get Closest Target Part
  297. function Aiming.GetClosestTargetPartToCursor(Character)
  298.     local TargetParts = Aiming.TargetPart
  299.  
  300.     -- // Vars
  301.     local ClosestPart = nil
  302.     local ClosestPartPosition = nil
  303.     local ClosestPartOnScreen = false
  304.     local ClosestPartMagnitudeFromMouse = nil
  305.     local ShortestDistance = 1/0
  306.  
  307.     -- //
  308.     local function CheckTargetPart(TargetPartName)
  309.         local TargetPart = FindFirstChild(Character, TargetPartName)
  310.  
  311.         if (TargetPart) then
  312.             local PartPos, onScreen = WorldToViewportPoint(CurrentCamera, TargetPart.Position)
  313.             local Magnitude = (Vector2new(PartPos.X, PartPos.Y) - Vector2new(Mouse.X, Mouse.Y)).Magnitude
  314.  
  315.             if (Magnitude < ShortestDistance) then
  316.                 ClosestPart = TargetPart
  317.                 ClosestPartPosition = PartPos
  318.                 ClosestPartOnScreen = onScreen
  319.                 ClosestPartMagnitudeFromMouse = Magnitude
  320.                 ShortestDistance = Magnitude
  321.             end
  322.         end
  323.     end
  324.  
  325.     -- // String check
  326.     if (typeof(TargetParts) == "string") then
  327.         -- // Check if it all
  328.         if (TargetParts == "All") then
  329.             -- // Loop through character children
  330.             for _, v in ipairs(Character:GetChildren()) do
  331.                 -- // See if it a part
  332.                 if not (v:IsA("BasePart")) then
  333.                     continue
  334.                 end
  335.  
  336.                 -- // Check it
  337.                 CheckTargetPart(v.Name)
  338.             end
  339.         else
  340.             -- // Individual
  341.             CheckTargetPart(TargetParts)
  342.         end
  343.     end
  344.  
  345.     -- // Loop through all target parts
  346.     if (typeof(TargetParts) == "table") then
  347.         for i = 1, #TargetParts do
  348.             local TargetPartName = TargetParts[i]
  349.             CheckTargetPart(TargetPartName)
  350.         end
  351.     end
  352.  
  353.     -- //
  354.     return ClosestPart, ClosestPartPosition, ClosestPartOnScreen, ClosestPartMagnitudeFromMouse
  355. end
  356.  
  357. -- // Silent Aim Function
  358. function Aiming.GetClosestPlayerToCursor()
  359.     -- // Vars
  360.     local TargetPart = nil
  361.     local ClosestPlayer = nil
  362.     local Chance = CalcChance(Aiming.HitChance)
  363.     local ShortestDistance = 1/0
  364.  
  365.     -- // Chance
  366.     if (not Chance) then
  367.         Aiming.Selected = LocalPlayer
  368.         Aiming.SelectedPart = nil
  369.  
  370.         return LocalPlayer
  371.     end
  372.  
  373.     -- // Loop through all players
  374.     local AllPlayers = GetPlayers(Players)
  375.     for i = 1, #AllPlayers do
  376.         local Player = AllPlayers[i]
  377.         local Character = Aiming.Character(Player)
  378.  
  379.         if (Aiming.IsIgnored(Player) == false and Character) then
  380.             local TargetPartTemp, _, _, Magnitude = Aiming.GetClosestTargetPartToCursor(Character)
  381.  
  382.             -- // Check if part exists and health
  383.             if (TargetPartTemp and Aiming.CheckHealth(Player)) then
  384.                 -- // Check if is in FOV
  385.                 if (circle.Radius > Magnitude and Magnitude < ShortestDistance) then
  386.                     -- // Check if Visible
  387.                     if (Aiming.VisibleCheck and not Aiming.IsPartVisible(TargetPartTemp, Character)) then continue end
  388.  
  389.                     -- // Set vars
  390.                     ClosestPlayer = Player
  391.                     ShortestDistance = Magnitude
  392.                     TargetPart = TargetPartTemp
  393.                 end
  394.             end
  395.         end
  396.     end
  397.  
  398.     -- // End
  399.     Aiming.Selected = ClosestPlayer
  400.     Aiming.SelectedPart = TargetPart
  401. end
  402.  
  403. -- // Heartbeat Function
  404. Heartbeat:Connect(function()
  405.     Aiming.UpdateFOV()
  406.     Aiming.GetClosestPlayerToCursor()
  407. end)
  408.  
  409. return Aiming
  410.  
  411. -- // Examples // --
  412.  
  413. --// Namecall Version // --
  414.  
  415. --[[
  416. -- // Load Aiming Module
  417. local Aiming = loadstring(game:HttpGet("https://raw.githubusercontent.com/Stefanuk12/ROBLOX/master/Universal/Aiming/Module.lua"))()
  418.  
  419. -- // Hook
  420. local __namecall
  421. __namecall = hookmetamethod(game, "__namecall", function(...)
  422.     -- // Vars
  423.     local args = {...}
  424.     local self = args[1]
  425.     local method = getnamecallmethod()
  426.  
  427.     -- // Checks
  428.     if (method == "FireServer") then
  429.         if (self.Name == "RemoteNameHere") then
  430.             -- change args
  431.  
  432.             -- // Return changed arguments
  433.             return __namecall(unpack(args))
  434.         end
  435.     end
  436.  
  437.     -- // Return
  438.     return __namecall(...)
  439. end)
  440. ]]--
  441.  
  442. -- // Index Version // --
  443.  
  444. --[[
  445. -- // Load Aiming Module
  446. local Aiming = loadstring(game:HttpGet("https://raw.githubusercontent.com/Stefanuk12/ROBLOX/master/Universal/Aiming/Module.lua"))()
  447.  
  448. -- // Hook
  449. local __index
  450. __index = hookmetamethod(game, "__index", function(t, k)
  451.     -- // Check if it trying to get our mouse's hit or target
  452.     if (t:IsA("Mouse") and (k == "Hit" or k == "Target")) then
  453.         -- // If we can use the silent aim
  454.         if (Aiming.Check()) then
  455.             -- // Vars
  456.             local TargetPart = Aiming.SelectedPart
  457.  
  458.             -- // Return modded val
  459.             return (k == "Hit" and TargetPart.CFrame or TargetPart)
  460.         end
  461.     end
  462.  
  463.     -- // Return
  464.     return __index(t, k)
  465. end)
  466. ]]--
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement