Advertisement
uibhib775adadad7rf

Untitled

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