MaxproGlitcher

Code Esp New version Dévollpement

Mar 16th, 2023
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.14 KB | None | 0 0
  1. --By MaxproGlitcher6199
  2.  
  3.  
  4. local Players = game:GetService("Players")
  5.  
  6. local ESP = {
  7. Enabled = true,
  8. Settings = {
  9. RemoveOnDeath = true,
  10. MaxDistance = 300, -- Max Distance for esp to render (IN METERS).
  11. MaxBoxSize = Vector3.new(15, 15, 0), -- Max size for ESP boxes.
  12. DestroyOnRemove = true, -- Whether the ESP objects should be deleted when the character is parented to nil, change this if you want.
  13. TeamColors = false, -- Whether or not the ESP color is based on team colors.
  14. TeamBased = false, -- Whether or not the ESP should render ESP on teammates.
  15. BoxTopOffset = Vector3.new(0, 1, 0), -- Offset for where the top of the box should be
  16.  
  17. Boxes = {
  18. Enabled = true,
  19. Color = Color3.new(1, 0, 1),
  20. Thickness = 1,
  21. },
  22. Names = {
  23. Distance = true,
  24. Health = true, -- Adds health values to the nametag.
  25. Enabled = true,
  26. Resize = true, -- Resizes the text based on the distance from the camera to the player so text doesn't get ridiculously large the further you are from the target.
  27. ResizeWeight = 0.05, -- How quickly names are resized based on the distance from the camera.
  28. Color = Color3.new(1, 1, 1),
  29. Size = 18,
  30. Font = 1,
  31. Center = true,
  32. Outline = true,
  33. },
  34. Tracers = {
  35. Enabled = true,
  36. Thickness = 0,
  37. Color = Color3.new(1, 0, 1),
  38. }
  39. },
  40. Objects = {} -- Table of ESP objects that you can read and do fun stuff with, however, editing settings changes the settings for every object at the same time so this is only needed if you want to set settings for individual targets.
  41. }
  42.  
  43.  
  44.  
  45.  
  46.  
  47. -- Initial functions for the lib that are used in functions like GetQuad, DrawQuad, Etc.
  48.  
  49. local function Draw(Type, Properties) -- Manually writing every property and Drawing.new() is extremely painful, making it a table is bazed. I definitely didn't steal this idea from ic3w0lf.
  50. local Object = Drawing.new(Type)
  51.  
  52. for Property, Value in next, Properties or {} do -- Prevents errors
  53. Object[Property] = Value
  54. end
  55.  
  56. return Object
  57. end
  58.  
  59. function ESP:GetScreenPosition(Position) -- Gets the screen position of a vector3 / cframe.
  60. local Position = typeof(Position) ~= "CFrame" and Position or Position.Position -- I'm probably going to forget to use .Position like a proper dumbfuck.
  61. local ScreenPos, IsOnScreen = workspace.CurrentCamera:WorldToViewportPoint(Position)
  62.  
  63. return Vector2.new(ScreenPos.X, ScreenPos.Y), IsOnScreen -- fuck the depth value i dont want it :<
  64. end
  65.  
  66. function ESP:GetDistance(Position) -- Gets the distance (IN METERS) from the camera position to a target position.
  67. local Magnitude = (workspace.CurrentCamera.CFrame.Position - Position).Magnitude
  68. local Metric = Magnitude * 0.28 -- Converts studs to meters
  69.  
  70. return math.round(Metric)
  71. end
  72.  
  73. function ESP:GetHealth(Model) -- Tries to find a humanoid and grab its health, this needs to be overwritten in games that have custom health paths.
  74. local Humanoid = Model:FindFirstChildOfClass("Humanoid")
  75.  
  76. if Humanoid then
  77. return Humanoid.Health, Humanoid.MaxHealth, (Humanoid.Health / Humanoid.MaxHealth) * 100
  78. end
  79.  
  80. return 100, 100, 100
  81. end
  82.  
  83. function ESP:GetPlayerFromCharacter(Model) -- Tries to get a player from their character, if the character doesn't have a player linked to it (thanks custom character games like bad business), it returns nil.
  84. return Players:GetPlayerFromCharacter(Model)
  85. end
  86.  
  87. function ESP:GetTeam(Model) -- Tries to get a player's team from their character model, if there is no player linked, this returns nil.
  88. local Player = ESP:GetPlayerFromCharacter(Model)
  89.  
  90. return Player and Player.Team or nil
  91. end
  92.  
  93. function ESP:GetPlayerTeam(Player) -- Tries to get a player's team, this won't work in games that have custom modules to get player teams and needs to be overwritten.
  94. return Player and Player.Team
  95. end
  96.  
  97. function ESP:IsHostile(Model) -- Tries to check if a player is hostile based on their team, this, again, won't work with custom characters.
  98. local Player = ESP:GetPlayerFromCharacter(Model)
  99. local MyTeam, TheirTeam = ESP:GetPlayerTeam(Players.LocalPlayer), ESP:GetPlayerTeam(Player)
  100.  
  101. return (MyTeam ~= TheirTeam)
  102. end
  103.  
  104. function ESP:GetTeamColor(Model) -- Tries to get a player's teamcolor from their character model or from their player directly.
  105. local Team = Model:IsA("Model") and ESP:GetTeam(Model) or Model:IsA("Player") and ESP:GetPlayerTeam(Model)
  106.  
  107. return Team and Team.TeamColor.Color or Color3.new(1, 0, 0)
  108. end
  109.  
  110. function ESP:GetOffset(Model)
  111. local Humanoid = Model:FindFirstChild("Humanoid")
  112.  
  113. if Humanoid and Humanoid.RigType == Enum.HumanoidRigType.R6 then
  114. return CFrame.new(0, -1.75, 0)
  115. end
  116.  
  117. return CFrame.new(0, 0, 0)
  118. end
  119.  
  120. function ESP:CharacterAdded(Player) -- Some games have custom characteradded signals, edit this if you want to change it for compatibility.
  121. return Player.CharacterAdded
  122. end
  123.  
  124. function ESP:GetCharacter(Player) -- Some games have custom characters and leave player.Character nil, edit this if you need it.
  125. return Player.Character
  126. end
  127.  
  128. local function Validate(Child, Type, ClassName, ExpectedName)
  129. return not (Type or ClassName or ExpectedName) or (not ExpectedName or (ExpectedName and Child.Name == ExpectedName)) and (not ClassName or (ClassName and Child.ClassName == ClassName)) and (not Type or (Type and Child:IsA(Type))) -- I hate my life.
  130. end
  131.  
  132. function ESP:AddListener(Model, Validator, Settings)
  133. local Descendants = Settings.Descendants
  134. local Type, ClassName, ExpectedName = Settings.Type, Settings.ClassName, Settings.ExpectedName
  135. local ExtraSettings = Settings.Custom or {}
  136.  
  137. local function ValidCheck(Child)
  138. if typeof(Validator) == "function" and Validator(Child) or not Validator then
  139. if Validate(Child, Type, ClassName, ExpectedName) then
  140. ESP.Object:New(Child, ExtraSettings)
  141. end
  142. end
  143. end
  144.  
  145. local Connection = Descendants and Model.DescendantAdded or Model.ChildAdded
  146. local ObjectsToCheck = Descendants and Model.GetDescendants or Model.GetChildren
  147.  
  148. Connection:Connect(function(Child)
  149. task.spawn(ValidCheck, Child)
  150. end)
  151.  
  152. for i, Child in next, ObjectsToCheck(Model) do
  153. task.spawn(ValidCheck, Child)
  154. end
  155. end
  156.  
  157.  
  158. -- Actual drawing functions for making boxes and stuff weee.
  159.  
  160. local Object = {}
  161. Object.__index = Object
  162.  
  163. ESP.Object = Object
  164.  
  165. local function Clone(Table) -- es not mine i stole it from roblox docs
  166. local Ret = {}
  167.  
  168. for i,v in next, Table do
  169. if typeof(v) == "table" then
  170. v = Clone(v)
  171. end
  172.  
  173. Ret[i] = v
  174. end
  175.  
  176. return Ret
  177. end
  178.  
  179. local function GetValue(Local, Global, Name) -- Blame the bird. Easy way to check if a setting is enabled on either the object settings or global settings.
  180. local GlobalVal = Global[Name]
  181. local LocalVal = Local[Name]
  182.  
  183. return LocalVal or ((LocalVal == nil or typeof(LocalVal) ~= "boolean") and GlobalVal)
  184. end
  185.  
  186. function Object:New(Model, ExtraInfo) -- Object:New(Target, {Name = "Custom Name", Settings = {Box = {Color = Color3.new(0, 1, 0)}}})
  187. if not Model then
  188. return
  189. end
  190.  
  191. local Settings = ESP.Settings
  192.  
  193. local NewObject = {
  194. Connections = {},
  195. RenderSettings = {
  196. Boxes = {},
  197. Tracers = {},
  198. Names = {},
  199. },
  200. GlobalSettings = Settings,
  201. Model = Model,
  202. Name = Model.Name,
  203.  
  204. Objects = {
  205. Box = {
  206. Color = Settings.Boxes.Color,
  207. Thickness = Settings.Boxes.Thickness,
  208. },
  209.  
  210. Name = {
  211. Color = Settings.Names.Color,
  212. Outline = Settings.Names.Outline,
  213. Text = Model.Name,
  214. Size = Settings.Names.Size,
  215. Font = Settings.Names.Font,
  216. Center = Settings.Names.Center,
  217. },
  218.  
  219. Tracer = {
  220. Thickness = Settings.Tracers.Thickness,
  221. Color = Settings.Tracers.Color,
  222. }
  223. },
  224. }
  225.  
  226. for Property, Value in next, ExtraInfo or {} do -- Honestly, I did this at 2am and I can't remember why I did it, probably because I had to filter variables so the stupid drawing objects wouldn't get ESP settings tangled up in the variabled like Enabled, causing an error.
  227.  
  228. if Property ~= "Settings" then
  229. NewObject[Property] = Value
  230. else
  231. for Name, Table in next, Value do
  232. for Property, Value in next, Table do
  233. NewObject.RenderSettings[Name][Property] = Value
  234. end
  235. end
  236. end
  237. end
  238.  
  239. NewObject = setmetatable(NewObject, Object)
  240. ESP.Objects[Model] = NewObject
  241.  
  242. NewObject.Objects.Box = Draw("Quad", NewObject.Objects.Box)
  243. NewObject.Objects.Name = Draw("Text", NewObject.Objects.Name)
  244. NewObject.Objects.Tracer = Draw("Line", NewObject.Objects.Tracer)
  245.  
  246. NewObject.Connections.Destroying = Model.Destroying:Connect(function() -- We don't want the ESP to try to render an object that doesn't exist anymore.
  247. NewObject:Destroy()
  248. end)
  249.  
  250. NewObject.Connections.AncestryChanged = Model.AncestryChanged:Connect(function(Old, New) -- Ditto on the Destroying connection, but some games might try to parent characters to nil to prevent esp so this could cause problems and can be toggled.
  251. if not Model:IsDescendantOf(workspace) and NewObject.RenderSettings.DestroyOnRemove or NewObject.GlobalSettings.DestroyOnRemove then
  252. NewObject:Destroy()
  253. end
  254. end)
  255.  
  256. local Humanoid = Model:FindFirstChildOfClass("Humanoid")
  257.  
  258. if Humanoid then
  259. NewObject.Connections.Died = Humanoid.Died:Connect(function()
  260. if Settings.RemoveOnDeath then
  261. NewObject:Destroy()
  262. end
  263. end)
  264. end
  265.  
  266. NewObject.Connections.Removing = Model.AncestryChanged:Connect(function()
  267. if NewObject.RenderSettings.DestroyOnRemove or NewObject.GlobalSettings.DestroyOnRemove then
  268. NewObject:Destroy()
  269. end
  270. end)
  271.  
  272. return NewObject
  273. end
  274.  
  275. function Object:GetQuad() -- Gets a table of positions for use in pretty much every ESP function. This also returns if the player is onscreen and will not return anything in the case that they aren't.
  276. local RenderSettings = self.RenderSettings
  277. local GlobalSettings = self.GlobalSettings
  278.  
  279. local MaxSize = GetValue(RenderSettings, GlobalSettings, "MaxBoxSize")
  280. local BoxTopOffset = GetValue(RenderSettings, GlobalSettings, "BoxTopOffset")
  281.  
  282. local Model = self.Model
  283. local Pivot = Model:GetPivot()
  284. local BoxPosition, Size = Model:GetBoundingBox()
  285.  
  286. Pivot = Pivot * ESP:GetOffset(Model)
  287.  
  288. Size = Size * Vector3.new(1, 1, 0) -- Thanks synapse editor for not supporting compound operators very cool (also fuck the depth).
  289.  
  290. local X, Y = math.clamp(Size.X, 1, MaxSize.X) / 2, math.clamp(Size.Y, 1, MaxSize.Y) / 2
  291.  
  292. -- Hey check out this amazing epic readable math and very simple easy-to-type variable names.
  293. -- There's some leftover code here from when I was using Vector3s instead of CFrames. If you want boxes to be locked on one axis, you can add this back. You're a sociopath if you do, though.
  294. local PivotVector, PivotOnScreen = (ESP:GetScreenPosition(Pivot.Position))
  295. local BoxTop = ESP:GetScreenPosition((Pivot * CFrame.new(0, Y, 0)).Position + (BoxTopOffset)) --[[+ (Size * Vector3.new(0, 1, 0) / 2) + Vector3.new(0, 1, 0)]]
  296. local BoxBottom = ESP:GetScreenPosition((Pivot * CFrame.new(0, -Y, 0)).Position)
  297. local TopRight, TopRightOnScreen = ESP:GetScreenPosition((Pivot * CFrame.new(-X, Y, 0)).Position) --[[+ ((Size * Vector3.new(-1, 1, 0)) / 2)]]
  298. local TopLeft, TopLeftOnScreen = ESP:GetScreenPosition((Pivot * CFrame.new(X, Y, 0)).Position)--[[Pivot + (Size / 2))]]
  299. local BottomLeft, BottomLeftOnScreen = ESP:GetScreenPosition((Pivot * CFrame.new(X, -Y, 0)).Position) --[[+ ((Size * Vector3.new(1, -1, 0)) / 2))]]
  300. local BottomRight, BottomRightOnScreen = ESP:GetScreenPosition((Pivot * CFrame.new(-X, -Y, 0)).Position)--[[ - (Size / 2))]]
  301.  
  302. if TopRightOnScreen or TopLeftOnScreen or BottomLeftOnScreen or BottomRightOnScreen then -- Boxes don't cause weird drawing issues if any part of the character is on-screen (only checks the bounding box, a player's arm can be slightly poking out and the box won't draw).
  303. local Positions = {
  304. BoxBottom = BoxBottom, -- For tracers :3.
  305. Pivot = PivotVector, -- The model base because maybe I'll use it? I have no idea stop asking me these questions.
  306. BoxTop = BoxTop, -- Just above the top of the model because funny nametag esp.
  307. TopRight = TopRight, -- Top Right
  308. TopLeft = TopLeft, -- Top Left
  309. BottomLeft = BottomLeft, -- Bottom Left
  310. BottomRight = BottomRight, -- Bottom Right
  311. }
  312.  
  313. return Positions, true -- The player is on the screen, so the box can be drawn.
  314. end
  315.  
  316. return false -- The player is offscreen and drawing this box is going to do crazy shit, stop.
  317. end
  318.  
  319. function Object:DrawBox(Quad) -- Draws a box around the player based on a given quad.
  320. local RenderSettings = self.RenderSettings
  321. local GlobalSettings = self.GlobalSettings
  322.  
  323. local RenderBoxes = RenderSettings.Boxes
  324. local GlobalBoxes = GlobalSettings.Boxes
  325.  
  326. local TeamColors = GetValue(RenderSettings, GlobalSettings, "TeamColors")
  327. local Thickness = GetValue(RenderBoxes, GlobalBoxes, "Thickness")
  328. local Color = GetValue(RenderBoxes, GlobalBoxes, "Color")
  329.  
  330. local Properties = {
  331. Visible = true,
  332. Color = TeamColors and ESP:GetTeamColor(self.Model) or Color,
  333. Thickness = Thickness,
  334. PointA = Quad.TopRight,
  335. PointB = Quad.TopLeft,
  336. PointC = Quad.BottomLeft,
  337. PointD = Quad.BottomRight,
  338. }
  339.  
  340. for Property, Value in next, Properties do
  341. self.Objects.Box[Property] = Value
  342. end
  343. end
  344.  
  345. function Object:DrawName(Quad)
  346. local RenderSettings = self.RenderSettings
  347. local GlobalSettings = self.GlobalSettings
  348.  
  349. local RenderNames = RenderSettings.Names
  350. local GlobalNames = GlobalSettings.Names
  351.  
  352.  
  353. local Settings = RenderSettings.Names or GlobalNames
  354.  
  355. local ShowDistance = GetValue(RenderNames, GlobalNames, "Distance")
  356. local Size = GetValue(RenderNames, GlobalNames, "Size")
  357. local Resize = GetValue(RenderNames, GlobalNames, "Resize")
  358. local ResizeWeight = GetValue(RenderNames, GlobalNames, "ResizeWeight")
  359. local ShowHealth = GetValue(RenderNames, GlobalNames, "Health")
  360. local Font = GetValue(RenderNames, GlobalNames, "Font")
  361. local Center = GetValue(RenderNames, GlobalNames, "Center")
  362. local TeamColors = GetValue(RenderNames, GlobalNames, "TeamColors")
  363. local Color = GetValue(RenderNames, GlobalNames, "Color")
  364. local Outline = GetValue(RenderNames, GlobalNames, "Outline")
  365.  
  366. local Distance = self.Model:GetPivot().Position
  367.  
  368. local Properties = {
  369. Visible = true,
  370. Color = TeamColors and ESP:GetTeamColor(self.Model) or Color,
  371. Outline = Outline,
  372. Text = not (Size or ShowHealth) and self.Name or ("%s [%sm]%s"):format(self.Name, ShowDistance and tostring(ESP:GetDistance(Distance)) or "", ShowHealth and ("\n%d/%d (%d%%)"):format(ESP:GetHealth(self.Model)) or ""), -- My god this is an ugly string.format
  373. Size = not Resize and Size or Size - math.clamp((ESP:GetDistance(Distance) * ResizeWeight), 1, Size * 0.75),
  374. Font = Font,
  375. Center = Center,
  376. Position = Quad.BoxTop,
  377. }
  378.  
  379. for Property, Value in next, Properties do
  380. self.Objects.Name[Property] = Value
  381. end
  382. end
  383.  
  384. function Object:DrawTracer(Quad)
  385. local RenderSettings = self.RenderSettings
  386. local GlobalSettings = self.GlobalSettings
  387.  
  388. local RenderTracers = RenderSettings.Tracers
  389. local GlobalTracers = GlobalSettings.Tracers
  390.  
  391. local TeamColors = GetValue(RenderTracers, GlobalTracers, "TeamColors")
  392. local Color = GetValue(RenderTracers, GlobalTracers, "Color")
  393. local Thickness = GetValue(RenderTracers, GlobalTracers, "Thickness")
  394.  
  395. local Properties = {
  396. Visible = true,
  397. Color = TeamColors and ESP:GetTeamColor(self.Model) or Color,
  398. Thickness = Thickness,
  399. From = workspace.CurrentCamera.ViewportSize * Vector2.new(.5, 1),
  400. To = Quad.BoxBottom,
  401. }
  402.  
  403. for Property, Value in next, Properties do
  404. self.Objects.Tracer[Property] = Value
  405. end
  406. end
  407.  
  408. function Object:Destroy()
  409. ESP.Objects[self.Model] = nil
  410. self:ClearDrawings()
  411.  
  412. for i,v in next, self.Objects do
  413. v:Remove()
  414. end
  415.  
  416. for i,v in next, self.Connections do -- I could use a module like maid but I'm lazy.
  417. v:Disconnect()
  418. end
  419.  
  420. table.clear(self.Objects)
  421. end
  422.  
  423. function Object:ClearDrawings()
  424. for i,v in next, self.Objects do
  425. v.Visible = false
  426. end
  427. end
  428.  
  429. function Object:Refresh()
  430. local Model = self.Model
  431. local Quad = self:GetQuad()
  432. local RenderSettings = self.RenderSettings
  433. local GlobalSettings = self.GlobalSettings
  434.  
  435. local TeamBased = GetValue(RenderSettings, GlobalSettings, "TeamBased")
  436. local MaxDistance = GetValue(RenderSettings, GlobalSettings, "MaxDistance")
  437. local Boxes = GetValue(RenderSettings.Boxes, GlobalSettings.Boxes, "Enabled")
  438. local Names = GetValue(RenderSettings.Names, GlobalSettings.Names, "Enabled")
  439. local Tracers = GetValue(RenderSettings.Tracers, GlobalSettings.Tracers, "Enabled")
  440.  
  441. if not ESP.Enabled then
  442. return self:ClearDrawings() -- This is obvious and doesn't need a comment, but I am adding a comment here because it's funny.
  443. end
  444.  
  445. if not Model.Parent or not Model:IsDescendantOf(workspace) then
  446. return self:ClearDrawings() -- I don't want stuff to render in nil, edit this if you don't like it pls.
  447. end
  448.  
  449. if not Quad then
  450. return self:ClearDrawings() -- Player isn't on-screen
  451. end
  452.  
  453. if TeamBased and not ESP:IsHostile(Model) then
  454. return self:ClearDrawings()
  455. end
  456.  
  457. if ESP:GetDistance(Model:GetPivot().Position) > MaxDistance then
  458. return self:ClearDrawings()
  459. end
  460.  
  461. if Boxes then
  462. self:DrawBox(Quad)
  463. else
  464. self.Objects.Box.Visible = false
  465. end
  466.  
  467. if Names then
  468. self:DrawName(Quad)
  469. else
  470. self.Objects.Name.Visible = false
  471. end
  472.  
  473. if Tracers then
  474. self:DrawTracer(Quad)
  475. else
  476. self.Objects.Tracer.Visible = false
  477. end
  478. end
  479.  
  480. game.RunService.Stepped:Connect(function()
  481. for i, Object in next, ESP.Objects do
  482. Object:Refresh()
  483. end
  484. end)
  485.  
  486. return ESP
Add Comment
Please, Sign In to add comment