Skip to content

Commit 73973d9

Browse files
committed
Never remove entities that's aren't map spawned.
1 parent 37d0049 commit 73973d9

File tree

1 file changed

+21
-7
lines changed
  • lua/entities/info_wiremapinterface

1 file changed

+21
-7
lines changed

lua/entities/info_wiremapinterface/init.lua

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -211,39 +211,51 @@ function ENT:CheckPortIdLimit(portId, warn)
211211
return true
212212
end
213213

214+
-- Protect in-/output entities from non-wire tools
214215
function ENT:FlagGetProtectFromTools()
215216
if not self:CreatedByMap() then
217+
-- Prevent abuse by runtime-spawned instances.
216218
return false
217219
end
218220

219221
local flags = self:GetSpawnFlags()
220-
return bit.band(flags, 1) == 1 -- Protect in-/output entities from non-wire tools
222+
return bit.band(flags, 1) == 1
221223
end
222224

225+
-- Protect in-/output entities from the physgun
223226
function ENT:FlagGetProtectFromPhysgun()
224227
if not self:CreatedByMap() then
225228
return false
226229
end
227230

228231
local flags = self:GetSpawnFlags()
229-
return bit.band(flags, 2) == 2 -- Protect in-/output entities from the physgun
232+
return bit.band(flags, 2) == 2
230233
end
231234

235+
-- Remove in-/output entities on remove
232236
function ENT:FlagGetRemoveEntities()
237+
if not self:CreatedByMap() then
238+
return false
239+
end
240+
233241
local flags = self:GetSpawnFlags()
234-
return bit.band(flags, 4) == 4 -- Remove in-/output entities on remove
242+
return bit.band(flags, 4) == 4
235243
end
236244

237-
-- Note: bit.band(flags, 8) == 8 Was used for running lua code. It must be left unused as could cause unexpected side effects on older maps.
245+
-- Note:
246+
-- bit.band(flags, 8) == 8 Was used for running lua code.
247+
-- It must be left unused as it could cause unexpected side effects on older maps.
238248

249+
-- Start Active
239250
function ENT:FlagGetStartActive()
240251
local flags = self:GetSpawnFlags()
241-
return bit.band(flags, 16) == 16 -- Start Active
252+
return bit.band(flags, 16) == 16
242253
end
243254

255+
-- Render wires clientside
244256
function ENT:FlagGetRenderWires()
245257
local flags = self:GetSpawnFlags()
246-
return bit.band(flags, 32) == 32 -- Start Active
258+
return bit.band(flags, 32) == 32
247259
end
248260

249261
function ENT:Initialize()
@@ -621,7 +633,9 @@ function ENT:OnRemove()
621633

622634
if self:FlagGetRemoveEntities() then
623635
for _, wireEnt in ipairs(wireEnts) do
624-
SafeRemoveEntity(wireEnt)
636+
if wireEnt:IsValid() and not wireEnt:IsMarkedForDeletion() and wireEnt:CreatedByMap() then
637+
wireEnt:Remove()
638+
end
625639
end
626640
else
627641
self:RemoveAllEntities()

0 commit comments

Comments
 (0)