Advertisement
MaxproGlitcher

Max ESP Version Test

Oct 29th, 2023
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.70 KB | None | 0 0
  1. --Settings--
  2. local ESP = {
  3. Enabled = false,
  4. Boxes = true,
  5. BoxShift = CFrame.new(0,-1.5,0),
  6. BoxSize = Vector3.new(4,6,0),
  7. Color = Color3.fromRGB(255, 170, 0),
  8. HighlightColor = Color3.new(1,1,1),
  9. HighlightEnabled = false,
  10. FaceCamera = false,
  11. Names = true,
  12. TeamColor = true,
  13. Thickness = 2,
  14. AttachShift = 1,
  15. TeamMates = true,
  16. Players = true,
  17. Bars = true,
  18. GlobalBars = {},
  19. HrpName = "HumanoidRootPart",
  20. ScreenScale = 1,
  21.  
  22. Objects = setmetatable({}, {__mode="kv"}),
  23. Overrides = {}
  24. }
  25. getgenv().shared.ESP = ESP
  26.  
  27. if ... and type(...) == "table" then
  28. for i,v in pairs(...) do
  29. ESP[i] = v
  30. end
  31. end
  32.  
  33. --Declarations--
  34. local cam = workspace.CurrentCamera
  35. local plrs = game:GetService("Players")
  36. local plr = plrs.LocalPlayer
  37. local mouse = plr:GetMouse()
  38.  
  39. local V3new = Vector3.new
  40. local function WorldToViewportPoint(...)
  41. local a,b = cam.WorldToViewportPoint(...)
  42. a = Vector3.new(a.X * ESP.ScreenScale, a.Y * ESP.ScreenScale, a.Z)
  43. return a,b
  44. end
  45.  
  46. --Functions--
  47. local function Draw(obj, props)
  48. local new = Drawing.new(obj)
  49.  
  50. props = props or {}
  51. for i,v in pairs(props) do
  52. new[i] = v
  53. end
  54. return new
  55. end
  56.  
  57. function ESP.GetFOV()
  58. local screenSize = workspace.CurrentCamera.ViewportSize
  59. return math.max(math.min(screenSize.X * ESP.ScreenScale, screenSize.Y * ESP.ScreenScale)/2, 400)
  60. end
  61.  
  62. function ESP.FOVCircle(radius)
  63. local FOVCircle = Drawing.new("Circle")
  64. FOVCircle.Radius = radius
  65. FOVCircle.Color = Color3.fromRGB(255, 170, 0)
  66. FOVCircle.Thickness = 3
  67. FOVCircle.Filled = false
  68.  
  69. local CircleTbl = {
  70. Update = function()
  71. FOVCircle.Position = Vector2.new(mouse.X * ESP.ScreenScale, mouse.Y * ESP.ScreenScale+36)
  72. end
  73. }
  74. table.insert(ESP.Objects, CircleTbl)
  75. return {Drawing = FOVCircle, Tbl = CircleTbl, Update = CircleTbl.Update}
  76. end
  77.  
  78. function ESP.GetTarget(Settings, GetEnemies, hrp)
  79. hrp = hrp or ESP.HrpName
  80. return function(chance, noVisCheck, ignoreList)
  81. noVisCheck = Settings.Wallbang or Settings.WallBang or Settings.VisCheck == false or noVisCheck
  82. ignoreList = Settings.IgnoreList or ignoreList
  83.  
  84. local cam = workspace.CurrentCamera
  85.  
  86. local camPos = cam.CFrame.p
  87. local clPos,clPart,clModel
  88. for i,v in pairs(GetEnemies()) do
  89. if v.Character and v.Character.Parent then
  90. local part = v.Character:FindFirstChild("Head")
  91. if chance and math.random(1, 100) >= Settings.HeadshotChance then
  92. part = v.Character:FindFirstChild(hrp)
  93. end
  94. if part then
  95. local p,vis = cam:WorldToViewportPoint(part.Position)
  96. if vis then
  97. local startPos = camPos
  98.  
  99. local workspaceDist = (cam.CFrame.p - part.Position).magnitude
  100.  
  101. local ray = Ray.new(startPos, CFrame.new(cam.CFrame.p, part.Position).LookVector.Unit * p.Z)
  102.  
  103. local hit
  104. if not noVisCheck then
  105. local ignore = ignoreList or {}
  106. ignore[#ignore + 1] = plr.Character
  107. ignore[#ignore + 1] = part.Parent
  108. ignore[#ignore + 1] = cam
  109.  
  110. hit = workspace:FindPartOnRayWithIgnoreList(ray, ignore)
  111. end
  112. if not hit and workspaceDist <= Settings.AimDistance then
  113. local dist
  114. local ok = true
  115. if Settings.AimMode == "Cursor" then
  116. dist = (Vector3.new(mouse.X,mouse.Y+36,0) - Vector3.new(p.X,p.Y,0)).magnitude
  117. ok = dist <= (Settings.UsedFOVRange or Settings.FOVRange)
  118. elseif Settings.AimMode == "Character" then
  119. dist = (camPos - part.Position).magnitude
  120. end
  121. if not clPos and ok then
  122. clPos = dist
  123. clPart = part
  124. clModel = v.Character
  125. end
  126. if ok and dist and dist < clPos then
  127. clPos = dist
  128. clPart = part
  129. clModel = v.Character
  130. end
  131. end
  132. end
  133. end
  134. end
  135. end
  136. return clPart,clModel
  137. end
  138. end
  139.  
  140. function ESP:RegisterHighlight(GetTarget)
  141. game:GetService("RunService").Stepped:Connect(function()
  142. if not ESP.HighlightEnabled or not ESP.Enabled then
  143. return
  144. end
  145. local target, char = GetTarget()
  146. if target and char then
  147. ESP.Highlighted = char
  148. else
  149. ESP.Highlighted = nil
  150. end
  151. end)
  152. end
  153.  
  154. function ESP:GetTeam(p)
  155. local ov = self.Overrides.GetTeam
  156. if ov then
  157. return ov(p)
  158. end
  159.  
  160. return p and p.Team
  161. end
  162.  
  163. function ESP:IsTeamMate(p)
  164. local ov = self.Overrides.IsTeamMate
  165. if ov then
  166. return ov(p)
  167. end
  168.  
  169. return self:GetTeam(p) == self:GetTeam(plr)
  170. end
  171.  
  172. function ESP:GetColor(obj)
  173. local ov = self.Overrides.GetColor
  174. if ov then
  175. return ov(obj)
  176. end
  177. local p = self:GetPlrFromChar(obj)
  178. return p and self.TeamColor and p.Team and p.Team.TeamColor.Color or self.Color
  179. end
  180.  
  181. function ESP:GetPlrFromChar(char)
  182. local ov = self.Overrides.GetPlrFromChar
  183. if ov then
  184. return ov(char)
  185. end
  186.  
  187. return plrs:GetPlayerFromCharacter(char)
  188. end
  189.  
  190. function ESP:Toggle(bool)
  191. self.Enabled = bool
  192. if not bool then
  193. for i,v in pairs(self.Objects) do
  194. if v.Type == "Box" then --fov circle etc
  195. if v.Temporary then
  196. v:Remove()
  197. else
  198. for i,v in pairs(v.Components) do
  199. v.Visible = false
  200. end
  201. end
  202. end
  203. end
  204. end
  205. end
  206.  
  207. --[[function ESP:ToggleTeamMates(bool)
  208. self.TeamMates = bool
  209. end
  210.  
  211. function ESP:ToggleTeamColor(bool)
  212. self.TeamColor = bool
  213. end]]
  214.  
  215. function ESP:GetBox(obj)
  216. return self.Objects[obj]
  217. end
  218.  
  219. function ESP:AddObjectListener(parent, options)
  220. local function NewListener(c)
  221. if type(options.Type) == "string" and c:IsA(options.Type) or options.Type == nil then
  222. if type(options.Name) == "string" and c.Name == options.Name or options.Name == nil then
  223. if not options.Validator or options.Validator(c) then
  224. local box = ESP:Add(c, {
  225. PrimaryPart = type(options.PrimaryPart) == "string" and c:WaitForChild(options.PrimaryPart) or type(options.PrimaryPart) == "function" and options.PrimaryPart(c),
  226. Color = type(options.Color) == "function" and options.Color(c) or options.Color,
  227. ColorDynamic = options.ColorDynamic,
  228. Name = type(options.CustomName) == "function" and options.CustomName(c) or options.CustomName,
  229. IsEnabled = options.IsEnabled,
  230. RenderInNil = options.RenderInNil
  231. })
  232. --TODO: add a better way of passing options
  233. if options.OnAdded then
  234. coroutine.wrap(options.OnAdded)(box)
  235. end
  236. end
  237. end
  238. end
  239. end
  240.  
  241. if options.Recursive then
  242. parent.DescendantAdded:Connect(NewListener)
  243. for i,v in pairs(parent:GetDescendants()) do
  244. coroutine.wrap(NewListener)(v)
  245. end
  246. else
  247. parent.ChildAdded:Connect(NewListener)
  248. for i,v in pairs(parent:GetChildren()) do
  249. coroutine.wrap(NewListener)(v)
  250. end
  251. end
  252. end
  253. --ESP:AddObjectListener(parent, type<string ClassName, function validator, nil any>, name<string, nil any> color<Color3, function>, optional isEnabled<string fieldNameInESPTable, function>, onAdded<function>)
  254.  
  255. function ESP:AddGlobalPlayerBar(name, options, onAdded)
  256. table.insert(self.GlobalBars, {name, options, onAdded})
  257. for i,box in pairs(self.Objects) do
  258. if box.Player then
  259. coroutine.wrap(onAdded)(box, box:AddBar(name, options))
  260. end
  261. end
  262. end
  263.  
  264. local boxBase = {}
  265. boxBase.__index = boxBase
  266.  
  267. function boxBase:Remove()
  268. ESP.Objects[self.Object] = nil
  269. for i,v in pairs(self.Components) do
  270. v.Visible = false
  271. v:Remove()
  272. self.Components[i] = nil
  273. end
  274. end
  275.  
  276. function boxBase:Update()
  277. if not self.PrimaryPart then
  278. --warn("not supposed to print", self.Object)
  279. return self:Remove()
  280. end
  281.  
  282. local color
  283. if ESP.Highlighted == self.Object then
  284. color = ESP.HighlightColor
  285. else
  286. color = self.Color or self.ColorDynamic and self:ColorDynamic() or ESP:GetColor(self.Object) or ESP.Color
  287. end
  288.  
  289. local allow = true
  290. if ESP.Overrides.UpdateAllow and not ESP.Overrides.UpdateAllow(self) then
  291. allow = false
  292. end
  293. if self.Player and not ESP.TeamMates and ESP:IsTeamMate(self.Player) then
  294. allow = false
  295. end
  296. if self.Player and not ESP.Players then
  297. allow = false
  298. end
  299. if self.IsEnabled and (type(self.IsEnabled) == "string" and not ESP[self.IsEnabled] or type(self.IsEnabled) == "function" and not self:IsEnabled()) then
  300. allow = false
  301. end
  302. if not workspace:IsAncestorOf(self.PrimaryPart) and not self.RenderInNil then
  303. allow = false
  304. end
  305.  
  306. if not allow then
  307. for i,v in pairs(self.Components) do
  308. v.Visible = false
  309. end
  310. self.Distance = nil
  311. return
  312. end
  313.  
  314. if ESP.Highlighted == self.Object then
  315. color = ESP.HighlightColor
  316. end
  317.  
  318. --calculations--
  319. local cf = self.PrimaryPart.CFrame
  320. if ESP.FaceCamera then
  321. cf = CFrame.new(cf.p, cf.p - cam.CFrame.lookVector)
  322. end
  323. local size = self.Size
  324. local locs = {
  325. TopLeft = cf * ESP.BoxShift * CFrame.new(size.X/2,size.Y/2,0),
  326. TopRight = cf * ESP.BoxShift * CFrame.new(-size.X/2,size.Y/2,0),
  327. BottomLeft = cf * ESP.BoxShift * CFrame.new(size.X/2,-size.Y/2,0),
  328. BottomRight = cf * ESP.BoxShift * CFrame.new(-size.X/2,-size.Y/2,0),
  329. TagPos = cf * ESP.BoxShift * CFrame.new(0,size.Y/2,0),
  330. Torso = cf * ESP.BoxShift
  331. }
  332.  
  333. local TopLeft, Vis1
  334. local BottomLeft, Vis3
  335. if ESP.Boxes then
  336. TopLeft, Vis1 = WorldToViewportPoint(cam, locs.TopLeft.p)
  337. local TopRight, Vis2 = WorldToViewportPoint(cam, locs.TopRight.p)
  338. BottomLeft, Vis3 = WorldToViewportPoint(cam, locs.BottomLeft.p)
  339. local BottomRight, Vis4 = WorldToViewportPoint(cam, locs.BottomRight.p)
  340.  
  341. if self.Components.Quad then
  342. if Vis1 or Vis2 or Vis3 or Vis4 then
  343. self.Components.Quad.Visible = true
  344. self.Components.Quad.PointA = Vector2.new(TopRight.X, TopRight.Y)
  345. self.Components.Quad.PointB = Vector2.new(TopLeft.X, TopLeft.Y)
  346. self.Components.Quad.PointC = Vector2.new(BottomLeft.X, BottomLeft.Y)
  347. self.Components.Quad.PointD = Vector2.new(BottomRight.X, BottomRight.Y)
  348. self.Components.Quad.Color = color
  349. else
  350. self.Components.Quad.Visible = false
  351. end
  352. end
  353. else
  354. self.Components.Quad.Visible = false
  355. end
  356.  
  357. if ESP.Names then
  358. local TagPos, Vis5 = WorldToViewportPoint(cam, locs.TagPos.p)
  359.  
  360. if Vis5 then
  361. local dist = (cam.CFrame.p - cf.p).magnitude
  362. self.Distance = dist
  363.  
  364. self.Components.Name.Visible = true
  365. self.Components.Name.Position = Vector2.new(TagPos.X, TagPos.Y)
  366. self.Components.Name.Text = self.Name
  367. self.Components.Name.Color = color
  368.  
  369. self.Components.Distance.Visible = true
  370. self.Components.Distance.Position = Vector2.new(TagPos.X, TagPos.Y + 14)
  371. self.Components.Distance.Text = math.floor(dist) .."m away"
  372. self.Components.Distance.Color = color
  373. else
  374. self.Distance = nil
  375. self.Components.Name.Visible = false
  376. self.Components.Distance.Visible = false
  377. end
  378. else
  379. self.Distance = nil
  380. self.Components.Name.Visible = false
  381. self.Components.Distance.Visible = false
  382. end
  383.  
  384. if ESP.Tracers then
  385. local TorsoPos, Vis6 = WorldToViewportPoint(cam, locs.Torso.p)
  386.  
  387. if Vis6 then
  388. self.Components.Tracer.Visible = true
  389. self.Components.Tracer.From = Vector2.new(TorsoPos.X, TorsoPos.Y)
  390. self.Components.Tracer.To = Vector2.new(cam.ViewportSize.X*ESP.ScreenScale/2,cam.ViewportSize.Y*ESP.ScreenScale/ESP.AttachShift)
  391. self.Components.Tracer.Color = color
  392. else
  393. self.Components.Tracer.Visible = false
  394. end
  395. else
  396. self.Components.Tracer.Visible = false
  397. end
  398.  
  399. if ESP.Bars and ESP.FaceCamera then
  400. if not ESP.Boxes then
  401. TopLeft, Vis1 = WorldToViewportPoint(cam, locs.TopLeft.p)
  402. BottomLeft, Vis3 = WorldToViewportPoint(cam, locs.BottomLeft.p)
  403. end
  404.  
  405. local amount = 0
  406. for i,v in pairs(self.Bars) do
  407. if (Vis1 or Vis3) and v.Value < 1 then
  408. local x = TopLeft.X - amount * 5 - 3 --i like magic numbers, basically 1st offset should be -3, 2nd -8, 3rd -13, etc.
  409. local barWidth = 4
  410. local barPadding = 1
  411.  
  412. v.Components.BarBackground.Visible = true
  413. v.Components.BarBackground.PointA = Vector2.new(x, TopLeft.Y)
  414. v.Components.BarBackground.PointB = Vector2.new(x - barWidth, TopLeft.Y)
  415. v.Components.BarBackground.PointC = Vector2.new(x - barWidth, BottomLeft.Y)
  416. v.Components.BarBackground.PointD = Vector2.new(x, BottomLeft.Y)
  417. --v.Components.BarBackground.Color = color
  418.  
  419. v.Components.Bar.Visible = true
  420. v.Components.Bar.Color = v.Color
  421. local height = (BottomLeft.Y - TopLeft.Y - barPadding * 2) * (1-v.Value)
  422. v.Components.Bar.PointA = Vector2.new(x - barPadding, TopLeft.Y + height + barPadding)
  423. v.Components.Bar.PointB = Vector2.new(x - barWidth + barPadding, TopLeft.Y + height + barPadding)
  424. v.Components.Bar.PointC = Vector2.new(x - barWidth + barPadding, BottomLeft.Y - barPadding)
  425. v.Components.Bar.PointD = Vector2.new(x - barPadding, BottomLeft.Y - barPadding)
  426. amount = amount + 1
  427. else
  428. v.Components.BarBackground.Visible = false
  429. v.Components.Bar.Visible = false
  430. end
  431. end
  432. else
  433. for i,v in pairs(self.Bars) do
  434. v.Components.BarBackground.Visible = false
  435. v.Components.Bar.Visible = false
  436. end
  437. end
  438. end
  439.  
  440. function ESP:Add(obj, options)
  441. if not obj.Parent and not options.RenderInNil then
  442. return warn("[KH ESP]:", obj, "has no parent")
  443. end
  444.  
  445. local box = setmetatable({
  446. Name = options.Name or obj.Name,
  447. Type = "Box",
  448. Color = options.Color --[[or self:GetColor(obj)]],
  449. Size = options.Size or self.BoxSize,
  450. Object = obj,
  451. Player = options.Player or plrs:GetPlayerFromCharacter(obj),
  452. PrimaryPart = options.PrimaryPart or obj.ClassName == "Model" and (obj.PrimaryPart or obj:FindFirstChild(ESP.HrpName) or obj:FindFirstChildWhichIsA("BasePart")) or obj:IsA("BasePart") and obj,
  453. Components = {},
  454. IsEnabled = options.IsEnabled,
  455. Temporary = options.Temporary,
  456. ColorDynamic = options.ColorDynamic,
  457. RenderInNil = options.RenderInNil,
  458. Bars = {}
  459. }, boxBase)
  460.  
  461. if self:GetBox(obj) then
  462. self:GetBox(obj):Remove()
  463. end
  464.  
  465. box.Components["Quad"] = Draw("Quad", {
  466. Thickness = self.Thickness,
  467. Color = color,
  468. Transparency = 1,
  469. Filled = false,
  470. Visible = self.Enabled and self.Boxes
  471. })
  472. box.Components["Name"] = Draw("Text", {
  473. Text = box.Name,
  474. Color = box.Color,
  475. Center = true,
  476. Outline = true,
  477. Size = 19,
  478. Visible = self.Enabled and self.Names
  479. })
  480. box.Components["Distance"] = Draw("Text", {
  481. Color = box.Color,
  482. Center = true,
  483. Outline = true,
  484. Size = 19,
  485. Visible = self.Enabled and self.Names
  486. })
  487.  
  488. box.Components["Tracer"] = Draw("Line", {
  489. Thickness = ESP.Thickness,
  490. Color = box.Color,
  491. Transparency = 1,
  492. Visible = self.Enabled and self.Tracers
  493. })
  494. self.Objects[obj] = box
  495.  
  496. obj.AncestryChanged:Connect(function(_, parent)
  497. if parent == nil and ESP.AutoRemove ~= false then
  498. box:Remove()
  499. end
  500. end)
  501. obj:GetPropertyChangedSignal("Parent"):Connect(function()
  502. if obj.Parent == nil and ESP.AutoRemove ~= false then
  503. box:Remove()
  504. end
  505. end)
  506.  
  507. local hum = obj:FindFirstChildOfClass("Humanoid")
  508. if hum then
  509. hum.Died:Connect(function()
  510. if ESP.AutoRemove ~= false then
  511. box:Remove()
  512. end
  513. end)
  514. end
  515.  
  516. return box
  517. end
  518.  
  519. local barBase = {}
  520. barBase.__index = barBase
  521.  
  522. function boxBase:AddBar(name, options)
  523. local bar = setmetatable({
  524. Name = name,
  525. Type = "Bar",
  526. Color = options.Color,
  527. Components = {},
  528. Value = 0.4
  529. }, barBase)
  530.  
  531. table.insert(self.Bars, bar)
  532.  
  533. bar.Components["BarBackground"] = Draw("Quad", {
  534. Thickness = ESP.Thickness,
  535. Color = Color3.fromRGB(26,26,26),
  536. Transparency = 1,
  537. Filled = true,
  538. Visible = ESP.Enabled and ESP.Bars
  539. })
  540. bar.Components["Bar"] = Draw("Quad", {
  541. Thickness = ESP.Thickness,
  542. Color = bar.Color,
  543. Transparency = 1,
  544. Filled = true,
  545. Visible = ESP.Enabled and ESP.Bars
  546. })
  547. for i,v in pairs(bar.Components) do
  548. table.insert(self.Components, v) --for box:Remove()
  549. end
  550. return bar
  551. end
  552.  
  553. local function CharAdded(char)
  554. local p = plrs:GetPlayerFromCharacter(char)
  555. if not char:FindFirstChild(ESP.HrpName) then
  556. local ev
  557. ev = char.ChildAdded:Connect(function(c)
  558. if c.Name == ESP.HrpName then
  559. ev:Disconnect()
  560. local box = ESP:Add(char, {
  561. Name = p.Name,
  562. Player = p,
  563. PrimaryPart = c
  564. })
  565. for i,v in pairs(ESP.GlobalBars) do
  566. coroutine.wrap(v[3])(box, box:AddBar(v[1], v[2]))
  567. end
  568. end
  569. end)
  570. else
  571. local box = ESP:Add(char, {
  572. Name = p.Name,
  573. Player = p,
  574. PrimaryPart = char:FindFirstChild(ESP.HrpName)
  575. })
  576. for i,v in pairs(ESP.GlobalBars) do
  577. coroutine.wrap(v[3])(box, box:AddBar(v[1], v[2]))
  578. end
  579. end
  580. end
  581. local function PlayerAdded(p)
  582. p.CharacterAdded:Connect(CharAdded)
  583. if p.Character then
  584. coroutine.wrap(CharAdded)(p.Character)
  585. end
  586. end
  587. plrs.PlayerAdded:Connect(PlayerAdded)
  588. for i,v in pairs(plrs:GetPlayers()) do
  589. if v ~= plr then
  590. PlayerAdded(v)
  591. end
  592. end
  593.  
  594. game:GetService("RunService").RenderStepped:Connect(function()
  595. cam = workspace.CurrentCamera
  596. for i,v in (ESP.Enabled and pairs or ipairs)(ESP.Objects) do
  597. if v.Update then
  598. local s,e = pcall(v.Update, v)
  599. if not s then warn("[EU]", e, v.Object:GetFullName()) end
  600. end
  601. end
  602. end)
  603.  
  604. return ESP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement