Advertisement
akaMeltDown

ESP

Apr 8th, 2023
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.62 KB | None | 0 0
  1. --Settings--
  2. local ESP = {
  3. Enabled = false,
  4. Boxes = true,
  5. BoxShift = CFrame.new(0,-1.5,0),
  6. BoxSize = Vector3.new(4,6,0),
  7. Color = Color3.fromRGB(255, 170, 0),
  8. FaceCamera = false,
  9. Names = true,
  10. TeamColor = false,
  11. Thickness = 2,
  12. AttachShift = 1,
  13. TeamMates = false,
  14. Players = true,
  15.  
  16. Objects = setmetatable({}, {__mode = "kv"}),
  17. Overrides = {}
  18. }
  19.  
  20. --Declarations--
  21. local cam = workspace.CurrentCamera
  22. local ViewportSize = cam.ViewportSize
  23. local ViewportX = ViewportSize.X
  24. local ViewportY = ViewportSize.Y
  25.  
  26. local plrs = game:GetService("Players")
  27. local plr = plrs.LocalPlayer
  28. local mouse = plr:GetMouse()
  29.  
  30. local V3new = Vector3.new
  31. local WorldToViewportPoint = cam.WorldToViewportPoint
  32.  
  33. --Functions--
  34. local function Draw(obj, props)
  35. local new = Drawing.new(obj)
  36.  
  37. props = props or {}
  38. for i, v in pairs(props) do
  39. new[i] = v
  40. end
  41.  
  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. return self:Remove()
  152. end
  153.  
  154. local color
  155. if ESP.Highlighted == self.Object then
  156. color = ESP.HighlightColor
  157. else
  158. color = self.Color or self.ColorDynamic and self:ColorDynamic() or ESP:GetColor(self.Object) or ESP.Color
  159. end
  160.  
  161. local allow = true
  162. if ESP.Overrides.UpdateAllow and not ESP.Overrides.UpdateAllow(self) then
  163. allow = false
  164. end
  165.  
  166. if self.Player and not ESP.TeamMates and ESP:IsTeamMate(self.Player) then
  167. allow = false
  168. end
  169.  
  170. if self.Player and not ESP.Players then
  171. allow = false
  172. end
  173.  
  174. if self.IsEnabled and (type(self.IsEnabled) == "string" and not ESP[self.IsEnabled] or type(self.IsEnabled) == "function" and not self:IsEnabled()) then
  175. allow = false
  176. end
  177.  
  178. if not workspace:IsAncestorOf(self.PrimaryPart) and not self.RenderInNil then
  179. allow = false
  180. end
  181.  
  182. if not allow then
  183. for i,v in pairs(self.Components) do
  184. v.Visible = false
  185. end
  186.  
  187. return
  188. end
  189.  
  190. if ESP.Highlighted == self.Object then
  191. color = ESP.HighlightColor
  192. end
  193.  
  194. --calculations--
  195. local cf = self.PrimaryPart.CFrame
  196. if ESP.FaceCamera then
  197. cf = CFrame.new(cf.p, cam.CFrame.p)
  198. end
  199. local size = self.Size
  200. local locs = {
  201. TopLeft = cf * ESP.BoxShift * CFrame.new(size.X/2, size.Y/2,0),
  202. TopRight = cf * ESP.BoxShift * CFrame.new(-size.X/2, size.Y/2,0),
  203. BottomLeft = cf * ESP.BoxShift * CFrame.new(size.X/2, -size.Y/2,0),
  204. BottomRight = cf * ESP.BoxShift * CFrame.new(-size.X/2,-size.Y/2,0),
  205. TagPos = cf * ESP.BoxShift * CFrame.new(0,size.Y/2,0),
  206. Torso = cf * ESP.BoxShift
  207. }
  208.  
  209. if ESP.Boxes then
  210. local TopLeft, Vis1 = cam:WorldToViewportPoint(locs.TopLeft.p)
  211. local TopRight, Vis2 = cam:WorldToViewportPoint(locs.TopRight.p)
  212. local BottomLeft, Vis3 = cam:WorldToViewportPoint(locs.BottomLeft.p)
  213. local BottomRight, Vis4 = cam:WorldToViewportPoint(locs.BottomRight.p)
  214.  
  215. if self.Components.Quad then
  216. if Vis1 or Vis2 or Vis3 or Vis4 then
  217. self.Components.Quad.Visible = true
  218. self.Components.Quad.PointA = Vector2.new(TopRight.X, TopRight.Y)
  219. self.Components.Quad.PointB = Vector2.new(TopLeft.X, TopLeft.Y)
  220. self.Components.Quad.PointC = Vector2.new(BottomLeft.X, BottomLeft.Y)
  221. self.Components.Quad.PointD = Vector2.new(BottomRight.X, BottomRight.Y)
  222. self.Components.Quad.Color = color
  223. else
  224. self.Components.Quad.Visible = false
  225. end
  226. end
  227. else
  228. self.Components.Quad.Visible = false
  229. end
  230.  
  231. if ESP.Names then
  232. local TagPos, Vis5 = cam:WorldToViewportPoint(locs.TagPos.p)
  233.  
  234. if Vis5 then
  235. self.Components.Name.Visible = true
  236. self.Components.Name.Position = Vector2.new(TagPos.X, TagPos.Y)
  237. self.Components.Name.Text = self.Name
  238. self.Components.Name.Color = color
  239.  
  240. self.Components.Distance.Visible = true
  241. self.Components.Distance.Position = Vector2.new(TagPos.X, TagPos.Y + 14)
  242. self.Components.Distance.Text = math.floor((cam.CFrame.p - cf.p).Magnitude) .. "m away"
  243. self.Components.Distance.Color = color
  244. else
  245. self.Components.Name.Visible = false
  246. self.Components.Distance.Visible = false
  247. end
  248. else
  249. self.Components.Name.Visible = false
  250. self.Components.Distance.Visible = false
  251. end
  252.  
  253. if ESP.Tracers then
  254. local TorsoPos, Vis6 = cam:WorldToViewportPoint(locs.Torso.p)
  255.  
  256. if Vis6 then
  257. self.Components.Tracer.From = Vector2.new(ViewportX/2, ViewportY/2)
  258. self.Components.Tracer.To = Vector2.new(TorsoPos.X, TorsoPos.Y)
  259. self.Components.Tracer.Color = color
  260. self.Components.Tracer.Visible = true
  261. else
  262. self.Components.Tracer.Visible = false
  263. end
  264. else
  265. self.Components.Tracer.Visible = false
  266. end
  267. end
  268.  
  269. function ESP:Add(obj, options)
  270. if not obj.Parent and not options.RenderInNil then
  271. return
  272. end
  273.  
  274. local box = setmetatable({
  275. Name = options.Name or obj.Name,
  276. Type = "Box",
  277. Color = options.Color,
  278. Size = options.Size or self.BoxSize,
  279. Object = obj,
  280. Player = options.Player or plrs:GetPlayerFromCharacter(obj),
  281. PrimaryPart = options.PrimaryPart or obj.ClassName == "Model" and (obj.PrimaryPart or obj:FindFirstChild("HumanoidRootPart") or obj:FindFirstChildWhichIsA("BasePart")) or obj:IsA("BasePart") and obj,
  282. Components = {},
  283. IsEnabled = options.IsEnabled,
  284. Temporary = options.Temporary,
  285. ColorDynamic = options.ColorDynamic,
  286. RenderInNil = options.RenderInNil
  287. }, boxBase)
  288.  
  289. if self:GetBox(obj) then
  290. self:GetBox(obj):Remove()
  291. end
  292.  
  293. box.Components["Quad"] = Draw("Quad", {
  294. Thickness = self.Thickness,
  295. Color = color,
  296. Transparency = 1,
  297. Filled = false,
  298. Visible = self.Enabled and self.Boxes
  299. })
  300.  
  301. box.Components["Name"] = Draw("Text", {
  302. Text = box.Name,
  303. Color = box.Color,
  304. Center = true,
  305. Outline = true,
  306. Size = 12,
  307. Visible = self.Enabled and self.Names
  308. })
  309.  
  310. box.Components["Distance"] = Draw("Text", {
  311. Color = box.Color,
  312. Center = false,
  313. Outline = true,
  314. Size = 12,
  315. Visible = self.Enabled and self.Names
  316. })
  317.  
  318. box.Components["Tracer"] = Draw("Line", {
  319. Thickness = ESP.Thickness,
  320. Color = box.Color,
  321. Transparency = 1,
  322. Visible = self.Enabled and self.Tracers
  323. })
  324.  
  325. self.Objects[obj] = box
  326.  
  327. obj.AncestryChanged:Connect(function(_, parent)
  328. if parent == nil and ESP.AutoRemove ~= false then
  329. box:Remove()
  330. end
  331. end)
  332.  
  333. obj:GetPropertyChangedSignal("Parent"):Connect(function()
  334. if obj.Parent == nil and ESP.AutoRemove ~= false then
  335. box:Remove()
  336. end
  337. end)
  338.  
  339. local hum = obj:FindFirstChildOfClass("Humanoid")
  340. if hum then
  341. hum.Died:Connect(function()
  342. if ESP.AutoRemove ~= false then
  343. box:Remove()
  344. end
  345. end)
  346. end
  347.  
  348. return box
  349. end
  350.  
  351. game:GetService("RunService").RenderStepped:Connect(function()
  352. if ESP.Enabled then
  353. for i, v in next, ESP.Objects do
  354. if v.Update then
  355. pcall(v.Update, v)
  356. end
  357. end
  358. end
  359. end)
  360.  
  361. return ESP
  362.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement