forked from alohabeach/Main
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsource.lua
More file actions
1083 lines (937 loc) · 45.4 KB
/
Copy pathsource.lua
File metadata and controls
1083 lines (937 loc) · 45.4 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
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
if not game:IsLoaded() or not game.Loaded then game.Loaded:Wait() end
getgenv().test = 35
if game.PlaceId == 606849621 then
print("this is jailbreak")
end
local Camera = workspace.CurrentCamera
local LocalPlayer = game:GetService("Players").LocalPlayer
local Services = {
RunService = game:GetService("RunService"),
Players = game:GetService("Players"),
Stats = game:GetService("Stats"),
}
local MainESP = {
Container = {},
TracerOrigins = {
Top = Vector2.new(Camera.ViewportSize.X / 2, 0),
Middle = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y / 2),
Bottom = Vector2.new(Camera.ViewportSize.X / 2, Camera.ViewportSize.Y),
},
Options = {
Enabled = false,
Box = false,
Health = false,
Tracer = false,
TracerOrigin = "Bottom",
Name = false,
Distance = false,
Direction = false,
Skeleton = false,
TextOutline = false,
Color = Color3.new(1, 1, 1),
UseTeamColor = true,
Rainbow = false,
Font = 1,
FontSize = 20,
TeamCheck = false,
BoxThickness = 0,
TracerThickness = 0,
DirectionThickness = 0,
SkeletonThickness = 0,
Bounties = false, -- jb only
},
ObjectOptions = {
Enabled = false,
Tracer = false,
TextOutline = false,
Distance = false,
Name = false,
Font = 1,
FontSize = 20,
Rainbow = false,
Color = Color3.fromRGB(255, 255, 0),
TracerOrigin = "Bottom",
TracerThickness = 0,
},
-- Optimization caches
_colorCache = {},
_positionCache = {},
}
--[[ Drawing Creation Functions ]]--
function MainESP.CreateBox()
local box = Drawing.new("Square")
box.Thickness = 1
box.Filled = false
box.Visible = false
box.ZIndex = 1
return box
end
function MainESP.CreateLine()
local line = Drawing.new("Line")
line.Thickness = 1
line.Visible = false
line.ZIndex = 1
return line
end
function MainESP.CreateText()
local text = Drawing.new("Text")
text.Center = true
text.Outline = false
text.Font = Drawing.Fonts.UI
text.Size = 16
text.Visible = false
text.ZIndex = 2
return text
end
function MainESP.CreateCircle()
local circle = Drawing.new("Circle")
circle.Filled = false
circle.NumSides = 12
circle.Radius = 4
circle.Thickness = 1
circle.Visible = false
circle.ZIndex = 1
return circle
end
--[[ Utility Functions ]]--
function MainESP.WTVP(position)
return Camera:WorldToViewportPoint(position)
end
function MainESP.GetHealth(player)
if player.Character and player.Character:FindFirstChild("Humanoid") then
local humanoid = player.Character.Humanoid
return humanoid.Health, humanoid.MaxHealth
end
return 0, 100
end
function MainESP:PlayerAlive(player)
local health = self.GetHealth(player)
return health > 0 and player.Character:FindFirstChild("HumanoidRootPart")
end
function MainESP.GetDistanceFromPlayer(player, position)
if player.Character and player.Character:FindFirstChild("HumanoidRootPart") then
return (player.Character.HumanoidRootPart.Position - position).Magnitude
end
return math.huge
end
--[[ Color Management ]]--
function MainESP:GetColor(player, useTeamColor, rainbow, defaultColor)
local currentTime = tick()
local cacheKey = player and tostring(player.UserId) or "default"
if useTeamColor and player and player.Team then
return player.Team.TeamColor.Color
elseif rainbow then
-- Limit rainbow cache updates and add cleanup
if not self._colorCache[cacheKey] or currentTime - (self._colorCache[cacheKey].time or 0) > 0.033 then
-- Only update rainbow color every ~30ms instead of every frame
self._colorCache[cacheKey] = {
color = Color3.fromHSV(currentTime * 35 % 255/255, 1, 1),
time = currentTime
}
end
return self._colorCache[cacheKey].color
else
return defaultColor
end
end
--[[ Distance-Based Culling System ]]--
local CullingSystem = {
maxRenderDistance = 2000, -- studs
nearDistance = 500, -- studs - full detail
farDistance = 1000, -- studs - reduced detail
}
function CullingSystem:ShouldRenderPlayer(player)
if not player.Character or not player.Character:FindFirstChild("HumanoidRootPart") then
return false
end
local distance = MainESP.GetDistanceFromPlayer(player,
MainESP:PlayerAlive(LocalPlayer) and LocalPlayer.Character.HumanoidRootPart.Position or Camera.CFrame.Position)
if distance > self.maxRenderDistance then
return false
end
return true, distance
end
function CullingSystem:GetDetailLevel(distance)
if distance <= self.nearDistance then
return "full"
elseif distance <= self.farDistance then
return "medium"
else
return "minimal"
end
end
--[[ Position Caching ]]--
local CacheManager = {
maxCacheAge = 30, -- seconds
cleanupInterval = 10, -- seconds
lastCleanup = 0,
}
function CacheManager:CleanupCaches()
local now = tick()
if now - self.lastCleanup < self.cleanupInterval then
return
end
-- Clean position cache
local positionKeysToRemove = {}
for key, data in pairs(MainESP._positionCache) do
if now - data.time > self.maxCacheAge then
table.insert(positionKeysToRemove, key)
end
end
for _, key in pairs(positionKeysToRemove) do
MainESP._positionCache[key] = nil
end
-- Clean color cache
local colorKeysToRemove = {}
for key, data in pairs(MainESP._colorCache) do
if data.time and now - data.time > self.maxCacheAge then
table.insert(colorKeysToRemove, key)
end
end
for _, key in pairs(colorKeysToRemove) do
MainESP._colorCache[key] = nil
end
self.lastCleanup = now
-- Debug info (remove in production)
-- if #positionKeysToRemove > 0 or #colorKeysToRemove > 0 then
-- print(string.format("Cache cleanup: Removed %d position entries, %d color entries",
-- #positionKeysToRemove, #colorKeysToRemove))
-- end
end
function MainESP:GetCachedPosition(part, partName, player, forceUpdate)
local currentTime = tick()
-- Include player userid in cache key to separate per player
local playerKey = player and tostring(player.UserId) or "unknown"
local cacheKey = playerKey .. "_" .. tostring(part) .. "_" .. partName
if not forceUpdate and self._positionCache[cacheKey] and
currentTime - self._positionCache[cacheKey].time < 0.016 then
return self._positionCache[cacheKey].pos, self._positionCache[cacheKey].onScreen
end
local pos, onScreen = self.WTVP(part.Position)
self._positionCache[cacheKey] = {
pos = pos,
onScreen = onScreen,
time = currentTime
}
return pos, onScreen
end
--[[ Skeleton System ]]--
function MainESP:CreateSkeleton()
local skeleton = {
-- R15 and R6 compatible skeleton lines
HeadToNeck = self.CreateLine(),
NeckToRightUpperArm = self.CreateLine(),
NeckToLeftUpperArm = self.CreateLine(),
RightUpperArmToRightLowerArm = self.CreateLine(),
LeftUpperArmToLeftLowerArm = self.CreateLine(),
RightLowerArmToRightHand = self.CreateLine(),
LeftLowerArmToLeftHand = self.CreateLine(),
NeckToLowerTorso = self.CreateLine(),
LowerTorsoToRightUpperLeg = self.CreateLine(),
LowerTorsoToLeftUpperLeg = self.CreateLine(),
RightUpperLegToRightLowerLeg = self.CreateLine(),
LeftUpperLegToLeftLowerLeg = self.CreateLine(),
RightLowerLegToRightFoot = self.CreateLine(),
LeftLowerLegToLeftFoot = self.CreateLine(),
}
return skeleton
end
function MainESP:UpdateSkeleton(playerESP, player, onScreen)
if not self.Options.Skeleton or not onScreen or not player.Character then
-- Hide all skeleton lines
for _, line in pairs(playerESP.Skeleton) do
if line and line.Visible ~= nil then
line.Visible = false
end
end
return
end
local character = player.Character
local head = character:FindFirstChild("Head")
if not head then
-- Hide all skeleton lines if no head
for _, line in pairs(playerESP.Skeleton) do
if line and line.Visible ~= nil then
line.Visible = false
end
end
return
end
local color = self:GetColor(player, self.Options.UseTeamColor, self.Options.Rainbow, self.Options.Color)
local headPos = MainESP:GetCachedPosition(head, "Head", player)
-- Check if R15 or R6
if character:FindFirstChild("UpperTorso") then
-- R15 Character
local upperTorso = character:FindFirstChild("UpperTorso")
local lowerTorso = character:FindFirstChild("LowerTorso")
local rightUpperArm = character:FindFirstChild("RightUpperArm")
local rightLowerArm = character:FindFirstChild("RightLowerArm")
local leftUpperArm = character:FindFirstChild("LeftUpperArm")
local leftLowerArm = character:FindFirstChild("LeftLowerArm")
local rightUpperLeg = character:FindFirstChild("RightUpperLeg")
local rightLowerLeg = character:FindFirstChild("RightLowerLeg")
local rightFoot = character:FindFirstChild("RightFoot")
local leftUpperLeg = character:FindFirstChild("LeftUpperLeg")
local leftLowerLeg = character:FindFirstChild("LeftLowerLeg")
local leftFoot = character:FindFirstChild("LeftFoot")
if upperTorso and lowerTorso and rightUpperArm and rightLowerArm and
leftUpperArm and leftLowerArm and rightUpperLeg and rightLowerLeg and
rightFoot and leftUpperLeg and leftLowerLeg and leftFoot then
local upperTorsoPos = MainESP:GetCachedPosition(upperTorso, "UpperTorso", player)
local lowerTorsoPos = MainESP:GetCachedPosition(lowerTorso, "LowerTorso", player)
local rightUpperArmPos = MainESP:GetCachedPosition(rightUpperArm, "RightUpperArm", player)
local rightLowerArmPos = MainESP:GetCachedPosition(rightLowerArm, "RightLowerArm", player)
local leftUpperArmPos = MainESP:GetCachedPosition(leftUpperArm, "LeftUpperArm", player)
local leftLowerArmPos = MainESP:GetCachedPosition(leftLowerArm, "LeftLowerArm", player)
local rightUpperLegPos = MainESP:GetCachedPosition(rightUpperLeg, "RightUpperLeg", player)
local rightLowerLegPos = MainESP:GetCachedPosition(rightLowerLeg, "RightLowerLeg", player)
local rightFootPos = MainESP:GetCachedPosition(rightFoot, "RightFoot", player)
local leftUpperLegPos = MainESP:GetCachedPosition(leftUpperLeg, "LeftUpperLeg", player)
local leftLowerLegPos = MainESP:GetCachedPosition(leftLowerLeg, "LeftLowerLeg", player)
local leftFootPos = MainESP:GetCachedPosition(leftFoot, "LeftFoot", player)
-- Calculate neck position (between head and upper torso)
local neckPos = Vector2.new(upperTorsoPos.X, (headPos.Y + upperTorsoPos.Y) / 2)
-- Head to Neck
playerESP.Skeleton.HeadToNeck.From = Vector2.new(headPos.X, headPos.Y)
playerESP.Skeleton.HeadToNeck.To = neckPos
playerESP.Skeleton.HeadToNeck.Color = color
playerESP.Skeleton.HeadToNeck.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.HeadToNeck.Visible = true
-- Neck to Arms
playerESP.Skeleton.NeckToRightUpperArm.From = neckPos
playerESP.Skeleton.NeckToRightUpperArm.To = Vector2.new(rightUpperArmPos.X, rightUpperArmPos.Y)
playerESP.Skeleton.NeckToRightUpperArm.Color = color
playerESP.Skeleton.NeckToRightUpperArm.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.NeckToRightUpperArm.Visible = true
playerESP.Skeleton.NeckToLeftUpperArm.From = neckPos
playerESP.Skeleton.NeckToLeftUpperArm.To = Vector2.new(leftUpperArmPos.X, leftUpperArmPos.Y)
playerESP.Skeleton.NeckToLeftUpperArm.Color = color
playerESP.Skeleton.NeckToLeftUpperArm.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.NeckToLeftUpperArm.Visible = true
-- Upper to Lower Arms
playerESP.Skeleton.RightUpperArmToRightLowerArm.From = Vector2.new(rightUpperArmPos.X, rightUpperArmPos.Y)
playerESP.Skeleton.RightUpperArmToRightLowerArm.To = Vector2.new(rightLowerArmPos.X, rightLowerArmPos.Y)
playerESP.Skeleton.RightUpperArmToRightLowerArm.Color = color
playerESP.Skeleton.RightUpperArmToRightLowerArm.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.RightUpperArmToRightLowerArm.Visible = true
playerESP.Skeleton.LeftUpperArmToLeftLowerArm.From = Vector2.new(leftUpperArmPos.X, leftUpperArmPos.Y)
playerESP.Skeleton.LeftUpperArmToLeftLowerArm.To = Vector2.new(leftLowerArmPos.X, leftLowerArmPos.Y)
playerESP.Skeleton.LeftUpperArmToLeftLowerArm.Color = color
playerESP.Skeleton.LeftUpperArmToLeftLowerArm.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LeftUpperArmToLeftLowerArm.Visible = true
-- Neck to Lower Torso
playerESP.Skeleton.NeckToLowerTorso.From = neckPos
playerESP.Skeleton.NeckToLowerTorso.To = Vector2.new(lowerTorsoPos.X, lowerTorsoPos.Y)
playerESP.Skeleton.NeckToLowerTorso.Color = color
playerESP.Skeleton.NeckToLowerTorso.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.NeckToLowerTorso.Visible = true
-- Lower Torso to Legs
playerESP.Skeleton.LowerTorsoToRightUpperLeg.From = Vector2.new(lowerTorsoPos.X, lowerTorsoPos.Y)
playerESP.Skeleton.LowerTorsoToRightUpperLeg.To = Vector2.new(rightUpperLegPos.X, rightUpperLegPos.Y)
playerESP.Skeleton.LowerTorsoToRightUpperLeg.Color = color
playerESP.Skeleton.LowerTorsoToRightUpperLeg.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LowerTorsoToRightUpperLeg.Visible = true
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.From = Vector2.new(lowerTorsoPos.X, lowerTorsoPos.Y)
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.To = Vector2.new(leftUpperLegPos.X, leftUpperLegPos.Y)
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.Color = color
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.Visible = true
-- Upper to Lower Legs
playerESP.Skeleton.RightUpperLegToRightLowerLeg.From = Vector2.new(rightUpperLegPos.X, rightUpperLegPos.Y)
playerESP.Skeleton.RightUpperLegToRightLowerLeg.To = Vector2.new(rightLowerLegPos.X, rightLowerLegPos.Y)
playerESP.Skeleton.RightUpperLegToRightLowerLeg.Color = color
playerESP.Skeleton.RightUpperLegToRightLowerLeg.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.RightUpperLegToRightLowerLeg.Visible = true
playerESP.Skeleton.LeftUpperLegToLeftLowerLeg.From = Vector2.new(leftUpperLegPos.X, leftUpperLegPos.Y)
playerESP.Skeleton.LeftUpperLegToLeftLowerLeg.To = Vector2.new(leftLowerLegPos.X, leftLowerLegPos.Y)
playerESP.Skeleton.LeftUpperLegToLeftLowerLeg.Color = color
playerESP.Skeleton.LeftUpperLegToLeftLowerLeg.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LeftUpperLegToLeftLowerLeg.Visible = true
-- Lower Legs to Feet
playerESP.Skeleton.RightLowerLegToRightFoot.From = Vector2.new(rightLowerLegPos.X, rightLowerLegPos.Y)
playerESP.Skeleton.RightLowerLegToRightFoot.To = Vector2.new(rightFootPos.X, rightFootPos.Y)
playerESP.Skeleton.RightLowerLegToRightFoot.Color = color
playerESP.Skeleton.RightLowerLegToRightFoot.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.RightLowerLegToRightFoot.Visible = true
playerESP.Skeleton.LeftLowerLegToLeftFoot.From = Vector2.new(leftLowerLegPos.X, leftLowerLegPos.Y)
playerESP.Skeleton.LeftLowerLegToLeftFoot.To = Vector2.new(leftFootPos.X, leftFootPos.Y)
playerESP.Skeleton.LeftLowerLegToLeftFoot.Color = color
playerESP.Skeleton.LeftLowerLegToLeftFoot.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LeftLowerLegToLeftFoot.Visible = true
-- Handle hands if they exist
if character:FindFirstChild("RightHand") and character:FindFirstChild("LeftHand") then
local rightHand = character.RightHand
local leftHand = character.LeftHand
local rightHandPos = MainESP:GetCachedPosition(rightHand, "RightHand", player)
local leftHandPos = MainESP:GetCachedPosition(leftHand, "LeftHand", player)
playerESP.Skeleton.RightLowerArmToRightHand.From = Vector2.new(rightLowerArmPos.X, rightLowerArmPos.Y)
playerESP.Skeleton.RightLowerArmToRightHand.To = Vector2.new(rightHandPos.X, rightHandPos.Y)
playerESP.Skeleton.RightLowerArmToRightHand.Color = color
playerESP.Skeleton.RightLowerArmToRightHand.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.RightLowerArmToRightHand.Visible = true
playerESP.Skeleton.LeftLowerArmToLeftHand.From = Vector2.new(leftLowerArmPos.X, leftLowerArmPos.Y)
playerESP.Skeleton.LeftLowerArmToLeftHand.To = Vector2.new(leftHandPos.X, leftHandPos.Y)
playerESP.Skeleton.LeftLowerArmToLeftHand.Color = color
playerESP.Skeleton.LeftLowerArmToLeftHand.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LeftLowerArmToLeftHand.Visible = true
else
-- Hide hand connections if hands don't exist
playerESP.Skeleton.RightLowerArmToRightHand.Visible = false
playerESP.Skeleton.LeftLowerArmToLeftHand.Visible = false
end
else
-- Hide all if missing parts
for _, line in pairs(playerESP.Skeleton) do
if line and line.Visible ~= nil then
line.Visible = false
end
end
end
else
-- R6 Character
local torso = character:FindFirstChild("Torso")
local rightArm = character:FindFirstChild("Right Arm")
local leftArm = character:FindFirstChild("Left Arm")
local rightLeg = character:FindFirstChild("Right Leg")
local leftLeg = character:FindFirstChild("Left Leg")
if torso and rightArm and leftArm and rightLeg and leftLeg then
local rootPos = MainESP:GetCachedPosition(torso, "Torso", player)
local rightArmPos = MainESP:GetCachedPosition(rightArm, "RightArm", player)
local leftArmPos = MainESP:GetCachedPosition(leftArm, "LeftArm", player)
local rightLegPos = MainESP:GetCachedPosition(rightLeg, "RightLeg", player)
local leftLegPos = MainESP:GetCachedPosition(leftLeg, "LeftLeg", player)
-- Calculate neck position (between head and torso)
local neckPos = Vector2.new(rootPos.X, (headPos.Y + rootPos.Y) / 2)
-- Head to Neck
playerESP.Skeleton.HeadToNeck.From = Vector2.new(headPos.X, headPos.Y)
playerESP.Skeleton.HeadToNeck.To = neckPos
playerESP.Skeleton.HeadToNeck.Color = color
playerESP.Skeleton.HeadToNeck.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.HeadToNeck.Visible = true
-- Neck to Arms
playerESP.Skeleton.NeckToRightUpperArm.From = neckPos
playerESP.Skeleton.NeckToRightUpperArm.To = Vector2.new(rightArmPos.X, rightArmPos.Y)
playerESP.Skeleton.NeckToRightUpperArm.Color = color
playerESP.Skeleton.NeckToRightUpperArm.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.NeckToRightUpperArm.Visible = true
playerESP.Skeleton.NeckToLeftUpperArm.From = neckPos
playerESP.Skeleton.NeckToLeftUpperArm.To = Vector2.new(leftArmPos.X, leftArmPos.Y)
playerESP.Skeleton.NeckToLeftUpperArm.Color = color
playerESP.Skeleton.NeckToLeftUpperArm.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.NeckToLeftUpperArm.Visible = true
-- Neck to Torso
playerESP.Skeleton.NeckToLowerTorso.From = neckPos
playerESP.Skeleton.NeckToLowerTorso.To = Vector2.new(rootPos.X, rootPos.Y)
playerESP.Skeleton.NeckToLowerTorso.Color = color
playerESP.Skeleton.NeckToLowerTorso.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.NeckToLowerTorso.Visible = true
-- Torso to Legs
playerESP.Skeleton.LowerTorsoToRightUpperLeg.From = Vector2.new(rootPos.X, rootPos.Y)
playerESP.Skeleton.LowerTorsoToRightUpperLeg.To = Vector2.new(rightLegPos.X, rightLegPos.Y)
playerESP.Skeleton.LowerTorsoToRightUpperLeg.Color = color
playerESP.Skeleton.LowerTorsoToRightUpperLeg.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LowerTorsoToRightUpperLeg.Visible = true
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.From = Vector2.new(rootPos.X, rootPos.Y)
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.To = Vector2.new(leftLegPos.X, leftLegPos.Y)
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.Color = color
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.Thickness = self.Options.SkeletonThickness
playerESP.Skeleton.LowerTorsoToLeftUpperLeg.Visible = true
-- Hide R15-specific connections for R6
playerESP.Skeleton.RightUpperArmToRightLowerArm.Visible = false
playerESP.Skeleton.LeftUpperArmToLeftLowerArm.Visible = false
playerESP.Skeleton.RightLowerArmToRightHand.Visible = false
playerESP.Skeleton.LeftLowerArmToLeftHand.Visible = false
playerESP.Skeleton.RightUpperLegToRightLowerLeg.Visible = false
playerESP.Skeleton.LeftUpperLegToLeftLowerLeg.Visible = false
playerESP.Skeleton.RightLowerLegToRightFoot.Visible = false
playerESP.Skeleton.LeftLowerLegToLeftFoot.Visible = false
else
-- Hide all if missing parts
for _, line in pairs(playerESP.Skeleton) do
if line and line.Visible ~= nil then
line.Visible = false
end
end
end
end
end
--[[ Main ESP Creation ]]--
function MainESP:CreateESP(player, object, customName, customPredicate)
if player then
local PlayerESP = {
IsPlayer = true,
Box = self.CreateBox(),
Health = self.CreateBox(),
Tracer = self.CreateLine(),
Name = self.CreateText(),
Distance = self.CreateText(),
Direction = self.CreateLine(),
Skeleton = self:CreateSkeleton(),
Connections = {},
_BoxDimensions = { width = 0, height = 0, x = 0, y = 0 },
}
if game.PlaceId == 606849621 then
PlayerESP.Bounties = self.CreateText()
end
self.Container[player] = PlayerESP
elseif object then
local ObjectESP = {
Info = self.CreateText(),
Tracer = self.CreateLine(),
Connections = {},
}
self.Container[object] = ObjectESP
ObjectESP.Connections.AncestryConnection = object.AncestryChanged:Connect(function()
if not object:IsDescendantOf(workspace) then
self:RemoveESP(object)
end
end)
ObjectESP.Connections.RenderConnection = Services.RunService.RenderStepped:Connect(function()
if not object:IsDescendantOf(workspace) or
(customPredicate and not customPredicate(object)) then
ObjectESP.Info.Visible = false
ObjectESP.Tracer.Visible = false
return
end
if self.ObjectOptions.Enabled then
local rootPos, onScreen = self.WTVP(object.Position)
local color = self:GetColor(nil, false, self.ObjectOptions.Rainbow, self.ObjectOptions.Color)
-- Object Tracer
if self.ObjectOptions.Tracer and rootPos.Z > 0 then
ObjectESP.Tracer.From = self.TracerOrigins[self.ObjectOptions.TracerOrigin]
ObjectESP.Tracer.To = Vector2.new(rootPos.X, rootPos.Y)
ObjectESP.Tracer.Color = color
ObjectESP.Tracer.Thickness = self.ObjectOptions.TracerThickness
ObjectESP.Tracer.Visible = true
else
ObjectESP.Tracer.Visible = false
end
-- Object Info
if onScreen and (self.ObjectOptions.Name or self.ObjectOptions.Distance) then
local name = self.ObjectOptions.Name and (customName or object.Name) or ""
local distance = ""
if self.ObjectOptions.Distance then
local dist = math.round(self.GetDistanceFromPlayer(LocalPlayer, object.Position))
distance = "\n[" .. tostring(dist) .. " studs]"
end
ObjectESP.Info.Text = name .. distance
ObjectESP.Info.Position = Vector2.new(rootPos.X, rootPos.Y)
ObjectESP.Info.Color = color
ObjectESP.Info.Font = self.ObjectOptions.Font
ObjectESP.Info.Size = self.ObjectOptions.FontSize
ObjectESP.Info.Outline = self.ObjectOptions.TextOutline
ObjectESP.Info.OutlineColor = Color3.fromRGB(0, 0, 0)
ObjectESP.Info.Visible = true
else
ObjectESP.Info.Visible = false
end
else
ObjectESP.Info.Visible = false
ObjectESP.Tracer.Visible = false
end
end)
end
end
function MainESP:HidePlayerESP(playerESP)
for elementName, element in pairs(playerESP) do
if elementName == "Skeleton" then
for _, line in pairs(element) do
line.Visible = false
end
elseif elementName ~= "Connections" and elementName ~= "IsPlayer" then
element.Visible = false
end
end
end
function MainESP:RemoveESP(value)
local container = self.Container[value]
if not container then return end
-- Clear caches more efficiently
local playerName = type(value) == "userdata" and value.Name or tostring(value)
-- Remove all cache entries for this player
for key in pairs(self._colorCache) do
if key:find(playerName) then
self._colorCache[key] = nil
end
end
for key in pairs(self._positionCache) do
if key:find(playerName) then
self._positionCache[key] = nil
end
end
-- Disconnect connections (only for objects)
if container.Connections then
for _, connection in pairs(container.Connections) do
if connection and connection.Connected then
connection:Disconnect()
end
end
container.Connections = nil
end
-- Remove drawing objects safely
for elementName, element in pairs(container) do
pcall(function()
for _, line in pairs(element) do
pcall(function() line:Destroy() end)
end
end)
pcall(function() element:Destroy() end)
end
self.Container[value] = nil
end
local ESPPerformance = {
lastUpdate = 0,
interval = 1/45, -- Start with reasonable update rate (45 FPS)
-- FPS averaging system
fpsHistory = {},
fpsHistorySize = 60, -- Average over 60 frames
fpsSum = 0,
averageFPS = 60,
lastOptimize = 0,
-- Performance thresholds
targetFPS = 55, -- Target to maintain above this FPS
minInterval = 1/30, -- Min ESP update rate (30 FPS)
maxInterval = 1/120, -- Max ESP update rate (120 FPS)
-- Smoothing factors
adjustmentRate = 0.1, -- How aggressively to adjust (0.1 = 10% per adjustment)
stabilityThreshold = 10, -- FPS must change by this amount to trigger adjustment
}
local function updateFPSAverage()
local currentFPS = math.min(1 / Services.Stats.FrameTime, 200)
-- Add new FPS to history
table.insert(ESPPerformance.fpsHistory, currentFPS)
ESPPerformance.fpsSum = ESPPerformance.fpsSum + currentFPS
-- Remove old FPS if history is too large (FIXED: Better cleanup)
if #ESPPerformance.fpsHistory > ESPPerformance.fpsHistorySize then
local overflow = #ESPPerformance.fpsHistory - ESPPerformance.fpsHistorySize
for _ = 1, overflow do
ESPPerformance.fpsSum -= table.remove(ESPPerformance.fpsHistory, 1)
end
end
-- Calculate average (prevent division by zero)
if #ESPPerformance.fpsHistory > 0 then
ESPPerformance.averageFPS = ESPPerformance.fpsSum / #ESPPerformance.fpsHistory
end
end
local globalRenderConnection = Services.RunService.RenderStepped:Connect(function()
local now = tick()
-- Update FPS average every frame
updateFPSAverage()
-- Cleanup caches periodically
CacheManager:CleanupCaches()
-- Optimize every 0.5 seconds for stability
if now - ESPPerformance.lastOptimize >= 0.5 then
local currentAvgFPS = ESPPerformance.averageFPS
-- Only adjust if we have enough history for reliable average
if #ESPPerformance.fpsHistory >= math.min(10, ESPPerformance.fpsHistorySize) then
if currentAvgFPS < ESPPerformance.targetFPS - ESPPerformance.stabilityThreshold then
-- print("reducing interval")
-- FPS too low, reduce ESP update rate
local adjustment = 1 + ESPPerformance.adjustmentRate
ESPPerformance.interval = math.min(ESPPerformance.interval * adjustment, ESPPerformance.minInterval)
elseif currentAvgFPS > ESPPerformance.targetFPS + ESPPerformance.stabilityThreshold then
-- print("increasing interval")
-- FPS good, can increase ESP update rate
local adjustment = 1 - ESPPerformance.adjustmentRate
ESPPerformance.interval = math.max(ESPPerformance.interval * adjustment, ESPPerformance.maxInterval)
end
-- If FPS is within threshold, don't adjust (stability)
end
ESPPerformance.lastOptimize = now
-- Debug output (remove in production)
-- print(string.format("ESP: Avg FPS: %.1f, Interval: %.3f, Update Rate: %.1f",
-- currentAvgFPS, ESPPerformance.interval, 1/ESPPerformance.interval))
end
-- Frame limiting with smooth intervals
if now - ESPPerformance.lastUpdate < ESPPerformance.interval then
return
end
ESPPerformance.lastUpdate = now
-- Update all players
for player, playerESP in pairs(MainESP.Container) do
if playerESP.IsPlayer then
-- Skip if player is invalid or destroyed
if not player or not player.Parent then
-- Clean up invalid player
MainESP:RemoveESP(player)
continue
end
-- Distance-based culling
local shouldRender, distance = CullingSystem:ShouldRenderPlayer(player)
if not shouldRender then
MainESP:HidePlayerESP(playerESP)
continue
end
-- Get detail level for distance-based optimization
local detailLevel = CullingSystem:GetDetailLevel(distance)
-- Move the entire player update logic here
if MainESP.Options.Enabled and
(not MainESP.Options.TeamCheck or not player.Team or LocalPlayer.Team ~= player.Team) and
MainESP:PlayerAlive(player) and player.Character then
local character = player.Character
local rootPart = character:FindFirstChild("UpperTorso") or character:FindFirstChild("Torso")
local head = character:FindFirstChild("Head")
local characterSizeHalved = select(2, character:GetBoundingBox()) / 2
if not rootPart or not head then
MainESP:HidePlayerESP(playerESP)
continue
end
local rootPos, onScreen = MainESP:GetCachedPosition(rootPart, "RootPart", player, true)
local headPos = MainESP:GetCachedPosition(head, "Head", player)
local topPos = MainESP.WTVP(rootPart.Position + Vector3.new(0, characterSizeHalved.Y, 0))
local bottomPos = MainESP.WTVP(rootPart.Position - Vector3.new(0, characterSizeHalved.Y, 0))
local color = MainESP:GetColor(player, MainESP.Options.UseTeamColor, MainESP.Options.Rainbow, MainESP.Options.Color)
local boxWidth = 3000 / rootPos.Z
local boxHeight = topPos.Y - bottomPos.Y
local boxX = rootPos.X - boxWidth / 2
local boxY = rootPos.Y - boxHeight / 2
playerESP._BoxDimensions.width = boxWidth
playerESP._BoxDimensions.height = boxHeight
playerESP._BoxDimensions.x = boxX
playerESP._BoxDimensions.y = boxY
local dims = playerESP._BoxDimensions
local infoX
-- Skip expensive operations for far players
if detailLevel == "minimal" then
-- Name/Distance ESP
if MainESP.Options.Name and onScreen then
local dynamicOffsetY = dims.height * 1.1
if not infoX then
infoX = dims.x + dims.width / 2
end
playerESP.Name.Text = player.DisplayName
if MainESP.Options.Distance and onScreen then
playerESP.Name.Text ..= "\n" .. "[" .. tostring(math.round(distance)) .. " studs]"
end
playerESP.Name.Position = Vector2.new(infoX, topPos.Y - 25)
playerESP.Name.Color = color
playerESP.Name.Font = MainESP.Options.Font
playerESP.Name.Size = MainESP.Options.FontSize
playerESP.Name.Outline = MainESP.Options.TextOutline
playerESP.Name.OutlineColor = Color3.fromRGB(0, 0, 0)
playerESP.Name.Visible = true
else
playerESP.Name.Visible = false
end
-- Hide other elements
playerESP.Box.Visible = false
playerESP.Health.Visible = false
playerESP.Distance.Visible = false
playerESP.Direction.Visible = false
playerESP.Tracer.Visible = false
for _, line in pairs(playerESP.Skeleton) do
line.Visible = false
end
continue
end
-- Box ESP (full/medium detail)
if MainESP.Options.Box and onScreen then
playerESP.Box.Size = Vector2.new(boxWidth, boxHeight)
playerESP.Box.Position = Vector2.new(boxX, boxY)
playerESP.Box.Color = color
playerESP.Box.Thickness = MainESP.Options.BoxThickness
playerESP.Box.Visible = true
else
playerESP.Box.Visible = false
end
local dims = playerESP._BoxDimensions
-- Health ESP (full detail)
if MainESP.Options.Health and onScreen and playerESP.Box.Visible and detailLevel == "full" then
local health, maxHealth = MainESP.GetHealth(player)
local healthPerc = health / maxHealth
local healthWidth = dims.width * 0.15
local healthHeight = dims.height * healthPerc
local offsetX = dims.width * 0.150
playerESP.Health.Size = Vector2.new(healthWidth, healthHeight)
playerESP.Health.Position = Vector2.new(dims.x - offsetX, dims.y)
playerESP.Health.Color = Color3.fromHSV(healthPerc * 0.3, 1, 1)
playerESP.Health.Filled = true
playerESP.Health.Visible = true
else
playerESP.Health.Visible = false
end
-- Tracer ESP (full detail)
if MainESP.Options.Tracer and rootPos.Z > 0 and detailLevel == "full" then
local upperTorso, neckPos = character:FindFirstChild("UpperTorso")
if upperTorso then
local upperTorsoPos = MainESP:GetCachedPosition(upperTorso, "UpperTorso", player)
neckPos = Vector2.new(upperTorsoPos.X, (headPos.Y + upperTorsoPos.Y) / 2)
else
neckPos = Vector2.new(rootPos.X, (headPos.Y + rootPos.Y) / 2)
end
playerESP.Tracer.From = MainESP.TracerOrigins[MainESP.Options.TracerOrigin]
playerESP.Tracer.To = Vector2.new(neckPos.X, neckPos.Y)
playerESP.Tracer.Color = color
playerESP.Tracer.Thickness = MainESP.Options.TracerThickness
playerESP.Tracer.Visible = true
else
playerESP.Tracer.Visible = false
end
-- Name ESP (full/medium detail)
if MainESP.Options.Name and onScreen then
if not infoX then
infoX = dims.x + dims.width / 2
end
playerESP.Name.Text = player.DisplayName
playerESP.Name.Position = Vector2.new(infoX, topPos.Y - 25)
playerESP.Name.Color = color
playerESP.Name.Font = MainESP.Options.Font
playerESP.Name.Size = MainESP.Options.FontSize
playerESP.Name.Outline = MainESP.Options.TextOutline
playerESP.Name.OutlineColor = Color3.fromRGB(0, 0, 0)
playerESP.Name.Visible = true
else
playerESP.Name.Visible = false
end
-- jb bounties system (WARNING: poorly wrtitten)
if MainESP.Options.Bounties and onScreen and game.PlaceId == 606849621 then
if not infoX then
infoX = dims.x + dims.width / 2
end
local getUsernameFromDisplayName = (function(name)
for i,v in next, game:GetService("Players"):GetPlayers() do
if v.DisplayName == name then
return v.Name
end
end
return nil
end)
local format = (function(displayname)
local uh = getUsernameFromDisplayName(displayname)
if uh then
local module = require(game:GetService("ReplicatedStorage").Bounty.BountyBoardService)
for i,v in next, module.Bounties do
if v.Name == uh then
return "Bounty: ".. tostring(v.Bounty)
end
end
end
return ""
end)
playerESP.Bounties.Text = format(player.DisplayName)
playerESP.Bounties.Position = Vector2.new(infoX, topPos.Y - getgenv().test)
playerESP.Bounties.Color = Color3.fromRGB(255, 255, 0)
playerESP.Bounties.Font = MainESP.Options.Font
playerESP.Bounties.Size = MainESP.Options.FontSize
playerESP.Bounties.Outline = MainESP.Options.TextOutline
playerESP.Bounties.OutlineColor = Color3.fromRGB(0, 0, 0)
playerESP.Bounties.Visible = true
else
playerESP.Bounties.Visible = false
end
-- Distance ESP (full/medium detail)
if MainESP.Options.Distance and onScreen then
local dynamicOffsetY = dims.height * 0.1
if not infoX then
infoX = dims.x + dims.width / 2
end
playerESP.Distance.Text = "[" .. tostring(math.round(distance)) .. " studs]"
playerESP.Distance.Position = Vector2.new(infoX, dims.y - dynamicOffsetY)
playerESP.Distance.Color = color
playerESP.Distance.Font = MainESP.Options.Font
playerESP.Distance.Size = MainESP.Options.FontSize
playerESP.Distance.Outline = MainESP.Options.TextOutline
playerESP.Distance.OutlineColor = Color3.fromRGB(0, 0, 0)
playerESP.Distance.Visible = true
else
playerESP.Distance.Visible = false
end
-- Direction ESP (full detail)
if MainESP.Options.Direction and onScreen and detailLevel == "full" then
local offset = MainESP.WTVP((head.CFrame * CFrame.new(0, 0, -head.Size.Z)).Position)
playerESP.Direction.From = Vector2.new(headPos.X, headPos.Y)
playerESP.Direction.To = Vector2.new(offset.X, offset.Y)
playerESP.Direction.Color = color
playerESP.Direction.Thickness = MainESP.Options.DirectionThickness
playerESP.Direction.Visible = true
else
playerESP.Direction.Visible = false
end
-- Skeleton ESP (full detail)
MainESP:UpdateSkeleton(playerESP, player, onScreen and detailLevel == "full")
else
MainESP:HidePlayerESP(playerESP)
end
end
end
end)
--[[ Game Compatibility ]]--
local CompatibilityFuncs = {
[292439477] = function() -- Phantom Forces
for _, v in pairs(getgc(true)) do
if type(v) == "function" and islclosure(v) then
local constants = getconstants(v)
if getinfo(v).name == "gethealth" and table.find(constants, "alive") then
MainESP.GetHealth = v
end