@@ -22,8 +22,6 @@ function PlayerHurtboxCreator:Init()
2222end
2323
2424function PlayerHurtboxCreator .CreateHurtboxesForPlayer (Player : Player , Character : Model )
25- local ManagedHurtboxes = {}
26-
2725 local HRP = Utils .Character .GetRootPart (Character )
2826 local TargetCFrame = CFrame .new (HRP .CFrame .Position )
2927
@@ -69,19 +67,16 @@ function PlayerHurtboxCreator.CreateHurtboxesForPlayer(Player: Player, Character
6967 Weld .Parent = HRP
7068
7169 --parent it NOW instead of BEFORE so that the client can properly get the ID attribute
72- HitboxClone .Parent = Character .Hitboxes
73-
74- --add it to the table for later hitbox display
75- ManagedHurtboxes [ID ] = HitboxClone
70+ HitboxClone .Parent = Character .Hurtboxes
7671 end
7772
7873 --setup hitbox display on client
79- PlayerHurtboxCreator ._SetupHurtboxViewConnections (Player , Character , ManagedHurtboxes )
74+ PlayerHurtboxCreator ._SetupHurtboxViewConnections (Player , Character )
8075end
8176
8277local Framerate = 1 / 15
8378--- Sets up all available hitboxes for the passed character.
84- function PlayerHurtboxCreator ._SetupHurtboxViewConnections (Player : Player , Character : Model , ManagedHitboxes : {[ number ]: BasePart } )
79+ function PlayerHurtboxCreator ._SetupHurtboxViewConnections (Player : Player , Character : Model )
8580 local JanitorInstance = Janitor .new ()
8681 JanitorInstance :LinkToInstance (Character )
8782
@@ -112,59 +107,9 @@ function PlayerHurtboxCreator._SetupHurtboxViewConnections(Player: Player, Chara
112107
113108 LastPosition = CurrentPosition
114109
115- --get every single hitbox that still exists from the managed hitboxes JUST IN FUCKING CASE.
116- local AliveHitboxes = {}
117- local Count = 0
118- for ID : number , Hitbox : BasePart in ManagedHitboxes do
119- if not (Hitbox and Hitbox .Parent ) then
120- continue
121- end
122-
123- Count += 1
124- AliveHitboxes [ID ] = Hitbox
125- end
126-
127- --if there are no available hitboxes to update, halt
128- if Count <= 0 then
129- return
130- end
131-
132- --let me break this down
133- -- * header for the hitbox count (1 byte, so you can add up to 255 hitboxes)
134- -- * multiplying the amount of hitboxes by 13
135- -- * 1 byte for the ID
136- -- * 12 bytes for XYZ
137- --cool size done!!1!
138- local BufferSize = 1 + (Count * 13 )
139-
140- --we make the buffer
141- local Buffer = buffer.create (BufferSize )
142- --skipping the count byte because that's set by itself in an obvious manner below
143- local Offset = 1
144-
145- --write count as the header
146- buffer.writeu8 (Buffer , 0 , Count )
147-
148- --iterate over every alive hitbox to add it to the buffer
149- for ID : number , Hitbox : BasePart in AliveHitboxes do
150- --write its id as its header
151- buffer.writeu8 (Buffer , Offset , ID :: any )
152- --move forward 1 byte
153- Offset += 1
154-
155- --iterate over every axis from its position
156- local Position = Hitbox .CFrame .Position
157- for _ , Axis in {"X" , "Y" , "Z" } do
158- --write it as a 32 bit float, which should be more than enough (4 bytes, up to 7 decimals)
159- buffer.writef32 (Buffer , Offset , Position [Axis ])
160-
161- --move forward 4 bytes
162- Offset += 4
163- end
164- end
165-
166- --send it to the client to update
167- Network :FireClientConnection (Player , "UpdHurtboxPos" , "UREMOTE_EVENT" , Buffer )
110+ --sending the root's cframe directly to update the hurtboxes's cframe on the client
111+ --i can send the cframe because it'll still be optimized and buffered by the networking module anyways
112+ Network :FireClientConnection (Player , "UpdHurtboxPos" , "UREMOTE_EVENT" , Root .CFrame )
168113 end ))
169114end
170115
0 commit comments