-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsense.lua
More file actions
626 lines (555 loc) · 22.6 KB
/
Copy pathsense.lua
File metadata and controls
626 lines (555 loc) · 22.6 KB
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
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
-- services
local runService = game:GetService("RunService");
local players = game:GetService("Players");
local workspace = game:GetService("Workspace");
local coreGui = game:GetService("CoreGui");
-- variables
local localPlayer = players.LocalPlayer;
local camera = workspace.CurrentCamera;
local viewportSize = camera.ViewportSize;
local container = Instance.new("Folder", coreGui);
-- locals
local floor = math.floor;
local round = math.round;
local atan2 = math.atan2;
local sin = math.sin;
local cos = math.cos;
local find = string.find;
local insert = table.insert;
local clear = table.clear;
-- namecalls
local wtvp = camera.WorldToViewportPoint;
local isA = workspace.IsA;
local findFirstChild = workspace.FindFirstChild;
local findFirstChildOfClass = workspace.FindFirstChildOfClass;
local getChildren = workspace.GetChildren;
local toOrientation = CFrame.identity.ToOrientation;
local pointToObjectSpace = CFrame.identity.PointToObjectSpace;
local lerpColor = Color3.new().Lerp;
local min2 = Vector2.zero.Min;
local max2 = Vector2.zero.Max;
local lerp2 = Vector2.zero.Lerp;
local min3 = Vector3.zero.Min;
local max3 = Vector3.zero.Max;
-- constants
local HEALTH_BAR_OFFSET = Vector2.new(5, 0);
local HEALTH_TEXT_OFFSET = Vector2.new(3, 0);
local HEALTH_BAR_OUTLINE_OFFSET = Vector2.new(0, 1);
local NAME_OFFSET = Vector2.new(0, 2);
local WEAPON_OFFSET = Vector2.new(0, 2);
local DISTANCE_OFFSET = Vector2.new(0, 2);
local VERTICES = {
Vector3.new(1, 1, 1),
Vector3.new(-1, 1, 1),
Vector3.new(1, -1, 1),
Vector3.new(-1, -1, 1),
Vector3.new(1, 1, -1),
Vector3.new(-1, 1, -1),
Vector3.new(1, -1, -1),
Vector3.new(-1, -1, -1),
};
-- utils
local function isBodyPart(name)
return name == "Head" or find(name, "Torso") or find(name, "Leg") or find(name, "Arm");
end
local function getBoundingBox(parts)
local min, max;
for _, part in next, parts do
local cframe, size = part.CFrame, part.Size;
min = min3(min or cframe.Position, (cframe - size*0.5).Position);
max = max3(max or cframe.Position, (cframe + size*0.5).Position);
end
local center = (min + max)*0.5;
local front = Vector3.new(center.X, center.Y, max.Z);
return CFrame.new(center, front), max - min;
end
local function worldToScreen(world)
local screen, inBounds = wtvp(camera, world);
return Vector2.new(screen.X, screen.Y), inBounds, screen.Z;
end
local function calculateCorners(cframe, size)
local min, max = viewportSize, Vector2.zero;
for _, vertex in next, VERTICES do
local position = (cframe + size*0.5 * vertex).Position;
local screen = worldToScreen(position);
min, max = min2(min, screen), max2(max, screen);
end
return {
topLeft = Vector2.new(floor(min.X), floor(min.Y)),
topRight = Vector2.new(floor(max.X), floor(min.Y)),
bottomLeft = Vector2.new(floor(min.X), floor(max.Y)),
bottomRight = Vector2.new(floor(max.X), floor(max.Y))
};
end
local function rotateVector(vector, radians)
local c, s = cos(radians), sin(radians);
return Vector2.new(c*vector.X - s*vector.Y, s*vector.X + c*vector.Y);
end
-- esp object
local EspObject = {};
EspObject.__index = EspObject;
function EspObject.new(player, interface)
local self = setmetatable({}, EspObject);
self.player = assert(player, "Missing argument #1 (Player expected)");
self.interface = assert(interface, "Missing argument #2 (table expected)");
self.bin = {};
self.charCache = {};
self.childCount = 0;
self:Construct();
return self;
end
function EspObject:Create(class, properties)
local drawing = Drawing.new(class);
for property, value in next, properties do
drawing[property] = value;
end
insert(self.bin, drawing);
return drawing;
end
function EspObject:Construct()
self.drawings = {
visible = {
boxOutline = self:Create("Square", {
Thickness = 3,
ZIndex = 2,
Visible = false
}),
box = self:Create("Square", {
Thickness = 1,
ZIndex = 2,
Visible = false
}),
boxFill = self:Create("Square", {
Filled = true,
ZIndex = 2,
Visible = false
}),
healthBarOutline = self:Create("Line", {
Thickness = 3,
ZIndex = 2,
Visible = false
}),
healthBar = self:Create("Line", {
Thickness = 1,
ZIndex = 2,
Visible = false
}),
healthText = self:Create("Text", {
Center = true,
ZIndex = 3,
Visible = false
}),
name = self:Create("Text", {
Text = self.player.Name,
Center = true,
ZIndex = 3,
Visible = false
}),
weapon = self:Create("Text", {
Center = true,
ZIndex = 3,
Visible = false
}),
distance = self:Create("Text", {
Center = true,
ZIndex = 3,
Visible = false
}),
tracerOutline = self:Create("Line", {
Thickness = 3,
ZIndex = 1,
Visible = false
}),
tracer = self:Create("Line", {
Thickness = 1,
ZIndex = 1,
Visible = false
}),
},
hidden = {
arrowOutline = self:Create("Triangle", {
Thickness = 3,
ZIndex = 4,
Visible = false
}),
arrow = self:Create("Triangle", {
Filled = true,
ZIndex = 4,
Visible = false
})
}
};
self.updateConnection = runService.Heartbeat:Connect(function(...)
self:Update(...);
end);
self.renderConnection = runService.RenderStepped:Connect(function(...)
self:Render(...);
end);
end
function EspObject:Destruct()
self.updateConnection:Disconnect();
self.renderConnection:Disconnect();
for _, drawing in next, self.bin do
drawing:Remove();
end
clear(self);
end
function EspObject:Update()
local character = self.interface.getCharacter(self.player);
local head = character and findFirstChild(character, "Head");
local interface = self.interface;
self.options = interface.teamSettings[interface.isFriendly(self.player) and "Friendly" or "Enemy"];
self.health, self.maxHealth = interface.getHealth(self.player);
self.weapon = interface.getWeapon(self.player);
self.character = character;
if head then
local _, onScreen, depth = worldToScreen(head.Position);
self.onScreen = onScreen;
self.distance = depth;
if onScreen then
local children = getChildren(character);
if not self.charCache[1] or self.childCount ~= #children then
clear(self.charCache);
for _, part in next, children do
if isA(part, "BasePart") and isBodyPart(part.Name) then
insert(self.charCache, part);
end
end
self.childCount = #children;
end
self.corners = calculateCorners(getBoundingBox(self.charCache));
elseif self.options.offScreenArrow then
local _, yaw, roll = toOrientation(camera.CFrame);
local flatCFrame = CFrame.Angles(0, yaw, roll) + camera.CFrame.Position;
local objectSpace = pointToObjectSpace(flatCFrame, head.Position);
local angle = atan2(objectSpace.Z, objectSpace.X);
self.direction = Vector2.new(cos(angle), sin(angle));
end
self.hasUpdated = true;
end
end
function EspObject:Render()
if not self.hasUpdated then
return;
end
local visible = self.drawings.visible;
local hidden = self.drawings.hidden;
local interface = self.interface;
local options = self.options;
local corners = self.corners;
local onScreen = self.onScreen or false;
local alive = self.character and self.health and self.health > 0 or false;
local enabled = options.enabled and alive and not (#interface.whitelist > 0 and not interface.whitelist[self.player]);
visible.box.Visible = enabled and onScreen and options.boxEnabled;
visible.boxOutline.Visible = visible.box.Visible and options.boxOutline;
if visible.box.Visible then
local box = visible.box;
box.Position = corners.topLeft;
box.Size = corners.bottomRight - corners.topLeft;
box.Color = options.boxColor[1];
box.Transparency = options.boxColor[2];
local boxOutline = visible.boxOutline;
boxOutline.Position = box.Position;
boxOutline.Size = box.Size;
boxOutline.Color = options.boxOutlineColor[1];
boxOutline.Transparency = options.boxOutlineColor[2];
end
visible.boxFill.Visible = enabled and onScreen and options.boxFill;
if visible.boxFill.Visible then
local boxFill = visible.boxFill;
boxFill.Position = corners.topLeft;
boxFill.Size = corners.bottomRight - corners.topLeft;
boxFill.Color = options.boxFillColor[1];
boxFill.Transparency = options.boxFillColor[2];
end
visible.healthBar.Visible = enabled and onScreen and options.healthBar;
visible.healthBarOutline.Visible = visible.healthBar.Visible and options.healthBarOutline;
if visible.healthBar.Visible then
local barFrom = corners.topLeft - HEALTH_BAR_OFFSET;
local barTo = corners.bottomLeft - HEALTH_BAR_OFFSET;
local healthBar = visible.healthBar;
healthBar.To = barTo;
healthBar.From = lerp2(barTo, barFrom, self.health/self.maxHealth);
healthBar.Color = lerpColor(options.dyingColor, options.healthyColor, self.health/self.maxHealth);
local healthBarOutline = visible.healthBarOutline;
healthBarOutline.To = barTo + HEALTH_BAR_OUTLINE_OFFSET;
healthBarOutline.From = barFrom - HEALTH_BAR_OUTLINE_OFFSET;
healthBarOutline.Color = options.healthBarOutlineColor[1];
healthBarOutline.Transparency = options.healthBarOutlineColor[2];
end
visible.healthText.Visible = enabled and onScreen and options.healthText;
if visible.healthText.Visible then
local barFrom = corners.topLeft - HEALTH_BAR_OFFSET;
local barTo = corners.bottomLeft - HEALTH_BAR_OFFSET;
local healthText = visible.healthText;
healthText.Text = round(self.health) .. "hp";
healthText.Size = interface.sharedSettings.textSize;
healthText.Font = interface.sharedSettings.textFont;
healthText.Color = options.healthTextColor[1];
healthText.Transparency = options.healthTextColor[2];
healthText.Outline = options.healthTextOutline;
healthText.OutlineColor = options.healthTextOutlineColor;
healthText.Position = lerp2(barTo, barFrom, self.health/self.maxHealth) - healthText.TextBounds*0.5 - HEALTH_TEXT_OFFSET;
end
visible.name.Visible = enabled and onScreen and options.name;
if visible.name.Visible then
local name = visible.name;
name.Size = interface.sharedSettings.textSize;
name.Font = interface.sharedSettings.textFont;
name.Color = options.nameColor[1];
name.Transparency = options.nameColor[2];
name.Outline = options.nameOutline;
name.OutlineColor = options.nameOutlineColor;
name.Position = (corners.topLeft + corners.topRight)*0.5 - Vector2.yAxis*name.TextBounds.Y - NAME_OFFSET;
end
visible.weapon.Visible = enabled and onScreen and options.weapon;
if visible.weapon.Visible then
local weapon = visible.weapon;
weapon.Text = self.weapon;
weapon.Size = interface.sharedSettings.textSize;
weapon.Font = interface.sharedSettings.textFont;
weapon.Color = options.weaponColor[1];
weapon.Transparency = options.weaponColor[2];
weapon.Outline = options.weaponOutline;
weapon.OutlineColor = options.weaponOutlineColor;
weapon.Position = (corners.bottomLeft + corners.bottomRight)*0.5 + WEAPON_OFFSET;
end
visible.distance.Visible = enabled and onScreen and options.distance;
if visible.distance.Visible then
local distance = visible.distance;
distance.Text = round(self.distance) .. " studs";
distance.Size = interface.sharedSettings.textSize;
distance.Font = interface.sharedSettings.textFont;
distance.Color = options.distanceColor[1];
distance.Transparency = options.distanceColor[2];
distance.Outline = options.distanceOutline;
distance.OutlineColor = options.distanceOutlineColor;
distance.Position =
(corners.bottomLeft + corners.bottomRight)*0.5 + DISTANCE_OFFSET +
(visible.weapon.Visible and WEAPON_OFFSET + Vector2.yAxis*visible.weapon.TextBounds.Y or Vector2.zero);
end
visible.tracer.Visible = enabled and onScreen and options.tracer;
visible.tracerOutline.Visible = visible.tracer.Visible and options.tracerOutline;
if visible.tracer.Visible then
local tracer = visible.tracer;
tracer.Color = options.tracerColor[1];
tracer.Transparency = options.tracerColor[2];
tracer.To = (corners.bottomLeft + corners.bottomRight)*0.5;
tracer.From =
options.tracerOrigin == "Middle" and viewportSize*0.5 or
options.tracerOrigin == "Top" and viewportSize*Vector2.new(0.5, 0) or
options.tracerOrigin == "Bottom" and viewportSize*Vector2.new(0.5, 1);
local tracerOutline = visible.tracerOutline;
tracerOutline.Color = options.tracerOutlineColor[1];
tracerOutline.Transparency = options.tracerOutlineColor[2];
tracerOutline.To = tracer.To;
tracerOutline.From = tracer.From;
end
hidden.arrow.Visible = enabled and not onScreen and options.offScreenArrow;
hidden.arrowOutline.Visible = hidden.arrow.Visible and options.offScreenArrowOutline;
if hidden.arrow.Visible then
local arrow = hidden.arrow;
arrow.PointA = min2(max2(viewportSize*0.5 + self.direction*options.offScreenArrowRadius, Vector2.one*25), viewportSize - Vector2.one*25);
arrow.PointB = arrow.PointA - rotateVector(self.direction, 0.45)*options.offScreenArrowSize;
arrow.PointC = arrow.PointA - rotateVector(self.direction, -0.45)*options.offScreenArrowSize;
arrow.Color = options.offScreenArrowColor[1];
arrow.Transparency = options.offScreenArrowColor[2];
local arrowOutline = hidden.arrowOutline;
arrowOutline.PointA = arrow.PointA;
arrowOutline.PointB = arrow.PointB;
arrowOutline.PointC = arrow.PointC;
arrowOutline.Color = options.offScreenArrowOutlineColor[1];
arrowOutline.Transparency = options.offScreenArrowOutlineColor[2];
end
end
-- cham object
local ChamObject = {};
ChamObject.__index = ChamObject;
function ChamObject.new(player, interface)
local self = setmetatable({}, ChamObject);
self.player = assert(player, "Missing argument #1 (Player expected)");
self.interface = assert(interface, "Missing argument #2 (table expected)");
self:Construct();
return self;
end
function ChamObject:Construct()
self.highlight = Instance.new("Highlight", container);
self.updateConnection = runService.Heartbeat:Connect(function()
self:Update();
end);
end
function ChamObject:Destruct()
self.updateConnection:Disconnect();
self.highlight:Destroy();
clear(self);
end
function ChamObject:Update()
local interface = self.interface;
local character = interface.getCharacter(self.player);
local options = interface.teamSettings[interface.isFriendly(self.player) and "Friendly" or "Enemy"];
local enabled = options.enabled and character and not (#interface.whitelist > 0 and not interface.whitelist[self.player]);
local highlight = self.highlight;
highlight.Enabled = enabled and options.chams;
highlight.DepthMode = options.chamsVisibleOnly and Enum.HighlightDepthMode.Occluded or Enum.HighlightDepthMode.AlwaysOnTop;
highlight.Adornee = character;
highlight.FillColor = options.chamsFillColor[1];
highlight.FillTransparency = options.chamsFillColor[2];
highlight.OutlineColor = options.chamsOutlineColor[1];
highlight.OutlineTransparency = options.chamsOutlineColor[2];
end
-- interface
local EspInterface = {
objectCache = {},
hasLoaded = false,
whitelist = {},
sharedSettings = {
textSize = 13,
textFont = 2
},
teamSettings = {
Enemy = {
enabled = false,
boxEnabled = false,
boxColor = { Color3.new(1,0,0), 1 },
boxOutline = true,
boxOutlineColor = { Color3.new(), 1 },
boxFill = false,
boxFillColor = { Color3.new(1,0,0), 0.5 },
healthBar = false,
healthyColor = Color3.new(0,1,0),
dyingColor = Color3.new(1,0,0),
healthBarOutline = true,
healthBarOutlineColor = { Color3.new(), 1 },
healthText = false,
healthTextColor = { Color3.new(1,1,1), 1 },
healthTextOutline = true,
healthTextOutlineColor = Color3.new(),
name = false,
nameColor = { Color3.new(1,1,1), 1 },
nameOutline = true,
nameOutlineColor = Color3.new(),
weapon = false,
weaponColor = { Color3.new(1,1,1), 1 },
weaponOutline = true,
weaponOutlineColor = Color3.new(),
distance = false,
distanceColor = { Color3.new(1,1,1), 1 },
distanceOutline = true,
distanceOutlineColor = Color3.new(),
tracer = false,
tracerOrigin = "Bottom",
tracerColor = { Color3.new(1,0,0), 1 },
tracerOutline = true,
tracerOutlineColor = { Color3.new(), 1 },
offScreenArrow = false,
offScreenArrowColor = { Color3.new(1,1,1), 1 },
offScreenArrowSize = 15,
offScreenArrowRadius = 150,
offScreenArrowOutline = true,
offScreenArrowOutlineColor = { Color3.new(), 1 },
chams = false,
chamsVisibleOnly = false,
chamsFillColor = { Color3.new(0.2, 0.2, 0.2), 0.5 },
chamsOutlineColor = { Color3.new(1,0,0), 0 }
},
Friendly = {
enabled = false,
boxEnabled = false,
boxColor = { Color3.new(0,1,0), 1 },
boxOutline = true,
boxOutlineColor = { Color3.new(), 1 },
boxFill = false,
boxFillColor = { Color3.new(0,1,0), 0.5 },
healthBar = false,
healthyColor = Color3.new(0,1,0),
dyingColor = Color3.new(1,0,0),
healthBarOutline = true,
healthBarOutlineColor = { Color3.new(), 1 },
healthText = false,
healthTextColor = { Color3.new(1,1,1), 1 },
healthTextOutline = true,
healthTextOutlineColor = Color3.new(),
name = false,
nameColor = { Color3.new(1,1,1), 1 },
nameOutline = true,
nameOutlineColor = Color3.new(),
weapon = false,
weaponColor = { Color3.new(1,1,1), 1 },
weaponOutline = true,
weaponOutlineColor = Color3.new(),
distance = false,
distanceColor = { Color3.new(1,1,1), 1 },
distanceOutline = true,
distanceOutlineColor = Color3.new(),
tracer = false,
tracerOrigin = "Bottom",
tracerColor = { Color3.new(0,1,0), 1 },
tracerOutline = true,
tracerOutlineColor = { Color3.new(), 1 },
offScreenArrow = false,
offScreenArrowColor = { Color3.new(1,1,1), 1 },
offScreenArrowSize = 15,
offScreenArrowRadius = 150,
offScreenArrowOutline = true,
offScreenArrowOutlineColor = { Color3.new(), 1 },
chams = false,
chamsVisibleOnly = false,
chamsFillColor = { Color3.new(0.2, 0.2, 0.2), 0.5 },
chamsOutlineColor = { Color3.new(0,1,0), 0 }
}
}
};
function EspInterface.Load()
assert(not EspInterface.hasLoaded, "Esp has already been loaded.");
local function createObject(player)
EspInterface.objectCache[player] = {
esp = EspObject.new(player, EspInterface),
cham = ChamObject.new(player, EspInterface)
};
end
local function removeObject(player)
local object = EspInterface.objectCache[player];
if object then
object.esp:Destruct();
object.cham:Destruct();
end
EspInterface.objectCache[player] = nil;
end
EspInterface.playerAdded = players.PlayerAdded:Connect(createObject);
EspInterface.playerRemoving = players.PlayerRemoving:Connect(removeObject);
for _, player in next, players:GetPlayers() do
if player ~= localPlayer then
createObject(player);
end
end
EspInterface.hasLoaded = true;
end
function EspInterface.Unload()
assert(EspInterface.hasLoaded, "Esp has not been loaded yet.");
EspInterface.playerAdded:Disconnect();
EspInterface.playerRemoving:Disconnect();
for _, object in next, EspInterface.objectCache do
object.esp:Destruct();
object.cham:Destruct();
end
EspInterface.hasLoaded = false;
end
-- game specific functions
function EspInterface.getWeapon(player)
return "Unknown";
end
function EspInterface.isFriendly(player)
return player.Team and player.Team == localPlayer.Team;
end
function EspInterface.getCharacter(player)
return player.Character;
end
function EspInterface.getHealth(player)
local character = EspInterface.getCharacter(player);
local humanoid = character and findFirstChildOfClass(character, "Humanoid");
if humanoid then
return humanoid.Health, humanoid.MaxHealth;
end
return 100, 100;
end
return EspInterface;