From 7aea9a37498213ddf7f931d95f173022e3849bb9 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Sun, 6 Sep 2026 18:03:55 +0200 Subject: [PATCH] Respawn map-spawned coop pickups --- gamemode/weaponsystem.lua | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/gamemode/weaponsystem.lua b/gamemode/weaponsystem.lua index 09fc764..397e8e3 100644 --- a/gamemode/weaponsystem.lua +++ b/gamemode/weaponsystem.lua @@ -94,6 +94,21 @@ local function IsRespawnable(ent) return string.StartWith(className, "item_") or string.StartWith(className, "weapon_") end +local function IsMapWorldPickup(ent) + if not IsRespawnable(ent) then return false end + if ent:CreatedByMap() or ent.CustomCoopRespawnTemplate then return true end + + -- point_template and other Hammer spawners create new entities at runtime, + -- so GMod reports CreatedByMap() as false for them. Their mapper-assigned + -- targetname survives, which lets us include them without also making + -- player-spawned or anonymous NPC-dropped weapons permanently respawn. + if IsValid(ent:GetOwner()) or IsValid(ent:GetParent()) or IsValid(ent:GetCreator()) then + return false + end + + return ent:GetName() ~= "" +end + local function CaptureTemplate(ent) local bodygroups = {} for _, bodygroup in ipairs(ent:GetBodyGroups() or {}) do @@ -200,7 +215,7 @@ end hook.Add("OnEntityCreated", "CustomCoopTrackMapItems", function(ent) -- OnEntityCreated fires before keyvalues and map-created state are ready. timer.Simple(0, function() - if IsRespawnable(ent) and ent:CreatedByMap() then + if IsMapWorldPickup(ent) then TrackItem(ent) end end) @@ -208,7 +223,7 @@ end) local function TrackExistingItems() for _, ent in ipairs(ents.GetAll()) do - if IsRespawnable(ent) and (ent:CreatedByMap() or ent.CustomCoopRespawnTemplate) then + if IsMapWorldPickup(ent) then TrackItem(ent) end end