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