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