-
Notifications
You must be signed in to change notification settings - Fork 0
/
Base.lua
1001 lines (816 loc) · 30.9 KB
/
Base.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
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
--[[
Information:
Contains the classes needed for the ESP. Additional logic is needed to make it functional
Note:
- This only works for Synapse V3, I may make a v2 -> v3 converter in the future
]]
-- // Services
local Workspace = game:GetService("Workspace")
-- // Vars
local ZeroVector2 = Vector2.zero
local DefaultFont = DrawFont.RegisterDefault("SegoeUI", {})
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)
}
-- // CIELUV - https://gist.github.com/Fraktality/8a833e3bea7471a05e388062efaf9886
local CIELUV = {}
do
-- Combines two colors in CIELUV space.
-- function<function<Color3 result>(float t)>(Color3 fromColor, Color3 toColor)
-- https://www.w3.org/Graphics/Color/srgb
local clamp = math.clamp
local C3 = Color3.new
local black = C3(0, 0, 0)
-- Convert from linear RGB to scaled CIELUV
function CIELUV.RgbToLuv13(c)
assert(typeof(c) == "Color3", "invalid type for c (expected Color3)")
local r, g, b = c.r, c.g, c.b
-- Apply inverse gamma correction
r = r < 0.0404482362771076 and r/12.92 or 0.87941546140213*(r + 0.055)^2.4
g = g < 0.0404482362771076 and g/12.92 or 0.87941546140213*(g + 0.055)^2.4
b = b < 0.0404482362771076 and b/12.92 or 0.87941546140213*(b + 0.055)^2.4
-- sRGB->XYZ->CIELUV
local y = 0.2125862307855956*r + 0.71517030370341085*g + 0.0722004986433362*b
local z = 3.6590806972265883*r + 11.4426895800574232*g + 4.1149915024264843*b
local l = y > 0.008856451679035631 and 116*y^(1/3) - 16 or 903.296296296296*y
if z > 1e-15 then
local x = 0.9257063972951867*r - 0.8333736323779866*g - 0.09209820666085898*b
return l, l*x/z, l*(9*y/z - 0.46832)
else
return l, -0.19783*l, -0.46832*l
end
end
function CIELUV.Lerp(t, c0, c1)
assert(typeof(t) == "number", "invalid type for t (expected number)")
assert(typeof(c0) == "Color3", "invalid type for c0 (expected Color3)")
assert(typeof(c1) == "Color3", "invalid type for c1 (expected Color3)")
local l0, u0, v0 = CIELUV.RgbToLuv13(c0)
local l1, u1, v1 = CIELUV.RgbToLuv13(c1)
-- Interpolate
local l = (1 - t)*l0 + t*l1
if l < 0.0197955 then
return black
end
local u = ((1 - t)*u0 + t*u1)/l + 0.19783
local v = ((1 - t)*v0 + t*v1)/l + 0.46832
-- CIELUV->XYZ
local y = (l + 16)/116
y = y > 0.206896551724137931 and y*y*y or 0.12841854934601665*y - 0.01771290335807126
local x = y*u/v
local z = y*((3 - 0.75*u)/v - 5)
-- XYZ->linear sRGB
local r = 7.2914074*x - 1.5372080*y - 0.4986286*z
local g = -2.1800940*x + 1.8757561*y + 0.0415175*z
local b = 0.1253477*x - 0.2040211*y + 1.0569959*z
-- Adjust for the lowest out-of-bounds component
if r < 0 and r < g and r < b then
r, g, b = 0, g - r, b - r
elseif g < 0 and g < b then
r, g, b = r - g, 0, b - g
elseif b < 0 then
r, g, b = r - b, g - b, 0
end
return C3(
-- Apply gamma correction and clamp the result
clamp(r < 3.1306684425e-3 and 12.92*r or 1.055*r^(1/2.4) - 0.055, 0, 1),
clamp(g < 3.1306684425e-3 and 12.92*g or 1.055*g^(1/2.4) - 0.055, 0, 1),
clamp(b < 3.1306684425e-3 and 12.92*b or 1.055*b^(1/2.4) - 0.055, 0, 1)
)
end
end
-- // Utilities
local Utilities = {}
do
-- // Gets the current camera
function Utilities.GetCurrentCamera()
return Workspace.CurrentCamera
end
-- // Applies operation to Vector2
function Utilities.ApplyVector2(Vector, f)
-- // Asserts
assert(typeof(Vector) == "Vector2", "invalid type for Vector (expected Vector2)")
assert(typeof(f) == "function", "invalid type for f (expected function)")
-- // Returns
return Vector2.new(f(Vector.X), f(Vector.Y))
end
-- // Combine two tables
function Utilities.CombineTables(Base, ToAdd)
-- // Default
Base = Base or {}
ToAdd = ToAdd or {}
-- // Loop through data we want to add
for i, v in pairs(ToAdd) do
-- // Recursive
local BaseValue = Base[i] or false
if (typeof(v) == "table" and typeof(BaseValue) == "table") then
Utilities.CombineTables(BaseValue, v)
continue
end
-- // Set
Base[i] = v
end
-- // Return
return Base
end
-- // Deep copying
function Utilities.DeepCopy(Original)
-- // Assert
assert(typeof(Original) == "table", "invalid type for Original (expected table)")
-- // Vars
local Copy = {}
-- // Loop through original
for i, v in pairs(Original) do
-- // Recursion if table
if (typeof(v) == "table") then
v = Utilities.DeepCopy(v)
end
-- // Set
Copy[i] = v
end
-- // Return the copy
return Copy
end
end
-- // Utilities - continued
do
-- // Converts Vector3 to Vector2
function Utilities.ConvertV3toV2(Vector)
-- // Convert if vector 3
local VectorType = typeof(Vector)
if (VectorType == "Vector3") then
return Vector2.new(Vector.X, Vector.Y)
end
assert(VectorType == "table", "invalid type for Vector (expected Vector3 or table)")
-- // Loop through all vectors
local Vectors = {}
for i, v in ipairs(Vector) do
Vectors[i] = Utilities.ConvertV3toV2(v)
end
-- // Return
return Vectors
end
-- // Gets the corners of a part (or bounding box)
function Utilities.CalculateCorners(PartCFrame, PartSize)
-- // Asserts
assert(typeof(PartCFrame) == "CFrame", "invalid type for PartCFrame (expected CFrame)")
assert(typeof(PartSize) == "Vector3", "invalid type for PartSize (expected Vector3)")
-- // Vars
local HalfSize = PartSize / 2
local Corners = table.create(#Vertices)
-- // Calculate each corner
for i, Vertex in ipairs(Vertices) do
Corners[i] = (PartCFrame + (HalfSize * Vertex)).Position
end
-- // Convert to screen
local Corners2D = worldtoscreen(Corners)
local Corners2DV2 = Utilities.ConvertV3toV2(Corners2D)
-- // Get min and max
local CurrentCamera = Utilities.GetCurrentCamera()
local MinPosition = CurrentCamera.ViewportSize:Min(unpack(Corners2DV2))
local MaxPosition = ZeroVector2:Max(unpack(Corners2DV2))
-- // Add data to table
local mathfloor = math.floor
local ApplyVector2 = Utilities.ApplyVector2
local Data = {
Corners = Corners2D,
Centre3D = PartCFrame.Position,
TopLeft = ApplyVector2(MinPosition, mathfloor),
TopRight = ApplyVector2(Vector2.new(MaxPosition.X, MinPosition.Y), mathfloor),
BottomLeft = ApplyVector2(Vector2.new(MinPosition.X, MaxPosition.Y), mathfloor),
BottomRight = ApplyVector2(MaxPosition, mathfloor),
}
-- // Get centre and onscreen
local CentrePos, OnScreen = CurrentCamera:WorldToViewportPoint(Data.Centre3D)
Data.Centre = CentrePos
Data.OnScreen = OnScreen
-- // Return
return Data
end
-- // Rotates a vector2
function Utilities.RotateVector2(Vector, Angle)
-- // Asserts
assert(typeof(Vector) == "Vector2", "invalid type for Vector (expected Vector2)")
assert(typeof(Angle) == "number", "invalid type for Angle (expected number)")
-- // Calculate the trig values
local CosValue = math.cos(Angle)
local SinValue = math.sin(Angle)
-- // Return the rotated vector
return Vector2.new(
(CosValue * Vector.X) - (SinValue * Vector.Y),
(SinValue * Vector.X) + (CosValue * Vector.Y)
)
end
-- // Sets a drawing object's properties
Utilities.IgnoredDrawingProperties = {"Type", "SubType"}
function Utilities.SetDrawingProperties(Object, Properties)
-- // Assets
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Set properties
for Property, Value in pairs(Properties) do
-- // Ignore if property is type
if (table.find(Utilities.IgnoredDrawingProperties, Property)) then
continue
end
-- // Set
Object[Property] = Value
end
-- // Return
return Object
end
-- // Creates a new drawing object
function Utilities.CreateDrawing(Properties)
-- // Assets
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local Object = getgenv()[Properties.Type].new()
-- // Return
return Utilities.SetDrawingProperties(Object, Properties)
end
end
-- // Base class. This is an abstract class used to build the rest, make sure to duplicate the constructor, update method, and others
local Base = {}
Base.__index = Base
Base.__type = "Base"
do
-- // Constructor
function Base.new(Data, Properties)
-- // Asserts and defaults
Data = Data or {}
Properties = Properties or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local self = setmetatable({}, Base)
-- // Vars
self.Objects = self:InitialiseObjects(Data, Properties)
-- // Return the object
return self
end
-- // Initialises the objects by using the properties
function Base:InitialiseObjects(Data, Properties)
-- // Asserts
Data = Data or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Vars
local Objects = {}
-- // Loop through the properties
for i, Property in pairs(Properties) do
-- // Check if table
if (typeof(Property) ~= "table") then
continue
end
-- // Create the object and add it
Objects[i] = Utilities.CreateDrawing(Property)
end
-- // Return
return Objects
end
-- // Destroys all of the objects
function Base:Destroy(TableObject)
-- // Asserts and Default
TableObject = TableObject or self.Objects
assert(typeof(TableObject) == "table", "invalid type for TableObject (expected table)")
-- // Loop through
for i, Object in pairs(TableObject) do
-- // Check if is a table
if (typeof(Object) == "table") then
self:Destroy(Object)
continue
end
-- // Destroy
Object:Remove()
TableObject[i] = nil
end
end
-- // Updates the properties of properties (assumes only main and outline)
function Base:Update(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Check for visibility
local IsVisible = self.Data.Enabled
-- // Vars
local MainData = {self.AdditionalData.ColorOpacity(self)}
local OutlineData = {self.AdditionalData.ColorOpacityOutline(self)}
-- // Set the properties
Utilities.SetDrawingProperties(self.Objects.Main, {
Color = MainData[1],
Opacity = MainData[2],
Visible = IsVisible
})
-- // Set properties
Utilities.SetDrawingProperties(self.Objects.Main, {
Color = OutlineData[1],
Opacity = OutlineData[2],
Visible = IsVisible and self.Data.OutlineEnabled
})
end
end
-- // Box (Square) Class
local BoxSquare = {}
BoxSquare.__index = BoxSquare
BoxSquare.__type = "BoxSquare"
setmetatable(BoxSquare, Base)
do
-- // Initialise box data
BoxSquare.DefaultData = {
Enabled = true,
OutlineEnabled = true
}
BoxSquare.DefaultProperties = {
Main = {
Type = "RectDynamic",
Thickness = 1,
Color = Color3.new(1, 0, 0),
Opacity = 1,
Outlined = true,
OutlineColor = Color3.new(0, 0, 0),
OutlineOpacity = 1,
OutlineThickness = 1,
Visible = false
}
}
-- // Constructor
function BoxSquare.new(Data, Properties)
-- // Default values and assert
Data = Data or {}
Properties = Properties or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local self = setmetatable({}, BoxSquare)
-- // Vars
self.Data = Utilities.CombineTables(Utilities.DeepCopy(BoxSquare.DefaultData), Data)
self.Properties = Utilities.CombineTables(Utilities.DeepCopy(BoxSquare.DefaultProperties), Properties)
-- // Make the object(s)
self.Objects = self:InitialiseObjects(self.Data, self.Properties)
-- // Return the object
return self
end
-- // Updates the properties
function BoxSquare:Update(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Check for visibility
local Data = self.Data
local Properties = Utilities.DeepCopy(self.Properties)
local IsVisible = Data.Enabled and Corners.OnScreen
local OutlineVisible = IsVisible and Data.OutlineEnabled
-- // Set the properties
Utilities.SetDrawingProperties(self.Objects.Main, Utilities.CombineTables(Properties.Main, {
Position = Corners.TopLeft,
BottomRight = Corners.BottomRight,
Outlined = OutlineVisible,
Visible = IsVisible
}))
end
end
-- // Tracer Class
local Tracer = {}
Tracer.__index = Tracer
Tracer.__type = "Tracer"
setmetatable(Tracer, Base)
do
-- // Initialise box data
Tracer.DefaultData = {
Enabled = true,
OutlineEnabled = true,
TracerOrigin = "Bottom" -- // Top, Middle, Bottom
}
Tracer.DefaultProperties = {
Main = {
Type = "LineDynamic",
Thickness = 1,
Color = Color3.new(1, 0, 0),
Opacity = 1,
Outlined = true,
OutlineColor = Color3.new(0, 0, 0),
OutlineOpacity = 1,
OutlineThickness = 1,
Visible = false,
}
}
-- // Constructor
function Tracer.new(Data, Properties)
-- // Default values and assert
Data = Data or {}
Properties = Properties or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local self = setmetatable({}, Tracer)
-- // Vars
self.Data = Utilities.CombineTables(Utilities.DeepCopy(Tracer.DefaultData), Data)
self.Properties = Utilities.CombineTables(Utilities.DeepCopy(Tracer.DefaultProperties), Properties)
-- // Make the object(s)
self.Objects = self:InitialiseObjects(self.Data, self.Properties)
-- // Return the object
return self
end
-- // Updates the properties
function Tracer:Update(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Check for visibility
local Data = self.Data
local Properties = Utilities.DeepCopy(self.Properties)
local IsVisible = Data.Enabled and Corners.OnScreen
local OutlineVisible = IsVisible and Data.OutlineEnabled
-- // Vars
local ViewportSize = Utilities.GetCurrentCamera().ViewportSize
local To = (Corners.BottomLeft + Corners.BottomRight) / 2
local From =
Data.TracerOrigin == "Middle" and ViewportSize / 2 or
Data.TracerOrigin == "Top" and ViewportSize * Vector2.new(0.5, 0) or
Data.TracerOrigin == "Bottom" and ViewportSize * Vector2.new(0.5, 1)
-- // Set the properties
Utilities.SetDrawingProperties(self.Objects.Main, Utilities.CombineTables(Properties.Main, {
To = To,
From = From,
Outlined = OutlineVisible,
Visible = IsVisible
}))
end
end
-- // Header (name) Class
local Header = {}
Header.__index = Header
Header.__type = "Header"
setmetatable(Header, Base)
do
-- // Initialise box data
Header.DefaultData = {
Enabled = true,
OutlineEnabled = true,
Type = "Name", -- // Options: Name, Distance, Weapon, MiscTop, MiscBottom
Value = "N/A", -- // Name -> "PLAYERNAME", Distance -> 12.0, Weapon -> "AK-47"
Formats = {
Name = "%s",
Weapon = "%s",
Distance = "%0.1f studs",
MiscTop = "%s",
MiscBottom = "%s"
},
Mounts = {
Name = "Top",
MiscTop = "Top",
Distance = "Bottom",
Weapon = "Bottom",
MiscBottom = "Bottom"
},
--[[
Below can be a function to return a dynamic offset. For example, if you have a Weapon and Distance header this helps avoid clashes:
PSEUDOCODE
function (self)
local Base = Vector2.new(0, 0)
if (not DistanceObject.Visible) then
return Base
end
return (Base + DistanceObject.TextBounds) * Vector2.yAxis
end
SEE MANAGER FOR A BETTER EXAMPLE
]]
Offset = Vector2.new(0, 0)
}
Header.DefaultProperties = {
Main = {
Type = "TextDynamic",
Font = DefaultFont,
Size = 13,
Color = Color3.new(1, 0, 0),
Opacity = 1,
OutlineColor = Color3.new(0, 0, 0),
OutlineOpacity = 1,
Visible = false,
}
}
-- // Constructor
function Header.new(Data, Properties)
-- // Default values and assert
Data = Data or {}
Properties = Properties or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local self = setmetatable({}, Header)
-- // Vars
self.Data = Utilities.CombineTables(Utilities.DeepCopy(Header.DefaultData), Data)
self.Properties = Utilities.CombineTables(Utilities.DeepCopy(Header.DefaultProperties), Properties)
-- // Make the object(s)
self.Objects = self:InitialiseObjects(self.Data, self.Properties)
-- // Return the object
return self
end
-- // Calculates the position
function Header:GetPosition(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Vars
local Data = self.Data
local Type = Data.Type
local MainObject = self.Objects.Main
-- // Grab the offset
local Offset = typeof(Data.Offset) == "function" and Data.Offset(self) or Data.Offset
-- // Name (mount to the top)
local MountType = Data.Mounts[Type]
if (MountType == "Top") then
return ((Corners.TopLeft + Corners.TopRight) / 2) - (MainObject.TextBounds * Vector2.yAxis) - Offset
end
-- // Distance (mount to bottom)
if (MountType == "Bottom") then
return ((Corners.BottomLeft + Corners.BottomRight) / 2) + Offset
end
-- // Default
return Vector2.zero
end
-- // Updates the properties
function Header:Update(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Check for visibility
local Data = self.Data
local Properties = Utilities.DeepCopy(self.Properties)
local IsVisible = Data.Enabled and Corners.OnScreen
local OutlineVisible = IsVisible and Data.OutlineEnabled
-- // Set the properties
Utilities.SetDrawingProperties(self.Objects.Main, Utilities.CombineTables(Properties.Main, {
Position = self:GetPosition(Corners),
Text = Data.Formats[Data.Type]:format(Data.Value),
Outlined = OutlineVisible,
Visible = IsVisible
}))
end
end
-- // Healthbar Class
local Healthbar = {}
Healthbar.__index = Healthbar
Healthbar.__type = "Healthbar"
setmetatable(Healthbar, Base)
do
-- // Initialise box data
Healthbar.DefaultData = {
Enabled = true,
OutlineEnabled = true,
Suffix = "HP",
ShowHP = true,
Value = 0, -- // Current Health
MaxValue = 100, -- // Maximum Health
MinColour = Color3.new(1, 0, 0),
MaxColour = Color3.new(0, 1, 0),
Offset = Vector2.new(0, 0),
TextOffset = Vector2.new(5, 0),
WidthOffset = 5 -- // %
}
Healthbar.DefaultProperties = {
Main = {
Type = "LineDynamic",
Thickness = 1,
Color = Color3.new(1, 0, 0),
Opacity = 1,
Outlined = true,
OutlineColor = Color3.new(0, 0, 0),
OutlineOpacity = 1,
OutlineThickness = 1,
Visible = false,
},
Text = {
Type = "TextDynamic",
Font = DefaultFont,
Size = 13,
Color = Color3.new(1, 0, 0),
Opacity = 1,
OutlineColor = Color3.new(0, 0, 0),
OutlineOpacity = 1,
Visible = false
}
}
-- // Constructor
function Healthbar.new(Data, Properties)
-- // Default values and assert
Data = Data or {}
Properties = Properties or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local self = setmetatable({}, Healthbar)
-- // Vars
self.Data = Utilities.CombineTables(Utilities.DeepCopy(Healthbar.DefaultData), Data)
self.Properties = Utilities.CombineTables(Utilities.DeepCopy(Healthbar.DefaultProperties), Properties)
-- // Make the object(s)
self.Objects = self:InitialiseObjects(self.Data, self.Properties)
-- // Return the object
return self
end
-- // Updates the properties
function Healthbar:Update(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Check for visibility
local Data = self.Data
local Properties = Utilities.DeepCopy(self.Properties)
local IsVisible = Data.Enabled and Corners.OnScreen
local OutlineVisible = IsVisible and Data.OutlineEnabled
-- // Vars
local Width = (Corners.TopLeft - Corners.BottomRight) * (Data.WidthOffset / 100) * Vector2.xAxis
local Offset = typeof(Data.Offset) == "function" and Data.Offset(self) or Data.Offset
local CombinedOffset = Width - Offset
local To = Corners.BottomLeft + CombinedOffset
local From = Corners.TopLeft + CombinedOffset
local ValueRatio = Data.Value / Data.MaxValue
local LerpFrom = To:Lerp(From, ValueRatio)
local LerpedColour = CIELUV.Lerp(ValueRatio, Data.MinColour, Data.MaxColour)
-- // Set the properties
Utilities.SetDrawingProperties(self.Objects.Main, Utilities.CombineTables(Properties.Main, {
To = To,
From = LerpFrom,
Color = LerpedColour,
Outlined = OutlineVisible,
Visible = IsVisible
}))
local TextObject = self.Objects.Text
Utilities.SetDrawingProperties(TextObject, Utilities.CombineTables(Properties.Text, {
Text = math.round(Data.Value) .. Data.Suffix,
Position = LerpFrom - Data.TextOffset - TextObject.TextBounds / 2,
Outlined = OutlineVisible,
Visible = Data.ShowHP and IsVisible
}))
end
end
-- // OffArrow Class
local OffArrow = {}
OffArrow.__index = OffArrow
OffArrow.__type = "OffArrow"
setmetatable(OffArrow, Base)
do
-- // Initialise box data
OffArrow.DefaultData = {
Enabled = true,
OutlineEnabled = true,
Radius = 150,
Size = 15,
Offset = Vector2.new(0, 0)
}
OffArrow.DefaultProperties = {
Main = {
Type = "PolyLineDynamic",
Thickness = 1,
FillType = PolyLineFillType.Closed,
Color = Color3.new(1, 0, 0),
Opacity = 1,
Outlined = true,
OutlineColor = Color3.new(0, 0, 0),
OutlineOpacity = 1,
OutlineThickness = 1,
Visible = false,
}
}
-- // Constructor
function OffArrow.new(Data, Properties)
-- // Default values and assert
Data = Data or {}
Properties = Properties or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local self = setmetatable({}, OffArrow)
-- // Vars
self.Data = Utilities.CombineTables(Utilities.DeepCopy(OffArrow.DefaultData), Data)
self.Properties = Utilities.CombineTables(Utilities.DeepCopy(OffArrow.DefaultProperties), Properties)
-- // Make the object(s)
self.Objects = self:InitialiseObjects(self.Data, self.Properties)
-- // Return the object
return self
end
-- // Calulcates direction
function OffArrow:Direction(Destination, Origin)
-- // Default and assert
Origin = Origin or Utilities.GetCurrentCamera().CFrame
assert(typeof(Destination) == "Vector3", "invalid type for Destination (expected Vector3)")
assert(typeof(Origin) == "CFrame", "invalid type for Origin (expected CFrame)")
-- // Maths in order to get the angle
local _, Yaw, Roll = Origin:ToOrientation()
local FlatCFrame = CFrame.Angles(0, Yaw, Roll) + Origin.Position
local ObjectSpace = FlatCFrame:PointToObjectSpace(Destination)
local Angle = math.atan2(ObjectSpace.Z, ObjectSpace.X)
-- // Return the direction
return Vector2.new(math.cos(Angle), math.sin(Angle))
end
-- // Updates the properties
function OffArrow:Update(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Check for visibility
local Data = self.Data
local Properties = Utilities.DeepCopy(self.Properties)
local Centre3D = Corners.Centre3D
local IsVisible = Data.Enabled and not Corners.OnScreen
local OutlineVisible = IsVisible and Data.OutlineEnabled
-- // Vars
local ViewportSize = Utilities.GetCurrentCamera().ViewportSize
local Vector25 = Vector2.one * 25
-- // Workout the value (direction)
local Value = Data.Value or self:Direction(Centre3D)
-- // Work out points
local Size = Data.Size
local PointA = (ViewportSize / 2 + Value * Data.Radius):Max(Vector25):Min(ViewportSize - Vector25)
local PointB = PointA - Utilities.RotateVector2(Value, 0.45) * Size
local PointC = PointA - Utilities.RotateVector2(Value, -0.45) * Size
-- // Set the properties
Utilities.SetDrawingProperties(self.Objects.Main, Utilities.CombineTables(Properties.Main, {
Points = {
PointA,
PointB,
PointC
},
Outlined = OutlineVisible,
Visible = IsVisible
}))
end
end
-- // Box 3D Class
local Box3D = {}
Box3D.__index = Box3D
Box3D.__type = "Box3D"
setmetatable(Box3D, Base)
do
-- // Initialise box data
Box3D.DefaultData = {
Enabled = true,
OutlineEnabled = true,
}
Box3D.DefaultProperties = table.create(4, {-- // Create each face
Type = "PolyLineDynamic",
Thickness = 1,
Outlined = true,
OutlineColor = Color3.new(0, 0, 0),
OutlineOpacity = 1,
OutlineThickness = 1,
Visible = false,
ZIndex = -1
})
-- // Constructor
function Box3D.new(Data, Properties)
-- // Default values and assert
Data = Data or {}
Properties = Properties or {}
assert(typeof(Data) == "table", "invalid type for Data (expected table)")
assert(typeof(Properties) == "table", "invalid type for Properties (expected table)")
-- // Create the object
local self = setmetatable({}, Box3D)
-- // Vars
self.Data = Utilities.CombineTables(Utilities.DeepCopy(Box3D.DefaultData), Data)
self.Properties = Utilities.CombineTables(Utilities.DeepCopy(Box3D.DefaultProperties), Properties)
-- // Make the object(s)
self.Objects = self:InitialiseObjects(self.Data, self.Properties)
-- // Return the object
return self
end
-- // Updates the properties
function Box3D:Update(Corners)
-- // Asserts
assert(typeof(Corners) == "table", "invalid type for Corners (expected table)")
-- // Check for visibility
local Data = self.Data
local Properties = Utilities.DeepCopy(self.Properties)
local IsVisible = Data.Enabled and Corners.OnScreen
local OutlineVisible = IsVisible and Data.OutlineEnabled
-- // Loop through each face
local CornersArray = Utilities.ConvertV3toV2(Corners.Corners)
local PointArray = {1, 5, 4}
for i = 1, #Properties do
-- // Create the points table
local Points = {CornersArray[i]}
for j = 1, 2 do
local Point = CornersArray[(i % 4) + PointArray[j]]
table.insert(Points, Point)
end
table.insert(Points, CornersArray[i == 4 and 8 or (i + PointArray[3])])
-- // Set properties
Utilities.SetDrawingProperties(self.Objects[i], Utilities.CombineTables(Properties[i], {
Points = Points,
Outlined = OutlineVisible,
Visible = IsVisible
}))
end
end
end
-- // Return
local RESP_BASE = {
Utilities = Utilities,
Base = Base,
BoxSquare = BoxSquare,
Tracer = Tracer,
Header = Header,
Healthbar = Healthbar,
OffArrow = OffArrow,
Box3D = Box3D
}
getgenv().RESP_BASE = RESP_BASE