Skip to content

Commit 91091f4

Browse files
committed
auto-link special tracked parts on creation
mainly to fix temporary damagezones (from projectiles) which we want to use with damage_zone_hit events for example the caching method, while better than looking through local parts, had its flaws
1 parent c069de0 commit 91091f4

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

lua/pac3/core/client/part_pool.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ function pac.EnablePartsByClass(classname, enable)
645645
end
646646
end
647647

648+
local known_special_link_parts = {}
648649
function pac.LinkSpecialTrackedPartsForEvent(part, ply)
649650
part.erroring_cached_parts = {}
650651
part.found_cached_parts = {}
@@ -654,11 +655,27 @@ function pac.LinkSpecialTrackedPartsForEvent(part, ply)
654655
["damage_zone"] = true,
655656
["lock"] = true
656657
}
658+
known_special_link_parts[ply] = known_special_link_parts[ply] or {}
659+
known_special_link_parts[ply][part] = part.specialtrackedparts
657660
for _,part2 in pairs(all_parts) do
658661
if ply == part2:GetPlayerOwner() and tracked_classes[part2.ClassName] then
659662
table.insert(part.specialtrackedparts,part2)
660663
end
661664
end
665+
known_special_link_parts[ply][part] = part.specialtrackedparts
666+
end
667+
function pac.InsertSpecialTrackedPart(ply, append_part, remove)
668+
if append_part then
669+
if known_special_link_parts[ply] then
670+
for part,tbl in pairs(known_special_link_parts[ply]) do
671+
if remove then table.RemoveByValue(part.specialtrackedparts, append_part) continue end
672+
if part:IsValid() then
673+
table.insert(part.specialtrackedparts, append_part)
674+
end
675+
end
676+
end
677+
return
678+
end
662679
end
663680

664681
--a centralized function to cache a part in a prebuilt list so we can access relevant parts already narrowed down instead of searching through all parts / localparts

lua/pac3/core/client/parts/damage_zone.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,8 @@ function PART:OnRemove()
998998
pac.RemoveHook(v, "pace_draw_hitbox")
999999
end
10001000
self:ClearHitMarkers()
1001+
--remove itself
1002+
pac.InsertSpecialTrackedPart(self:GetPlayerOwner(), self, true)
10011003
end
10021004

10031005
local previousRenderingHook
@@ -1295,6 +1297,7 @@ function PART:Initialize()
12951297
end
12961298
end)
12971299

1300+
pac.InsertSpecialTrackedPart(self:GetPlayerOwner(), self)
12981301
end
12991302

13001303
function PART:SetRadius(val)

lua/pac3/core/client/parts/lock.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@ function PART:reset_ent_ang()
478478
end
479479

480480
function PART:OnRemove()
481+
pac.InsertSpecialTrackedPart(self:GetPlayerOwner(), self, true)
481482
end
482483

483484
function PART:DecideTarget()
@@ -595,6 +596,7 @@ function PART:Initialize()
595596
end
596597
end
597598
if not convar_lock:GetBool() then self:SetError("lock parts are disabled on this server!") end
599+
pac.InsertSpecialTrackedPart(self:GetPlayerOwner(), self)
598600
end
599601

600602

0 commit comments

Comments
 (0)