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