@@ -211,39 +211,51 @@ function ENT:CheckPortIdLimit(portId, warn)
211211 return true
212212end
213213
214+ -- Protect in-/output entities from non-wire tools
214215function 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
221223end
222224
225+ -- Protect in-/output entities from the physgun
223226function 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
230233end
231234
235+ -- Remove in-/output entities on remove
232236function 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
235243end
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
239250function ENT :FlagGetStartActive ()
240251 local flags = self :GetSpawnFlags ()
241- return bit .band (flags , 16 ) == 16 -- Start Active
252+ return bit .band (flags , 16 ) == 16
242253end
243254
255+ -- Render wires clientside
244256function ENT :FlagGetRenderWires ()
245257 local flags = self :GetSpawnFlags ()
246- return bit .band (flags , 32 ) == 32 -- Start Active
258+ return bit .band (flags , 32 ) == 32
247259end
248260
249261function 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