Advertisement
TheDevastation

bonk

Sep 26th, 2022
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.04 KB | None | 0 0
  1. local RunService = game:GetService("RunService")
  2. local Players = game:GetService("Players")
  3.  
  4. -- Cache
  5. local LocalPlayer = Players.LocalPlayer
  6. local Mouse = LocalPlayer:GetMouse()
  7. local CurrentCamera = workspace.CurrentCamera
  8.  
  9. -- Variables
  10. local FindFirstChild = game.FindFirstChild
  11. local Color3New = Color3.new
  12. local Vector2New = Vector2.new
  13. local DrawingNew = Drawing.new
  14. local Round = math.round
  15. local Tan = math.tan
  16. local Random = math.random
  17. local Rad = math.rad
  18. local FindPartOnRayWithIgnoreList = workspace.FindPartOnRayWithIgnoreList
  19. local CameraWorldToViewportPoint = CurrentCamera.WorldToViewportPoint
  20. local UnbindFromRenderStep = RunService.UnbindFromRenderStep
  21.  
  22. -- Module
  23. local Library = {
  24.     Cache = {},
  25.     Drawings = {},
  26.     Options = {
  27.         Enabled = false,
  28.         VisibleOnly = false,
  29.         Names = false,
  30.         Boxes = false,
  31.         BoxFill = false,
  32.         Healthbars = false,
  33.         HealthbarSize = 1,
  34.         Distance = false,
  35.         Tracers = false,
  36.         WidthInStuds = 4,
  37.         HeightInStuds = 5,
  38.     },
  39.     Colors = {
  40.         Names = Color3New(1, 1, 1),
  41.         Boxes = Color3New(1, 1, 1),
  42.         BoxFill = Color3New(1, 1, 1),
  43.         Healthbars = Color3New(0, 1, 0),
  44.         Distance = Color3New(1, 1, 1),
  45.         Tracers = Color3New(1, 1, 1),
  46.     }
  47. }
  48.  
  49. local function Create(Class, Properties)
  50.     local Object = DrawingNew(Class)
  51.  
  52.     for Property, Value in pairs(Properties) do
  53.         Object[Property] = Value
  54.     end
  55.  
  56.     table.insert(Library.Drawings, Object)
  57.     return Object
  58. end
  59.  
  60. local function RoundVec(Vector)
  61.     return Vector2New(Round(Vector.X), Round(Vector.Y))
  62. end
  63.  
  64. local function WorldToViewportPoint(Position)
  65.     local ScreenPos, OnScreen = CameraWorldToViewportPoint(CurrentCamera, Position)
  66.     return Vector2New(ScreenPos.X, ScreenPos.Y), OnScreen, ScreenPos.Z
  67. end
  68.  
  69. function Library.GetTeam(Player)
  70.     return Player.Team
  71. end
  72.  
  73. function Library.GetCharacter(Player)
  74.     local Character = Player.Character
  75.     return Character, Character and FindFirstChild(Character, "HumanoidRootPart")
  76. end
  77.  
  78. function Library.VisibleCheck(Origin, Target, Character)
  79.     local Part = FindPartOnRayWithIgnoreList(workspace, Ray.new(Origin, Target - Origin), { CurrentCamera, LocalPlayer.Character, Character }, false, true)
  80.     return Part == nil
  81. end
  82.  
  83. function Library.GetHealth(Character)
  84.     local Humanoid = FindFirstChild(Character, "Humanoid")
  85.     return Humanoid.Health, Humanoid.MaxHealth
  86. end
  87.  
  88. function Library.AddEsp(Player)
  89.     if (Player == LocalPlayer) then
  90.         return
  91.     end
  92.  
  93.     local Id = Random(-100000, 999999)
  94.  
  95.     local Objects = {
  96.         Name = Create("Text", {
  97.             Text = Player.Name,
  98.             Size = 13,
  99.             Center = true,
  100.             Outline = true,
  101.             OutlineColor = Color3New(),
  102.             Font = 2,
  103.             ZIndex = Id + 10
  104.         }),
  105.         Box = Create("Square", {
  106.             Thickness = 1,
  107.             ZIndex = Id + 9,
  108.         }),
  109.         BoxOutline = Create("Square", {
  110.             Thickness = 3,
  111.             Color = Color3New(),
  112.             ZIndex = Id + 8
  113.         }),
  114.         BoxFill = Create("Square", {
  115.             Thickness = 1,
  116.             Transparency = 0.5,
  117.             ZIndex = Id + 7,
  118.             Filled = true,
  119.         }),
  120.         Healthbar = Create("Square", {
  121.             Thickness = 1,
  122.             Filled = true,
  123.             ZIndex = Id + 6,
  124.         }),
  125.         HealthbarOutline = Create("Square", {
  126.             Thickness = 3,
  127.             Filled = true,
  128.             Color = Color3New(),
  129.             ZIndex = Id + 5
  130.         }),
  131.         Distance = Create("Text", {
  132.             Size = 13,
  133.             Center = true,
  134.             Outline = true,
  135.             OutlineColor = Color3New(),
  136.             Font = 2,
  137.             ZIndex = Id + 4
  138.         }),
  139.         Tracer = Create("Line", {
  140.             Thickness = 1,
  141.             ZIndex = Id + 3
  142.         })
  143.     }
  144.  
  145.     Library.Cache[Player] = Objects
  146. end
  147.  
  148. function Library.RemoveEsp(Player)
  149.     local Data = Library.Cache[Player]
  150.  
  151.     if (Data) then
  152.         Library.Cache[Player] = nil
  153.  
  154.         for i,v in pairs(Data) do
  155.             v:Remove()
  156.         end
  157.     end
  158. end
  159.  
  160. function Library.Unload()
  161.     UnbindFromRenderStep(RunService, "Esp Loop")
  162.  
  163.     for _, Player in pairs(Players:GetPlayers()) do
  164.         Library.RemoveEsp(Player)
  165.     end
  166.  
  167.     for _, Object in pairs(Library.Drawings) do
  168.         Object:Destroy()
  169.     end
  170. end
  171.  
  172. function Library.Init()
  173.     Players.PlayerAdded:Connect(function(Player)
  174.         Library.AddEsp(Player)
  175.     end)
  176.  
  177.     Players.PlayerRemoving:Connect(function(Player)
  178.         Library.RemoveEsp(Player)
  179.     end)
  180.  
  181.     RunService.BindToRenderStep(RunService, "Esp Loop", 1, function()
  182.         for Player, Objects in pairs(Library.Cache) do
  183.             if (Player ~= LocalPlayer and Library.GetTeam(Player) ~= Library.GetTeam(LocalPlayer)) then
  184.                 local Character, Torso = Library.GetCharacter(Player)
  185.  
  186.                 if (Character and Torso) then
  187.                     local TorsoPosition, OnScreen, Depth = WorldToViewportPoint(Torso.Position)
  188.  
  189.                     if (Library.Options.VisibleOnly and Library.VisibleCheck(CurrentCamera.CFrame.p, Torso.Position)) then
  190.                         OnScreen = false
  191.                     end
  192.  
  193.                     if (OnScreen and Library.Options.Enabled) then
  194.                         local ScaleFactor = 1 / (Tan(Rad(CurrentCamera.FieldOfView / 2)) * 2 * Depth) * 1000
  195.                         local Width, Height = Round(Library.Options.WidthInStuds * ScaleFactor), Round(Library.Options.HeightInStuds * ScaleFactor)
  196.                         local X, Y = Round(TorsoPosition.X), Round(TorsoPosition.Y)
  197.                         local BoxPosition = RoundVec(Vector2New(X - Width / 2, Y - Height / 2))
  198.                         local BoxSize = Vector2New(Width, Height)
  199.                         local Health, MaxHealth = Library.GetHealth(Character)
  200.                         local HealthbarPosition = RoundVec(Vector2New(BoxPosition.X - (3 + Library.Options.HealthbarSize), BoxPosition.Y + BoxSize.Y))
  201.                         local HealthbarSize = RoundVec(Vector2New(Library.Options.HealthbarSize, -BoxSize.Y))
  202.                         local Magnitude = Round((CurrentCamera.CFrame.Position - Torso.Position).Magnitude)
  203.  
  204.                         Objects.Name.Visible = Library.Options.Names
  205.                         Objects.Name.Color = Library.Colors.Names
  206.                         Objects.Name.Position = Vector2New(X, BoxPosition.Y - 15)
  207.  
  208.                         Objects.Box.Visible = Library.Options.Boxes
  209.                         Objects.Box.Color = Library.Colors.Boxes
  210.                         Objects.Box.Position = BoxPosition
  211.                         Objects.Box.Size = BoxSize
  212.  
  213.                         Objects.BoxOutline.Visible = Library.Options.Boxes
  214.                         Objects.BoxOutline.Position = BoxPosition
  215.                         Objects.BoxOutline.Size = BoxSize
  216.  
  217.                         Objects.BoxFill.Visible = Library.Options.BoxFill
  218.                         Objects.BoxFill.Color = Library.Colors.BoxFill
  219.                         Objects.BoxFill.Position = BoxPosition
  220.                         Objects.BoxFill.Size = BoxSize
  221.  
  222.                         Objects.Healthbar.Visible = Library.Options.Healthbars
  223.                         Objects.Healthbar.Color = Library.Colors.Healthbars
  224.                         Objects.Healthbar.Position = HealthbarPosition
  225.                         Objects.Healthbar.Size = RoundVec(Vector2New(HealthbarSize.X, HealthbarSize.Y * (Health / MaxHealth)))
  226.  
  227.                         Objects.HealthbarOutline.Visible = Library.Options.Healthbars
  228.                         Objects.HealthbarOutline.Position = HealthbarPosition - Vector2New(1, -1)
  229.                         Objects.HealthbarOutline.Size = HealthbarSize + Vector2New(2, -2)
  230.  
  231.                         Objects.Distance.Visible = Library.Options.Distance
  232.                         Objects.Distance.Color = Library.Colors.Distance
  233.                         Objects.Distance.Text = Magnitude .. " Studs"
  234.                         Objects.Distance.Position = Vector2New(X, (BoxPosition.Y + BoxSize.Y) + 3)
  235.  
  236.                         Objects.Tracer.Visible = Library.Options.Tracers
  237.                         Objects.Tracer.Color = Library.Colors.Tracers
  238.                         Objects.Tracer.From = Vector2New(Mouse.X, Mouse.Y + 36)
  239.                         Objects.Tracer.To = Vector2New(X, Y)
  240.                     else
  241.                         for i,v in pairs(Objects) do
  242.                             v.Visible = false
  243.                         end
  244.                     end
  245.                 else
  246.                     for i,v in pairs(Objects) do
  247.                         v.Visible = false
  248.                     end
  249.                 end
  250.             else
  251.                 for i,v in pairs(Objects) do
  252.                     v.Visible = false
  253.                 end
  254.             end
  255.         end
  256.     end)
  257.  
  258.     for i,v in pairs(Players:GetPlayers()) do
  259.         Library.AddEsp(v)
  260.     end
  261. end
  262.  
  263. return Library
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement