Advertisement
DankGreenMoney

ESPOP

May 13th, 2022
688
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.96 KB | None | 0 0
  1. --Settings--
  2. local ESP = {
  3.     Enabled = false,
  4.     Boxes = false,
  5.     BoxShift = CFrame.new(0,-1.5,0),
  6.     BoxSize = Vector3.new(4,6,0),
  7.     Color = Color3.fromRGB(199, 255, 255),
  8.     ToolColor = Color3.fromRGB(199, 255, 255),
  9.     FaceCamera = false,
  10.     Names = false,
  11.     Distance = false,
  12.     Health = false,
  13.     Tool = false,
  14.     TeamColor = true,
  15.     Thickness = 1.5,
  16.     AttachShift = 1,
  17.     TeamMates = true,
  18.     Players = true,
  19.     DistanceS = 2000,
  20.  
  21.     Objects = setmetatable({}, {__mode="kv"}),
  22.     Overrides = {}
  23. }
  24.  
  25. --Declarations--
  26. local cam = workspace.CurrentCamera
  27. local plrs = game:GetService("Players")
  28. local plr = plrs.LocalPlayer
  29. local mouse = plr:GetMouse()
  30.  
  31. local V3new = Vector3.new
  32. local WorldToViewportPoint = cam.WorldToViewportPoint
  33.  
  34. --Functions--
  35. local function Draw(obj, props)
  36.     local new = Drawing.new(obj)
  37.  
  38.     props = props or {}
  39.     for i,v in pairs(props) do
  40.         new[i] = v
  41.     end
  42.     return new
  43. end
  44.  
  45. function ESP:GetTeam(p)
  46.     local ov = self.Overrides.GetTeam
  47.     if ov then
  48.         return ov(p)
  49.     end
  50.  
  51.     return p and p.Team
  52. end
  53.  
  54. function ESP:IsTeamMate(p)
  55.     local ov = self.Overrides.IsTeamMate
  56.     if ov then
  57.         return ov(p)
  58.     end
  59.  
  60.     return self:GetTeam(p) == self:GetTeam(plr)
  61. end
  62.  
  63. function ESP:GetColor(obj)
  64.     local ov = self.Overrides.GetColor
  65.     if ov then
  66.         return ov(obj)
  67.     end
  68.     local p = self:GetPlrFromChar(obj)
  69.     return p and self.TeamColor and p.Team and p.Team.TeamColor.Color or self.Color
  70. end
  71.  
  72. function ESP:GetPlrFromChar(char)
  73.     local ov = self.Overrides.GetPlrFromChar
  74.     if ov then
  75.         return ov(char)
  76.     end
  77.  
  78.     return plrs:GetPlayerFromCharacter(char)
  79. end
  80.  
  81. function ESP:Toggle(bool)
  82.     self.Enabled = bool
  83.     if not bool then
  84.         for i,v in pairs(self.Objects) do
  85.             if v.Type == "Box" then --fov circle etc
  86.                 if v.Temporary then
  87.                     v:Remove()
  88.                 else
  89.                     for i,v in pairs(v.Components) do
  90.                         v.Visible = false
  91.                     end
  92.                 end
  93.             end
  94.         end
  95.     end
  96. end
  97.  
  98. function ESP:GetBox(obj)
  99.     return self.Objects[obj]
  100. end
  101.  
  102. function ESP:AddObjectListener(parent, options)
  103.     local function NewListener(c)
  104.         if type(options.Type) == "string" and c:IsA(options.Type) or options.Type == nil then
  105.             if type(options.Name) == "string" and c.Name == options.Name or options.Name == nil then
  106.                 if not options.Validator or options.Validator(c) then
  107.                     local box = ESP:Add(c, {
  108.                         PrimaryPart = type(options.PrimaryPart) == "string" and c:WaitForChild(options.PrimaryPart) or type(options.PrimaryPart) == "function" and options.PrimaryPart(c),
  109.                         Color = type(options.Color) == "function" and options.Color(c) or options.Color,
  110.                         ColorDynamic = options.ColorDynamic,
  111.                         Name = type(options.CustomName) == "function" and options.CustomName(c) or options.CustomName,
  112.                         IsEnabled = options.IsEnabled,
  113.                         RenderInNil = options.RenderInNil
  114.                     })
  115.                     --TODO: add a better way of passing options
  116.                     if options.OnAdded then
  117.                         coroutine.wrap(options.OnAdded)(box)
  118.                     end
  119.                 end
  120.             end
  121.         end
  122.     end
  123.  
  124.     if options.Recursive then
  125.         parent.DescendantAdded:Connect(NewListener)
  126.         for i,v in pairs(parent:GetDescendants()) do
  127.             coroutine.wrap(NewListener)(v)
  128.         end
  129.     else
  130.         parent.ChildAdded:Connect(NewListener)
  131.         for i,v in pairs(parent:GetChildren()) do
  132.             coroutine.wrap(NewListener)(v)
  133.         end
  134.     end
  135. end
  136.  
  137. local boxBase = {}
  138. boxBase.__index = boxBase
  139.  
  140. function boxBase:Remove()
  141.     ESP.Objects[self.Object] = nil
  142.     for i,v in pairs(self.Components) do
  143.         v.Visible = false
  144.         v:Remove()
  145.         self.Components[i] = nil
  146.     end
  147. end
  148.  
  149. function boxBase:Update()
  150.     if not self.PrimaryPart then
  151.         --warn("not supposed to print", self.Object)
  152.         return self:Remove()
  153.     end
  154.  
  155.     local color
  156.     if ESP.Highlighted == self.Object then
  157.         color = ESP.HighlightColor
  158.     else
  159.         color = self.Color or self.ColorDynamic and self:ColorDynamic() or ESP:GetColor(self.Object) or ESP.Color
  160.     end
  161.  
  162.     local allow = true
  163.     if ESP.Overrides.UpdateAllow and not ESP.Overrides.UpdateAllow(self) then
  164.         allow = false
  165.     end
  166.     if self.Player and not ESP.TeamMates and ESP:IsTeamMate(self.Player) then
  167.         allow = false
  168.     end
  169.     if self.Player and not ESP.Players then
  170.         allow = false
  171.     end
  172.     if self.IsEnabled and (type(self.IsEnabled) == "string" and not ESP[self.IsEnabled] or type(self.IsEnabled) == "function" and not self:IsEnabled()) then
  173.         allow = false
  174.     end
  175.     if not workspace:IsAncestorOf(self.PrimaryPart) and not self.RenderInNil then
  176.         allow = false
  177.     end
  178.  
  179.     if not allow then
  180.         for i,v in pairs(self.Components) do
  181.             v.Visible = false
  182.         end
  183.         return
  184.     end
  185.  
  186.     if ESP.Highlighted == self.Object then
  187.         color = ESP.HighlightColor
  188.     end
  189.  
  190.     --calculations--
  191.     local cf = self.PrimaryPart.CFrame
  192.     local PlayerDistance = math.floor((cf.p - cam.CFrame.p).magnitude)
  193.         if PlayerDistance < ESP.DistanceS then
  194.             if ESP.FaceCamera then
  195.                 cf = CFrame.new(cf.p, cam.CFrame.p)
  196.             end
  197.             local size = self.Size
  198.             local locs = {
  199.                 TopLeft = cf * ESP.BoxShift * CFrame.new(size.X/2,size.Y/2,0),
  200.                 TopRight = cf * ESP.BoxShift * CFrame.new(-size.X/2,size.Y/2,0),
  201.                 BottomLeft = cf * ESP.BoxShift * CFrame.new(size.X/2,-size.Y/2,0),
  202.                 BottomRight = cf * ESP.BoxShift * CFrame.new(-size.X/2,-size.Y/2,0),
  203.                 TagPos = cf * ESP.BoxShift * CFrame.new(0,size.Y/2,0),
  204.                 Torso = cf * ESP.BoxShift
  205.             }
  206.  
  207.             if ESP.Boxes then
  208.                 local TopLeft, Vis1 = WorldToViewportPoint(cam, locs.TopLeft.p)
  209.                 local TopRight, Vis2 = WorldToViewportPoint(cam, locs.TopRight.p)
  210.                 local BottomLeft, Vis3 = WorldToViewportPoint(cam, locs.BottomLeft.p)
  211.                 local BottomRight, Vis4 = WorldToViewportPoint(cam, locs.BottomRight.p)
  212.  
  213.                 if self.Components.Quad then
  214.                     if Vis1 or Vis2 or Vis3 or Vis4 then
  215.                         self.Components.Quad.Visible = true
  216.                         self.Components.Quad.PointA = Vector2.new(TopRight.X, TopRight.Y)
  217.                         self.Components.Quad.PointB = Vector2.new(TopLeft.X, TopLeft.Y)
  218.                         self.Components.Quad.PointC = Vector2.new(BottomLeft.X, BottomLeft.Y)
  219.                         self.Components.Quad.PointD = Vector2.new(BottomRight.X, BottomRight.Y)
  220.                         self.Components.Quad.Color = color
  221.                     else
  222.                         self.Components.Quad.Visible = false
  223.                     end
  224.                 end
  225.             else
  226.                 self.Components.Quad.Visible = false
  227.             end
  228.  
  229.             if ESP.Distance then
  230.                 local TagPos, Vis5 = WorldToViewportPoint(cam, locs.TagPos.p)
  231.  
  232.                 if Vis5 then
  233.                     self.Components.Distance.Visible = true
  234.                     self.Components.Distance.Position = Vector2.new(TagPos.X, TagPos.Y + 28)
  235.                     self.Components.Distance.Text = math.floor((cam.CFrame.p - cf.p).magnitude) .."m"
  236.                     self.Components.Distance.Color = color
  237.                 else
  238.                     self.Components.Distance.Visible = false
  239.                 end
  240.             else
  241.                 self.Components.Distance.Visible = false
  242.             end
  243.            
  244.             if self.Player then
  245.                 if ESP.Health then
  246.                     local TagPos, Vis5 = WorldToViewportPoint(cam, locs.TagPos.p)
  247.  
  248.                         if Vis5 then
  249.                             self.Components.Health.Visible = true
  250.                             self.Components.Health.Position = Vector2.new(TagPos.X, TagPos.Y + 14)              
  251.                             self.Components.Health.Text = math.floor(self.Player.Character.Humanoid.Health + 0.5)  .. ":" .. self.Player.Character.Humanoid.MaxHealth
  252.                             self.Components.Health.Color = color
  253.                         else
  254.                             self.Components.Health.Visible = false
  255.                         end
  256.                 else
  257.                     self.Components.Health.Visible = false
  258.                 end
  259.             else
  260.                 self.Components.Health.Visible = false
  261.             end
  262.  
  263.             if self.Player then
  264.                 if ESP.Tool then
  265.                     local TagPos, Vis5 = WorldToViewportPoint(cam, locs.TagPos.p)
  266.  
  267.                     if Vis5 then
  268.                         self.Components.Tool.Visible = true
  269.                         self.Components.Tool.Position = Vector2.new(TagPos.X, TagPos.Y - 14)
  270.                         if self.Player.Character:FindFirstChildOfClass("Tool") then
  271.                             self.Components.Tool.Text = self.Player.Character:FindFirstChildOfClass("Tool").Name
  272.                             self.Components.Tool.Color = ESP.ToolColor
  273.                         else
  274.                             self.Components.Tool.Visible = false
  275.                         end
  276.                     else
  277.                         self.Components.Tool.Visible = false
  278.                     end
  279.                 else
  280.                     self.Components.Tool.Visible = false
  281.                 end
  282.             else
  283.                 self.Components.Tool.Visible = false
  284.             end
  285.            
  286.             if ESP.Names then
  287.                 local TagPos, Vis5 = WorldToViewportPoint(cam, locs.TagPos.p)
  288.  
  289.                 if Vis5 then
  290.                     self.Components.Name.Visible = true
  291.                     self.Components.Name.Position = Vector2.new(TagPos.X, TagPos.Y)
  292.                     self.Components.Name.Text = self.Name
  293.                     self.Components.Name.Color = color
  294.                 else
  295.                     self.Components.Name.Visible = false
  296.                 end
  297.             else
  298.                 self.Components.Name.Visible = false
  299.             end
  300.  
  301.             if ESP.Tracers then
  302.                 local TorsoPos, Vis6 = WorldToViewportPoint(cam, locs.Torso.p)
  303.  
  304.                 if Vis6 then
  305.                     self.Components.Tracer.Visible = true
  306.                     self.Components.Tracer.From = Vector2.new(TorsoPos.X, TorsoPos.Y)
  307.                     self.Components.Tracer.To = Vector2.new(cam.ViewportSize.X/2,cam.ViewportSize.Y/ESP.AttachShift)
  308.                     self.Components.Tracer.Color = color
  309.                 else
  310.                     self.Components.Tracer.Visible = false
  311.                 end
  312.             else
  313.                 self.Components.Tracer.Visible = false
  314.             end
  315.         else
  316.             self.Components.Quad.Visible = false
  317.             self.Components.Distance.Visible = false
  318.             self.Components.Health.Visible = false
  319.             self.Components.Tool.Visible = false
  320.             self.Components.Name.Visible = false
  321.             self.Components.Tracer.Visible = false
  322.         end
  323. end
  324.  
  325. function ESP:Add(obj, options)
  326.     if not obj.Parent and not options.RenderInNil then
  327.         return warn(obj, "has no parent")
  328.     end
  329.  
  330.     local box = setmetatable({
  331.         Name = options.Name or obj.Name,
  332.         Type = "Box",
  333.         Color = options.Color --[[or self:GetColor(obj)]],
  334.         Size = options.Size or self.BoxSize,
  335.         Object = obj,
  336.         Player = options.Player or plrs:GetPlayerFromCharacter(obj),
  337.         PrimaryPart = options.PrimaryPart or obj.ClassName == "Model" and (obj.PrimaryPart or obj:FindFirstChild("HumanoidRootPart") or obj:FindFirstChildWhichIsA("BasePart")) or obj:IsA("BasePart") and obj,
  338.         Components = {},
  339.         IsEnabled = options.IsEnabled,
  340.         Temporary = options.Temporary,
  341.         ColorDynamic = options.ColorDynamic,
  342.         RenderInNil = options.RenderInNil
  343.     }, boxBase)
  344.  
  345.     if self:GetBox(obj) then
  346.         self:GetBox(obj):Remove()
  347.     end
  348.  
  349.     box.Components["Quad"] = Draw("Quad", {
  350.         Thickness = self.Thickness,
  351.         Color = color,
  352.         Transparency = 1,
  353.         Filled = false,
  354.         Visible = self.Enabled and self.Boxes
  355.     })
  356.     box.Components["Name"] = Draw("Text", {
  357.         Text = box.Name,
  358.         Color = box.Color,
  359.         Center = true,
  360.         Outline = true,
  361.         Size = 15,
  362.         Visible = self.Enabled and self.Names
  363.     })
  364.     box.Components["Distance"] = Draw("Text", {
  365.         Color = box.Color,
  366.         Center = true,
  367.         Outline = true,
  368.         Size = 15,
  369.         Visible = self.Enabled and self.Distance
  370.     })
  371.     box.Components["Health"] = Draw("Text", {
  372.         Color = box.Color,
  373.         Center = true,
  374.         Outline = true,
  375.         Size = 15,
  376.         Visible = self.Enabled and self.Health
  377.     })
  378.     box.Components["Tool"] = Draw("Text", {
  379.         Color = box.Color,
  380.         Center = true,
  381.         Outline = true,
  382.         Size = 15,
  383.         Visible = self.Enabled and self.Tool
  384.     })
  385.     box.Components["Tracer"] = Draw("Line", {
  386.         Thickness = ESP.Thickness,
  387.         Color = box.Color,
  388.         Transparency = 1,
  389.         Visible = self.Enabled and self.Tracers
  390.     })
  391.     self.Objects[obj] = box
  392.  
  393.     obj.AncestryChanged:Connect(function(_, parent)
  394.         if parent == nil and ESP.AutoRemove ~= false then
  395.             box:Remove()
  396.         end
  397.     end)
  398.     obj:GetPropertyChangedSignal("Parent"):Connect(function()
  399.         if obj.Parent == nil and ESP.AutoRemove ~= false then
  400.             box:Remove()
  401.         end
  402.     end)
  403.  
  404.     local hum = obj:FindFirstChildOfClass("Humanoid")
  405.     if hum then
  406.         hum.Died:Connect(function()
  407.             if ESP.AutoRemove ~= false then
  408.                 box:Remove()
  409.             end
  410.         end)
  411.     end
  412.  
  413.     return box
  414. end
  415.  
  416. local function CharAdded(char)
  417.     local p = plrs:GetPlayerFromCharacter(char)
  418.     if not char:FindFirstChild("HumanoidRootPart") then
  419.         local ev
  420.         ev = char.ChildAdded:Connect(function(c)
  421.             if c.Name == "HumanoidRootPart" then
  422.                 ev:Disconnect()
  423.                 ESP:Add(char, {
  424.                     Name = p.Name,
  425.                     Player = p,
  426.                     PrimaryPart = c
  427.                 })
  428.             end
  429.         end)
  430.     else
  431.         ESP:Add(char, {
  432.             Name = p.Name,
  433.             Player = p,
  434.             PrimaryPart = char.HumanoidRootPart
  435.         })
  436.     end
  437. end
  438. local function PlayerAdded(p)
  439.     p.CharacterAdded:Connect(CharAdded)
  440.     if p.Character then
  441.         coroutine.wrap(CharAdded)(p.Character)
  442.     end
  443. end
  444. plrs.PlayerAdded:Connect(PlayerAdded)
  445. for i,v in pairs(plrs:GetPlayers()) do
  446.     if v ~= plr then
  447.         PlayerAdded(v)
  448.     end
  449. end
  450.  
  451. game:GetService("RunService").RenderStepped:Connect(function()
  452.     cam = workspace.CurrentCamera
  453.     for i,v in (ESP.Enabled and pairs or ipairs)(ESP.Objects) do
  454.         if v.Update then
  455.             local s,e = pcall(v.Update, v)
  456.             if not s then warn("[EU]", e, v.Object:GetFullName()) end
  457.         end
  458.     end
  459. end)
  460.  
  461. return ESP
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement