Advertisement
Vzurxy

ic3's drawing api

Dec 19th, 2019
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.39 KB | None | 0 0
  1. if not shared.__BIGCACHE then
  2.     shared.__BIGCACHE = {};
  3. end
  4.  
  5. shared.ckill = false;
  6.  
  7. local Players = game:GetService'Players';
  8. local LocalPlayer = Players.LocalPlayer;
  9. local Mouse = LocalPlayer:GetMouse();
  10. local Camera = workspace.CurrentCamera;
  11. local RunService = game:GetService'RunService';
  12.  
  13. RunService:UnbindFromRenderStep'RLESP';
  14.  
  15. local RefreshRate = 60; RefreshRate = 1 / RefreshRate;
  16.  
  17. local Colors = {
  18.     White           = Color3.new(1, 1, 1);
  19.     Black           = Color3.new(0.12, 0.12, 0.12);
  20.     ReallyBlack     = Color3.new(0, 0, 0);
  21.     Red             = Color3.new(1, 0, 0);
  22.     Green           = Color3.new(0, 1, 0);
  23.     Blue            = Color3.new(0, 0, 1);
  24.     Scroll          = Color3.fromRGB(255, 151, 41);
  25.     ScrollOutline   = Color3.fromRGB(25, 20, 30);
  26.     Trinket         = Color3.fromRGB(81, 117, 255);
  27.     TrinketOutline  = Color3.fromRGB(25, 25, 25);
  28.     Gem             = Color3.fromRGB(205, 46, 255);
  29.     HotPink         = Color3.fromRGB(255, 0, 255);
  30.     Ice             = Color3.fromRGB(70, 255, 255);
  31.     Shroom          = Color3.fromRGB(100, 220, 25);
  32.     Crimson         = Color3.fromRGB(220, 50, 50);
  33.     PD              = Color3.fromRGB(255, 120, 0);
  34.     Diamond         = Color3.fromRGB(255, 255, 255);
  35.     Ruby            = Color3.fromRGB(255, 25, 75);
  36.     Emerald         = Color3.fromRGB(50, 220, 50);
  37.     Sapphire        = Color3.fromRGB(25, 75, 255);
  38.     RoyalPurple     = BrickColor.new'Royal purple'.Color;
  39. }
  40.  
  41. shared.__Colors = Colors;
  42.  
  43. local Updates = setmetatable({}, {
  44.     __index = function(t, i)
  45.         return rawget(t, i) and rawget(t, i) or 0;
  46.     end;
  47. });
  48.  
  49. shared.RLDrawings = shared.RLDrawings or {
  50.     ObjectsToDraw = setmetatable({
  51.         Tables = {};
  52.         Cap = 150;
  53.     }, {
  54.         __index = function(self, i)
  55.             return rawget(self.Tables, i) or rawget(self, i);
  56.         end;
  57.  
  58.         __newindex = function(self, i, v)
  59.             local current = self.Tables[#self.Tables];
  60.            
  61.             if typeof(current) ~= 'table' or #current > self.Cap then
  62.                 current = {};
  63.                 table.insert(self.Tables, current);
  64.             end
  65.  
  66.             current[i] = v;
  67.         end
  68.     });
  69.     Cache = {};
  70.     ScreenPositionCache = {};
  71.     Enabled = true;
  72. };
  73.  
  74. local function IsStringEmpty(String)
  75.     if type(String) == 'string' then
  76.         return String:match'^%s+$' ~= nil or #String == 0 or String == '' or false;
  77.     end
  78.     return false
  79. end
  80.  
  81. local function Set(t, i, v)
  82.     t[i] = v;
  83. end
  84.  
  85. function GetIndex(T, V)
  86.     for i, v in pairs(T) do
  87.         if v == V then
  88.             return i;
  89.         end
  90.     end
  91.  
  92.     return -1;
  93. end
  94.  
  95. local DefaultPropties = {
  96.     Line = {
  97.         Visible         = false;
  98.         Color           = Color3.new(1, 1, 1);
  99.         Transparency    = 1;
  100.         Thickness       = 1;
  101.     };
  102.     Square = {
  103.         Size            = Vector2.new(100, 100);
  104.         Position        = Vector2.new(250, 100);
  105.         Filled          = false;
  106.         Color           = Color3.new(1, 1, 1);
  107.         Thickness       = 2;
  108.         Visible         = true;
  109.     };
  110.     Text = {
  111.         Size            = 16;
  112.         Position        = Vector2.new(25, 15);
  113.         Text            = 'undefined';
  114.         Color           = Color3.new(1, 1, 1);
  115.         Visible         = true;
  116.         Center          = true;
  117.         Outline         = true;
  118.         OutlineColor    = Colors.Black;
  119.     };
  120.     Circle = {
  121.         Radius          = 10;
  122.         Position        = Vector2.new(25, 25);
  123.         Color           = Color3.new(1, 1, 1);
  124.         Filled          = true;
  125.         Visible         = true;
  126.     };
  127. };
  128.  
  129. function SetDefaultProperties(Drawing)
  130.     local Type = getmetatable(Drawing).__type;
  131.  
  132.     if DefaultPropties[Type] then
  133.         for i, v in pairs(DefaultPropties[Type]) do
  134.             pcall(Set, Drawing, i, v);
  135.         end
  136.     end
  137. end
  138.  
  139. local function False() return false; end
  140.  
  141. function shared.RLDrawings:GetInstanceName(Instance, Name)
  142.     if Instance == nil or typeof(Instance) ~= 'Instance' then
  143.         return false;
  144.     end
  145.  
  146.     return string.format('%s-%s', Instance:GetDebugId(), Name);
  147. end
  148.  
  149. function shared.RLDrawings:DrawingExists(Instance, Name)
  150.     local CachedName = self:GetInstanceName(Instance, Name);
  151.     return self.Cache[CachedName] ~= nil;
  152. end
  153.  
  154. function shared.RLDrawings:CreateDrawing(Type, Instance, Name)
  155.     if not self:DrawingExists(Instance, Name) then
  156.         local CachedName = self:GetInstanceName(Instance, Name);
  157.  
  158.         local Drawing = Drawing.new(Type);
  159.         table.insert(shared.__BIGCACHE, Drawing);
  160.        
  161.         SetDefaultProperties(Drawing);
  162.  
  163.         self.Cache[CachedName] = {
  164.             LastUpdate = 0;
  165.             Instance = Instance;
  166.             Drawing = Drawing;
  167.         };
  168.  
  169.         return Drawing;
  170.     else
  171.         return false, 'drawing already exists';
  172.     end
  173. end
  174.  
  175. function shared.RLDrawings:GetDrawing(Instance, Name)
  176.     if self:DrawingExists(Instance, Name) then
  177.         local CachedName = self:GetInstanceName(Instance, Name);
  178.         local Drawing = nil;
  179.         local Cache = self.Cache[CachedName];
  180.  
  181.         self.Cache[CachedName].LastUpdate = tick();
  182.  
  183.         if Cache.Drawing then
  184.             Drawing = Cache.Drawing
  185.         else
  186.             return False;
  187.         end
  188.  
  189.         return function(func)
  190.             if typeof(func) == 'function' then
  191.                 func(Drawing);
  192.             else
  193.                 return Drawing;
  194.             end
  195.         end;
  196.     end
  197.  
  198.     return False
  199. end
  200.  
  201. function shared.RLDrawings:RemoveDrawing(Instance, Name)
  202.     if self:DrawingExists(Instance, Name) then
  203.         self:GetDrawing(Instance, Name)(function(Drawing)
  204.             local CachedName = self:GetInstanceName(Instance, Name);
  205.            
  206.             Drawing.Visible = false;
  207.             Drawing:Remove();
  208.             self.Cache[CachedName] = nil;
  209.         end);
  210.     end    
  211. end
  212.  
  213. function shared.RLDrawings:CheckForInvalidDrawings()
  214.     for i, v in pairs(self.Cache) do
  215.         if i == nil or typeof(v) ~= 'table' or v.Instance == nil or not v.Instance:IsDescendantOf(workspace) or (tick() - v.LastUpdate) > 10 then
  216.             -- i == nil or typeof(v) ~= 'table' or v.Instance == nil or (v.Instance.Parent ~= workspace and not v.Instance:IsDescendantOf(workspace)) or (tick() - v.LastUpdate) > 1 or not v.Instance:IsDescendantOf(workspace)
  217.             -- print('1',i==nil)
  218.             -- print('2',i.Parent==nil)
  219.             -- print('3',v.Instance==nil)
  220.             -- print('4',v.Instance.Parent~=workspace)
  221.             -- print('5',tick() - v.LastUpdate > 1)
  222.             -- print('6',v.Instance:IsDescendantOf(workspace));
  223.             -- print('removing', v.Instance:GetDebugId());
  224.             -- print()
  225.             v.Drawing.Visible = false;
  226.             v.Drawing:Remove();
  227.             self.Cache[i] = nil;
  228.             self:RemoveObject(v.Instance);
  229.         end
  230.     end
  231. end
  232.  
  233. function shared.RLDrawings:Cleanup()
  234.     for i, v in pairs(self.Cache) do
  235.         if i.Parent == nil or not i:IsDescendantOf(workspace) or (tick() - v.LastUpdate) > 1 / 3 then
  236.             v.Drawing.Visible = false;
  237.             v.Drawing:Remove();
  238.             self.Cache[i] = nil;
  239.         end
  240.     end
  241. end
  242.  
  243. -- local t = nil;
  244.  
  245. function shared.RLDrawings:GetScreenPosition(Instance)
  246.     -- if Instance.ClassName ~= 'Part' and Instance.ClassName ~= 'UnionOperation' and not Instance:IsA'BasePart' then
  247.     --     -- print(Instance.ClassName ~= 'Part', Instance.ClassName ~= 'UnionOperation', Instance:IsA'BasePart');
  248.     --     return false;
  249.     -- end
  250.  
  251.     local Unit = (Instance.Position - Camera.CFrame.p).unit;
  252.     local Dot = Camera.CFrame.lookVector:Dot(Unit);
  253.  
  254.     if Dot > 1.000001 then
  255.         return false;
  256.     end
  257.  
  258.     if self.ScreenPositionCache[Instance] == nil then
  259.         self.ScreenPositionCache[Instance] = {
  260.             LastUpdate = tick() + 1;
  261.             ScreenPosition = Vector2.new();
  262.         };
  263.     end
  264.  
  265.     local Cache = self.ScreenPositionCache[Instance];
  266.  
  267.     if (tick() - Cache.LastUpdate) > RefreshRate then
  268.         -- local t = t or Instance;
  269.  
  270.         -- if Instance == t then
  271.         --     print(Instance:GetFullName(), tick(), tick() - Cache.LastUpdate, tableToString(debug.getlocals(2)));
  272.         -- end
  273.  
  274.         local Position, _V = Camera:WorldToViewportPoint(Instance.Position);
  275.  
  276.         Cache.LastUpdate = tick();
  277.         Cache.ScreenPosition = Vector2.new(Position.X, Position.Y);
  278.         Cache.Depth = Position.Z;
  279.         Cache.Distance = (Camera.CFrame.p - Instance.Position).magnitude;
  280.         -- tonumber(string.format('%.1f', (Camera.CFrame.p - Instance.Position).magnitude));
  281.         Cache.Visible = _V;
  282.         Cache.OVisible = Position.Z > 0;
  283.     end
  284.  
  285.     self.ScreenPositionCache[Instance] = Cache;
  286.  
  287.     return Cache;
  288. end
  289.  
  290. function shared.RLDrawings:AddObject(Instance, Text, Color, DrawDistance, DrawTracer, DrawCircle)
  291.     if typeof(Instance) ~= 'Instance' and not Instance:IsA'BasePart' then return false; end
  292.  
  293.     local Table = {
  294.         Instance = Instance;
  295.         Text = IsStringEmpty(Text) and nil or Text;
  296.         Color = Color or Colors.White;
  297.         DrawTracer = DrawTracer;
  298.         DrawCircle = DrawCircle;
  299.         DrawDistance = DrawDistance;
  300.     };
  301.  
  302.     self.ObjectsToDraw[Instance] = Table;
  303.  
  304.     return Table;
  305. end
  306.  
  307. function shared.RLDrawings:RemoveObject(Instance)
  308.     self.ObjectsToDraw[Instance] = nil;
  309. end
  310.  
  311. function DrawObjectText(Instance, DisplayText, DisplayColor, ShowDistance)
  312.     local TextObject = shared.RLDrawings:GetDrawing(Instance, 'NameTag')() or shared.RLDrawings:CreateDrawing('Text', Instance, 'NameTag');
  313.  
  314.     local Position, Visible = shared.RLDrawings:GetScreenPosition(Instance);
  315.  
  316.     -- print(Position);
  317.    
  318.     if Position and Position.Visible and Position.Distance < 25000 then
  319.         if ShowDistance then
  320.             DisplayText = DisplayText .. '\n' .. tostring(Position.Distance):match'%d+.[%d]?';
  321.             -- string.format('%s\n[%s]', DisplayText, tostring(Position.Distance):match'%d+.[%d]?');
  322.         end
  323.  
  324.         TextObject.Visible = true;
  325.         TextObject.Size = 17;
  326.         TextObject.Text = DisplayText or 'undefined';
  327.         TextObject.Color = DisplayColor or Colors.White;
  328.         TextObject.Position = Position.ScreenPosition;
  329.         TextObject.Outline = true;
  330.        
  331.         if syn then
  332.             TextObject.OutlineColor = Color3.fromRGB(45, 45, 45);
  333.             TextObject.Font = Drawing.Fonts.Plex;
  334.         end
  335.     else
  336.         TextObject.Visible = false;
  337.     end
  338. end
  339.  
  340. function DrawObjectTracer(Instance, DisplayColor)
  341.     local LineObject = shared.RLDrawings:GetDrawing(Instance, 'Tracer')() or shared.RLDrawings:CreateDrawing('Line', Instance, 'Tracer');
  342.  
  343.     local Position = shared.RLDrawings:GetScreenPosition(Instance);
  344.  
  345.     if Position and Position.OVisible and Position.Distance < 1000 then
  346.         LineObject.Visible = true;
  347.         LineObject.Color = DisplayColor or Colors.White;
  348.         LineObject.From = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y);
  349.         LineObject.To = Position.ScreenPosition;
  350.     else
  351.         LineObject.Visible = false;
  352.     end
  353. end
  354.  
  355. function DrawObjectCircle(Instance, DisplayColor)
  356.     local CircleObject = shared.RLDrawings:GetDrawing(Instance, 'Dot')() or shared.RLDrawings:CreateDrawing('Circle', Instance, 'Dot');
  357.  
  358.     local Position, Visible = shared.RLDrawings:GetScreenPosition(Instance);
  359.  
  360.     if Position and Position.Visible and Position.Distance < 1000 then
  361.         local Distance = Position.Depth;
  362.  
  363.         if LocalPlayer.Character and LocalPlayer.Character.PrimaryPart then
  364.             Distance = (LocalPlayer.Character.PrimaryPart.Position - Instance.Position).magnitude;
  365.         end
  366.  
  367.         CircleObject.Visible = true;
  368.         CircleObject.Color = DisplayColor or Colors.White;
  369.         CircleObject.Radius = math.clamp(650 / Distance, 3, 20);
  370.         CircleObject.Filled = true;
  371.         CircleObject.Transparency = CircleObject.Radius <= 7.5 and 1 or 0.35;
  372.         CircleObject.Position = Position.ScreenPosition;
  373.     else
  374.         CircleObject.Visible = false;
  375.     end
  376. end
  377.  
  378. function DrawObjects(Table)
  379.     if typeof(Table) ~= 'table' then return; end
  380.  
  381.     for i, v in pairs(Table) do
  382.         -- print(i, v, typeof(v));
  383.         if shared.ckill then break; end
  384.  
  385.         if typeof(v) == 'table' and v.Instance ~= nil then
  386.             if v.Text then
  387.                 DrawObjectText(v.Instance, v.Text, v.Color, v.DrawDistance);
  388.             end
  389.             if v.DrawTracer then
  390.                 DrawObjectTracer(v.Instance, v.Color);
  391.             end
  392.             if v.DrawCircle then
  393.                 DrawObjectCircle(v.Instance, v.Color);
  394.             end
  395.         end
  396.     end
  397. end
  398.  
  399. if bind then
  400.     bind('f6', function()
  401.         RunService:UnbindFromRenderStep'RLESP';
  402.         shared.RLDrawings.Enabled = false;
  403.         shared.ckill = true;
  404.         wait(1 / 20);
  405.         shared.RLDrawings:Cleanup();
  406.     end);
  407. end
  408.  
  409. RunService:BindToRenderStep('RLESP', 1, function()
  410.     if (tick() - Updates.InvalidCheck) > 1 then
  411.         Updates.InvalidCheck = tick();
  412.         shared.RLDrawings:CheckForInvalidDrawings();
  413.     end
  414.  
  415.     if (tick() - Updates.ESP) > RefreshRate then
  416.         Updates.ESP = tick();
  417.         for i, v in pairs(shared.RLDrawings.ObjectsToDraw.Tables) do
  418.             if shared.ckill then break; end
  419.  
  420.             coroutine.wrap(DrawObjects)(v);
  421.         end
  422.     end
  423. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement