@@ -13,15 +13,15 @@ local hitboxHandler = {
13
13
hitboxTransparency = 0 ,
14
14
hitboxCanCollide = false ,
15
15
customPartName = " HeadHB" ,
16
- hitboxPartList = {},
16
+ hitboxPartList = {} :: { [ string ]: boolean } ,
17
17
18
18
ignoreTeammates = false ,
19
19
ignoreFF = false ,
20
20
ignoreSitting = false ,
21
21
ignoreSelectedPlayers = false ,
22
- ignorePlayerList = {},
22
+ ignorePlayerList = {} :: { string } ,
23
23
ignoreSelectedTeams = false ,
24
- ignoreTeamList = {},
24
+ ignoreTeamList = {} :: { string } ,
25
25
}
26
26
27
27
type Entity = typeof (require (" ./Classes/Entity.lua" ).new (Instance .new (" Model" ))) & {
@@ -73,7 +73,7 @@ local function addEntity(entity: Entity)
73
73
return if hitboxHandler .extendHitbox then hitboxHandler .hitboxCanCollide else value
74
74
end ))
75
75
76
- -- properties don't trigger sethooks when set from a serverscript
76
+ -- properties don't trigger sethooks when set by a serverscript
77
77
partDumpster :dump (part .Changed :Connect (function (property )
78
78
if partProperties .debounce then return end
79
79
if partProperties [property ] then partProperties [property ] = part [property ] end
@@ -187,46 +187,57 @@ local function addEntity(entity: Entity)
187
187
end
188
188
end
189
189
190
- local function addUpdateEvents (character : Model ? )
191
- -- print("addUpdateEvents:", entity:GetName(), character)
192
- if not character then
193
- -- print("character not found")
194
- return
195
- end
196
- -- Roblox still hasn't fixed CharacterAdded firing before all of the limbs are loaded
190
+ local function addUpdateEvents ()
191
+ local character = entity :WaitForCharacter ()
192
+ -- print("addUpdateEvents:", entity:GetName())
193
+ -- Roblox still hasn't fixed CharacterAdded firing too early
197
194
-- https://devforum.roblox.com/t/avatar-loading-event-ordering-improvements/269607
198
195
local humanoid
199
196
local loaded = false
200
197
local startTime = tick ()
201
198
while not loaded and tick () - startTime <= 2 do
202
199
task .wait ()
203
200
-- print("addUpdateEvents loop")
204
- for name , _ in hitboxHandler .hitboxPartList do
205
- -- print("checking part", name .. ":", character:FindFirstChild(name) ~= nil)
206
- if not character :FindFirstChild (name ) then return end
207
- end
201
+ -- I sure hope limbs loading before the humanoid is consistent behavior! Seems fine in my 3 minutes of testing.
208
202
humanoid = character :FindFirstChildWhichIsA (" Humanoid" )
209
203
-- print("checking humanoid:", humanoid ~= nil)
210
- if not humanoid then return end
204
+ if not humanoid then continue end
211
205
loaded = true
212
206
end
213
207
if humanoid then
208
+ -- Have to check both Health and StateType since some games disable HumanoidStateType.Dead
209
+ -- This has a side effect of calling hitboxStep twice on death for most games. Too bad!
214
210
humanoid :GetPropertyChangedSignal (" Health" ):Connect (function ()
215
- if humanoid .Health <= 0 then entity :hitboxStep () end
216
- -- print(entity:GetName(), "died")
211
+ if humanoid .Health <= 0 then
212
+ -- print("0Health:", entity:GetName())
213
+ entity :hitboxStep ()
214
+ end
217
215
end )
218
216
humanoid .StateChanged :Connect (function (_ , newState )
219
- if newState == Enum .HumanoidStateType .Dead then entity :hitboxStep () end
217
+ if newState == Enum .HumanoidStateType .Dead then
218
+ -- print("HumanoidDead:", entity:GetName())
219
+ entity :hitboxStep ()
220
+ end
220
221
end )
221
222
end
222
- character .ChildAdded :Connect (function (child )
223
- if child :IsA (" ForceField" ) then entity :hitboxStep () end
224
- -- print(entity:GetName(), "invulnerable")
225
- end )
226
- character .ChildRemoved :Connect (function (child )
227
- if child :IsA (" ForceField" ) then entity :hitboxStep () end
228
- -- print(entity:GetName(), "vulnerable")
229
- end )
223
+ entity .dumpsters [character ] = Dumpster .new ()
224
+ local characterConnectionsDumpster = entity .dumpsters [character ]
225
+ characterConnectionsDumpster :dump (character .ChildAdded :Connect (function (child )
226
+ if child :IsA (" ForceField" ) then
227
+ -- print("+forcefield:", entity:GetName())
228
+ entity :hitboxStep ()
229
+ end
230
+ end ))
231
+ characterConnectionsDumpster :dump (character .ChildRemoved :Connect (function (child )
232
+ if child :IsA (" ForceField" ) then
233
+ -- print("-forcefield:", entity:GetName())
234
+ entity :hitboxStep ()
235
+ end
236
+ end ))
237
+ characterConnectionsDumpster :dump (character .AncestryChanged :Connect (function (_ , parent )
238
+ if parent ~= nil then return end
239
+ characterConnectionsDumpster :burn ()
240
+ end ))
230
241
entity :hitboxStep ()
231
242
end
232
243
@@ -240,7 +251,7 @@ local function addEntity(entity: Entity)
240
251
playerConnectionDumpster :dump (player :GetPropertyChangedSignal (" Team" ):Connect (entity .hitboxStep ))
241
252
end
242
253
243
- addUpdateEvents (entity : GetCharacter () )
254
+ addUpdateEvents ()
244
255
end
245
256
local function removeEntity (entity : Entity )
246
257
entity .oldProperties = {}
@@ -249,7 +260,7 @@ local function removeEntity(entity: Entity)
249
260
end
250
261
end
251
262
252
- function hitboxHandler :updatePartList (list : { [ string] : boolean } )
263
+ function hitboxHandler :updatePartList (list : { string } )
253
264
hitboxHandler .hitboxPartList = {}
254
265
local partMap : { [string ]: { string } } = {
255
266
[" Custom Part" ] = { hitboxHandler .customPartName },
@@ -270,7 +281,7 @@ function hitboxHandler:updatePartList(list: { [string]: boolean })
270
281
end
271
282
end
272
283
function hitboxHandler :updateHitbox ()
273
- for _ , player in EntHandler :GetPlayers () do
284
+ for _ , player : Entity in EntHandler :GetPlayers () do
274
285
player :hitboxStep ()
275
286
end
276
287
end
0 commit comments