Advertisement
DankGreenMoney

OPESP

May 17th, 2022
574
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- unload old esp (if it exists)
  2. if _G.unloadESP then _G.unloadESP(); end
  3.  
  4. local espConfig = {
  5.     -- Toggle
  6.     enabled = false,
  7.     -- ESP Elements
  8.     tracer = true,
  9.     headdot = true,
  10.     tag = true,
  11.     -- ESP Behaviour
  12.     locktocursor = false,
  13.     renderrange = 2000,
  14.     teamcheck = false,
  15.     -- ESP Color
  16.     rainbowcolor = false,
  17.     rainbowspeed = 2,
  18.     setcolor = {255, 255, 255},
  19.     teamcolor = true,
  20.     -- ESP offsets
  21.     xoffset = 1.6,
  22.     yoffsetaboveorigin = 2.5,
  23.     yoffsetbeloworigin = 3.5,
  24.     tagoffset = 8,
  25.     -- Headdot Settings
  26.     headdotfilled = false,
  27.     headdotscale = 2.5
  28. }
  29.  
  30. local isPhantom = (game.PlaceId == 292439477 and _G.getBodyparts and
  31. _G.getPlayerInstanceFromCharacter and _G.getCharacterFromPlayerInstance);
  32.  
  33. local isMM2 = (game.PlaceId == 142823291);
  34.  
  35. local drawESP;
  36. local espmem = {};
  37. local conmem = {};
  38.  
  39. ----------------------------------------------------------------------
  40. -- The reason that certain functions are stored in espConfig is because certain games may require specific modifications to functions
  41. -- This is so that I don't have to copy and paste the entire ESP module code for each game that requires minor changes
  42.  
  43. local function getVector3D(vector3)
  44.     local vector, onScreen = workspace.CurrentCamera:WorldToViewportPoint(vector3);
  45.     return {Vector2.new(vector.X, vector.Y), onScreen, vector.Z};
  46. end
  47.  
  48. espConfig.rainbowcs = nil;
  49. coroutine.wrap(function()
  50.     while wait() do
  51.         local i = 0;
  52.         repeat
  53.             i = i + (0.001 * espConfig.rainbowspeed);
  54.             espConfig.rainbowcs = Color3.fromHSV(i,1,1);  --creates a color using i
  55.             wait();
  56.         until i >= 1;
  57.     end
  58. end)();
  59.  
  60. local function getESPColor(playerinstance)
  61.     if not playerinstance then
  62.         return Color3.fromRGB(espConfig.setcolor[1], espConfig.setcolor[2], espConfig.setcolor[3])
  63.     end
  64.     if espConfig.rainbowcolor then
  65.         return espConfig.rainbowcs or Color3.fromRGB(espConfig.setcolor[1], espConfig.setcolor[2], espConfig.setcolor[3]);
  66.     elseif espConfig.teamcolor then
  67.         if isMM2 then
  68.             return (findMurder() == playerinstance and Color3.fromRGB(255, 0, 0))
  69.             or (findSheriff() == playerinstance and Color3.fromRGB(0, 0, 255))
  70.             or Color3.fromRGB(espConfig.setcolor[1], espConfig.setcolor[2], espConfig.setcolor[3])
  71.         else
  72.             return playerinstance.TeamColor.Color or Color3.fromRGB(espConfig.setcolor[1], espConfig.setcolor[2], espConfig.setcolor[3]) or Color3.fromRGB(255,255,255);
  73.         end
  74.     elseif espConfig.setcolor then
  75.         return Color3.fromRGB(espConfig.setcolor[1], espConfig.setcolor[2], espConfig.setcolor[3]);
  76.     end
  77. end
  78.  
  79. local function getTracerPoint()
  80.     if espConfig.locktocursor then
  81.         return Vector2.new(game.Players.LocalPlayer:GetMouse().X, game.Players.LocalPlayer:GetMouse().Y) + Vector2.new(0, 36);
  82.     else
  83.         return Vector2.new(workspace.CurrentCamera.ViewportSize.X/2, workspace.CurrentCamera.ViewportSize.Y);
  84.     end
  85. end
  86.  
  87. local function checkTeam(player)
  88.     if espConfig.teamcheck and player and player.Parent then
  89.         if isPhantom then
  90.             return _G.getPlayerInstanceFromCharacter(player).Team ~= game.Players.LocalPlayer.Team;
  91.         else
  92.             return game:GetService("Players"):FindFirstChild(player.Name).Team ~= game:GetService("Players").LocalPlayer.Team;
  93.         end
  94.     else
  95.         return true;
  96.     end
  97. end
  98.  
  99. drawESP = function(player)
  100.     if not player or not (isPhantom and player:FindFirstChild("Left Arm") or player:FindFirstChild("Humanoid")) then return end
  101.    
  102.     local cachedparent = player.Parent;
  103.  
  104.     -- Make ESP Drawings Mem container
  105.     espmem[player] = {};
  106.  
  107.     -- Tracer
  108.     espmem[player].Tracer = Drawing.new("Line");
  109.  
  110.     -- Box around Player Drawing
  111.     espmem[player].Up = Drawing.new("Line");
  112.     espmem[player].Down = Drawing.new("Line");
  113.     espmem[player].Left = Drawing.new("Line");
  114.     espmem[player].Right = Drawing.new("Line");
  115.  
  116.     -- Headdot
  117.     espmem[player].Headdot = Drawing.new("Circle");
  118.  
  119.     -- Texttag
  120.     espmem[player].Tag = Drawing.new("Text");  -- Name
  121.  
  122.     -- Start Updating ESP
  123.     spawn(function()
  124.  
  125.         local renderESPConnection = Instance.new("BindableEvent");
  126.         coroutine.wrap(function()
  127.             while game:GetService("RunService").RenderStepped:Wait() do
  128.                 renderESPConnection:Fire();
  129.             end
  130.         end)()
  131.  
  132.         conmem[player] = renderESPConnection.Event:Connect(function()
  133.             if not (isPhantom and player:FindFirstChild("Left Arm") or player:FindFirstChild("Head")) then return end;
  134.  
  135.             -- Initiate Variables
  136.             local point = getVector3D(player.Head.Position)[1];
  137.             local espColor = getESPColor(isPhantom and _G.getPlayerInstanceFromCharacter(player) or game:GetService("Players"):FindFirstChild(player.Name));
  138.  
  139.             -- Tracer
  140.             if getVector3D(player.Head.Position)[2] and espConfig.enabled and espConfig.tracer and espConfig.renderrange > getVector3D(player.Head.Position)[3] and checkTeam(player) and espmem[player].Tracer then
  141.                 local tracer = espmem[player].Tracer; if not tracer then return end;
  142.                 tracer.Thickness = 1;
  143.                 tracer.From = getTracerPoint();
  144.                 tracer.To = point;
  145.                 tracer.Color = espColor;
  146.                 tracer.Visible = true;
  147.             elseif espmem[player].Tracer then
  148.                 if not pcall(function()
  149.                     espmem[player].Tracer.Visible = false;
  150.                 end) then
  151.                     conmem[player]:Disconnect();
  152.                 end
  153.             else
  154.                 conmem[player]:Disconnect();
  155.             end
  156.  
  157.             -- ESP Box
  158.             local espBoxOriginCFrame;
  159.             if player:FindFirstChild("Torso") and player.Torso:IsA("BasePart") then espBoxOriginCFrame = player.Torso.CFrame:ToWorldSpace();
  160.             elseif player:FindFirstChild("LowerTorso") and player.LowerTorso:IsA("BasePart")
  161.                 and player:FindFirstChild("UpperTorso") and player.UpperTorso:IsA("BasePart") then
  162.                 espBoxOriginCFrame = CFrame.new(((player:FindFirstChild("LowerTorso").Position) + (player:FindFirstChild("UpperTorso").Position)) / 2):ToWorldSpace();
  163.             elseif player:FindFirstChild("Head") then espBoxOriginCFrame = player:FindFirstChild("Head").CFrame:ToWorldSpace();
  164.             else
  165.                 espBoxOriginCFrame = player:FindFirstChild("HumanoidRootPart").CFrame:ToWorldSpace();
  166.             end
  167.  
  168.             -- Calculate CFrame
  169.             -- Variables stand for the corresponding box corner - tl = top left
  170.             local tl = espBoxOriginCFrame * CFrame.new(-(espConfig.xoffset), espConfig.yoffsetaboveorigin, 0);
  171.             local tr = espBoxOriginCFrame * CFrame.new(espConfig.xoffset, espConfig.yoffsetaboveorigin, 0);
  172.             local bl = espBoxOriginCFrame * CFrame.new(-(espConfig.xoffset), -(espConfig.yoffsetbeloworigin), 0);
  173.             local br = espBoxOriginCFrame * CFrame.new(espConfig.xoffset, -(espConfig.yoffsetbeloworigin), 0);
  174.        
  175.             if getVector3D(player.Head.Position)[2] and espConfig.enabled and espConfig.renderrange > getVector3D(player.Head.Position)[3] and checkTeam(player) and espmem[player].Up and espmem[player].Down and espmem[player].Right and espmem[player].Left then
  176.  
  177.                 -- Top Line
  178.                 espmem[player].Up.From = getVector3D(tl.p)[1];
  179.                 espmem[player].Up.To = getVector3D(tr.p)[1];
  180.                 espmem[player].Up.Thickness = 1;
  181.                 espmem[player].Up.Color = espColor;
  182.  
  183.                 -- Left Line
  184.                 espmem[player].Left.From = getVector3D(tl.p)[1];
  185.                 espmem[player].Left.To = getVector3D(bl.p)[1];
  186.                 espmem[player].Left.Thickness = 1;
  187.                 espmem[player].Left.Color = espColor;
  188.  
  189.                 -- Right Line
  190.                 espmem[player].Right.From = getVector3D(tr.p)[1];
  191.                 espmem[player].Right.To = getVector3D(br.p)[1];
  192.                 espmem[player].Right.Thickness = 1;
  193.                 espmem[player].Right.Color = espColor;
  194.  
  195.                 -- Bottom Line
  196.                 espmem[player].Down.From = getVector3D(bl.p)[1];
  197.                 espmem[player].Down.To = getVector3D(br.p)[1];
  198.                 espmem[player].Down.Thickness = 1;
  199.                 espmem[player].Down.Color = espColor;
  200.  
  201.                 espmem[player].Down.Visible = true;
  202.                 espmem[player].Right.Visible = true;
  203.                 espmem[player].Left.Visible = true;
  204.                 espmem[player].Up.Visible = true;
  205.                
  206.             elseif espmem[player].Up and espmem[player].Down and espmem[player].Right and espmem[player].Left then
  207.                 if not pcall(function()
  208.                     espmem[player].Down.Visible = false;
  209.                     espmem[player].Right.Visible = false;
  210.                     espmem[player].Left.Visible = false;
  211.                     espmem[player].Up.Visible = false;
  212.                 end) then
  213.                     conmem[player]:Disconnect();
  214.                 end
  215.             else
  216.                 conmem[player]:Disconnect();
  217.             end
  218.  
  219.             -- Head Dot
  220.             if getVector3D(player.Head.Position)[2] and espConfig.enabled and espConfig.headdot and espConfig.renderrange > getVector3D(player.Head.Position)[3] and checkTeam(player) and espmem[player].Headdot then
  221.                 espmem[player].Headdot.Position = point;
  222.                 espmem[player].Headdot.Filled = espConfig.headdotfilled;
  223.                 espmem[player].Headdot.Color = espColor;
  224.                 espmem[player].Headdot.NumSides = 15;
  225.                 espmem[player].Headdot.Thickness = 1;
  226.  
  227.                 -- Head dot radius
  228.                 local Scale = player.Head.Size.Y / espConfig.headdotscale;
  229.                 local Top = workspace.CurrentCamera:WorldToViewportPoint((player.Head.CFrame * CFrame.new(0, Scale, 0)).Position);
  230.                 local Bottom = workspace.CurrentCamera:WorldToViewportPoint((player.Head.CFrame * CFrame.new(0, -Scale, 0)).Position);
  231.  
  232.                 -- Synapse gets absolute value by default but exploits like KRNL and Scriptware don't
  233.                 -- Causing the circle to not be rendered if radius is a negative value (which makes sense)
  234.                 espmem[player].Headdot.Radius = math.abs((Top - Bottom).y);
  235.  
  236.                 espmem[player].Headdot.Visible = true;
  237.             elseif espmem[player].Headdot then
  238.                 if not pcall(function()
  239.                     espmem[player].Headdot.Visible = false;
  240.                 end) then
  241.                     conmem[player]:Disconnect();
  242.                 end
  243.             else
  244.                 conmem[player]:Disconnect();
  245.             end
  246.            
  247.             -- Tag
  248.        
  249.             if getVector3D(player.Head.Position)[2] and espConfig.enabled and espConfig.tag and espConfig.renderrange > getVector3D(player.Head.Position)[3] and checkTeam(player) and espmem[player].Tag then
  250.  
  251.                 local ScreenPositionUpper;
  252.                 if isPhantom then
  253.                     ScreenPositionUpper = workspace.CurrentCamera:WorldToViewportPoint((player.Torso:GetRenderCFrame() * CFrame.new(0, player.Head.Size.Y + player.Torso.Size.Y + (espConfig.tagoffset - 200 / 25), 0)).Position);
  254.                 else
  255.                     ScreenPositionUpper = workspace.CurrentCamera:WorldToViewportPoint((player.HumanoidRootPart:GetRenderCFrame() * CFrame.new(0, player.Head.Size.Y + player.HumanoidRootPart.Size.Y + (espConfig.tagoffset - 200 / 25), 0)).Position);
  256.                 end
  257.  
  258.                 if espmem[player].Tag.Font and Drawing and Drawing.Fonts then
  259.                     espmem[player].Tag.Font = Drawing.Fonts.Monospace;
  260.                 end
  261.  
  262.                 espmem[player].Tag.Visible = true;
  263.                 espmem[player].Tag.Center = true;
  264.                 espmem[player].Tag.Color = espColor;
  265.                 espmem[player].Tag.Outline = true;
  266.                 espmem[player].Tag.Position = Vector2.new(ScreenPositionUpper.X, ScreenPositionUpper.Y) - Vector2.new(0, espmem[player].Tag.TextBounds.Y);
  267.                
  268.                 playerName = isPhantom and _G.getPlayerInstanceFromCharacter(player).Name or player.Name;
  269.                 espmem[player].Tag.Text = (playerName or "Unknown").." | ["..math.floor(getVector3D(player.Head.Position)[3]).."]";
  270.                
  271.             elseif espmem[player].Tag then
  272.                 if not pcall(function()
  273.                     espmem[player].Tag.Visible = false;
  274.                 end) then
  275.                     conmem[player]:Disconnect();
  276.                 end
  277.             else
  278.                 conmem[player]:Disconnect();
  279.             end
  280.  
  281.         end)
  282.  
  283.         -- Wait until player character is dead/leaves ect
  284.         while game:GetService("RunService").RenderStepped:Wait() do
  285.            
  286.             if not player
  287.             or not (isPhantom and player:FindFirstChild("Left Arm") or player:FindFirstChild("HumanoidRootPart"))
  288.             or player.Parent ~= cachedparent or not player:IsDescendantOf(workspace)
  289.             or (not isPhantom and player.Humanoid.Health == 0)
  290.             or not espmem[player] then break end
  291.  
  292.         end
  293.  
  294.         pcall(function() conmem[player]:Disconnect() end)
  295.         for _,v in pairs(espmem[player]) do
  296.             if v then pcall(function() v:Remove() end) end
  297.         end
  298.         espmem[player] = nil;
  299.  
  300.     end)
  301.  
  302. end
  303.  
  304. ----------------------------------------------------------------------
  305.  
  306. if not isPhantom then
  307.     for _, player in pairs(game:GetService("Players"):GetPlayers()) do
  308.         if player.Name ~= game.Players.LocalPlayer.Name then
  309.             drawESP(player.Character);
  310.             player.CharacterAdded:Connect(function()
  311.                 delay(0.5, function()
  312.                     drawESP(player.Character);
  313.                 end)
  314.             end)
  315.         end
  316.     end
  317.  
  318.     game:GetService("Players").PlayerAdded:Connect(function(player)
  319.         player.CharacterAdded:Connect(function()
  320.             delay(0.5, function()
  321.                 drawESP(player.Character);
  322.             end)
  323.         end)
  324.     end)
  325. else
  326.     for _, player in pairs(workspace.Players:GetDescendants()) do
  327.         if player.Name == "Player" then
  328.             if _G.getPlayerInstanceFromCharacter(player)
  329.             and _G.getPlayerInstanceFromCharacter(player).Name ~= game:GetService("Players").LocalPlayer.Name then
  330.                 delay(0.5, function()
  331.                     drawESP(player);
  332.                 end)
  333.             end
  334.         end
  335.     end
  336.  
  337.     workspace.Players.DescendantAdded:Connect(function(Player)
  338.         if Player.Name == "Player" and Player:FindFirstChild("Left Arm") and _G.getPlayerInstanceFromCharacter(Player)
  339.         and _G.getPlayerInstanceFromCharacter(Player).Name ~= game:GetService("Players").LocalPlayer.Name then
  340.             delay(0.5, function()
  341.                 drawESP(Player);
  342.             end)
  343.         end
  344.     end)
  345. end
  346.  
  347. ----------------------------------------------------------------------
  348.  
  349. _G.change = function(p, v)
  350.     espConfig[p] = v;
  351. end
  352.  
  353. _G.unloadESP = function()
  354.     drawESP = function() return; end
  355.     for i,v in pairs(conmem) do
  356.         v:Disconnect();
  357.     end
  358.     for i,v in pairs(espmem) do
  359.         if type(v) == "table" then
  360.             for ii, vv in pairs(v) do
  361.                 if vv then pcall(function() vv:Remove() end) end
  362.             end
  363.         end
  364.     end
  365. end
  366.  
  367. return espConfig;
Advertisement
RAW Paste Data Copied
Advertisement