diff --git a/gamemodes/zombiesurvival/entities/entities/point_propnocollide.lua b/gamemodes/zombiesurvival/entities/entities/point_propnocollide.lua index f76dc29..9f312de 100644 --- a/gamemodes/zombiesurvival/entities/entities/point_propnocollide.lua +++ b/gamemodes/zombiesurvival/entities/entities/point_propnocollide.lua @@ -23,7 +23,7 @@ function ENT:SetProp(ent) local teamid = self:GetTeam() local inrad = false for _, pl in pairs(ents.FindInSphere(ent:LocalToWorld(ent:OBBCenter()), ent:BoundingRadius() / 2 + self:GetExtraRadius())) do - if pl:IsValid() and pl:IsPlayer() and pl:Alive() and (teamid == 0 or pl:Team() == teamid) then + if pl and pl:IsValid() and pl:IsPlayer() and pl:Alive() and (teamid == 0 or pl:Team() == teamid) then inrad = true break end @@ -65,7 +65,7 @@ function ENT:Think() local center = ent:LocalToWorld(ent:OBBCenter()) for _, pl in pairs(ents.FindInSphere(center, ent:BoundingRadius() / 2 + self:GetExtraRadius())) do - if pl:IsValid() and pl:IsPlayer() and pl:Alive() and (teamid == 0 or pl:Team() == teamid) then + if pl and pl:IsValid() and pl:IsPlayer() and pl:Alive() and (teamid == 0 or pl:Team() == teamid) then pushout = true if timeout then diff --git a/gamemodes/zombiesurvival/entities/entities/status_ghost_arsenalcrate/shared.lua b/gamemodes/zombiesurvival/entities/entities/status_ghost_arsenalcrate/shared.lua index 3662a60..e13ce1d 100644 --- a/gamemodes/zombiesurvival/entities/entities/status_ghost_arsenalcrate/shared.lua +++ b/gamemodes/zombiesurvival/entities/entities/status_ghost_arsenalcrate/shared.lua @@ -13,7 +13,7 @@ end function ENT:IsInsideProp() for _, ent in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if ent ~= self and ent:IsValid() and ent:GetMoveType() == MOVETYPE_VPHYSICS and ent:GetSolid() > 0 then return true end + if ent and ent ~= self and ent:IsValid() and ent:GetMoveType() == MOVETYPE_VPHYSICS and ent:GetSolid() > 0 then return true end end return false @@ -41,7 +41,7 @@ function ENT:RecalculateValidity() valid = false else for _, ent in pairs(ents.FindInSphere(tr.HitPos, 128)) do - if ent:IsValid() and ent:GetClass() == "prop_arsenalcrate" then + if ent and ent:IsValid() and ent:GetClass() == "prop_arsenalcrate" then valid = false break end diff --git a/gamemodes/zombiesurvival/entities/entities/status_ghost_base/shared.lua b/gamemodes/zombiesurvival/entities/entities/status_ghost_base/shared.lua index 3d2c7ef..3ed5b66 100644 --- a/gamemodes/zombiesurvival/entities/entities/status_ghost_base/shared.lua +++ b/gamemodes/zombiesurvival/entities/entities/status_ghost_base/shared.lua @@ -19,7 +19,7 @@ end function ENT:IsInsideProp() for _, ent in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if ent ~= self and ent:IsValid() and ent:GetMoveType() == MOVETYPE_VPHYSICS and ent:GetSolid() > 0 then return true end + if ent and ent ~= self and ent:IsValid() and ent:GetMoveType() == MOVETYPE_VPHYSICS and ent:GetSolid() > 0 then return true end end return false @@ -56,7 +56,7 @@ function ENT:RecalculateValidity() valid = false elseif self.GhostDistance then for _, ent in pairs(ents.FindInSphere(tr.HitPos, self.GhostDistance)) do - if ent:IsValid() and ent:GetClass() == self.GhostEntity then + if ent and ent:IsValid() and ent:GetClass() == self.GhostEntity then valid = false break end diff --git a/gamemodes/zombiesurvival/entities/entities/status_ghost_messagebeacon/shared.lua b/gamemodes/zombiesurvival/entities/entities/status_ghost_messagebeacon/shared.lua index d1d81da..f086c41 100644 --- a/gamemodes/zombiesurvival/entities/entities/status_ghost_messagebeacon/shared.lua +++ b/gamemodes/zombiesurvival/entities/entities/status_ghost_messagebeacon/shared.lua @@ -14,7 +14,7 @@ end function ENT:IsInsideProp() for _, ent in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if ent ~= self and ent:IsValid() and ent:GetMoveType() == MOVETYPE_VPHYSICS and ent:GetSolid() > 0 then return true end + if ent and ent ~= self and ent:IsValid() and ent:GetMoveType() == MOVETYPE_VPHYSICS and ent:GetSolid() > 0 then return true end end return false @@ -37,7 +37,7 @@ function ENT:RecalculateValidity() valid = false else for _, ent in pairs(ents.FindInSphere(tr.HitPos, 48)) do - if ent:IsValid() and ent:GetClass() == "prop_messagebeacon" then + if ent and ent:IsValid() and ent:GetClass() == "prop_messagebeacon" then valid = false break end diff --git a/gamemodes/zombiesurvival/entities/entities/zombiegasses/init.lua b/gamemodes/zombiesurvival/entities/entities/zombiegasses/init.lua index 6ba654b..2b95195 100644 --- a/gamemodes/zombiesurvival/entities/entities/zombiegasses/init.lua +++ b/gamemodes/zombiesurvival/entities/entities/zombiegasses/init.lua @@ -37,7 +37,7 @@ function ENT:AcceptInput(name, activator, caller, arg) local vPos = self:GetPos() for _, ent in pairs(ents.FindInSphere(vPos, self:GetRadius())) do - if ent:IsPlayer() and ent:Alive() and WorldVisible(vPos, ent:NearestPoint(vPos)) then + if ent and ent:IsValid() and ent:IsPlayer() and ent:Alive() and WorldVisible(vPos, ent:NearestPoint(vPos)) then if ent:Team() == TEAM_UNDEAD then --[[if ent:Health() < ent:GetMaxHealth() and not ent:GetZombieClassTable().Boss then ent:SetHealth(math.min(ent:GetMaxZombieHealth(), ent:Health() + self.Heal)) diff --git a/gamemodes/zombiesurvival/entities/weapons/weapon_zs_chemzombie/init.lua b/gamemodes/zombiesurvival/entities/weapons/weapon_zs_chemzombie/init.lua index 61d9473..1598043 100644 --- a/gamemodes/zombiesurvival/entities/weapons/weapon_zs_chemzombie/init.lua +++ b/gamemodes/zombiesurvival/entities/weapons/weapon_zs_chemzombie/init.lua @@ -15,7 +15,7 @@ function SWEP:Think() local origin = self.Owner:LocalToWorld(self.Owner:OBBCenter()) for _, ent in pairs(ents.FindInSphere(origin, 40)) do - if ent:IsPlayer() and ent:Team() ~= TEAM_UNDEAD and ent:Alive() and TrueVisible(origin, ent:NearestPoint(origin)) then + if ent and ent:IsValid() and ent:IsPlayer() and ent:Team() ~= TEAM_UNDEAD and ent:Alive() and TrueVisible(origin, ent:NearestPoint(origin)) then ent:PoisonDamage(1, self.Owner, self) end end diff --git a/gamemodes/zombiesurvival/entities/weapons/weapon_zs_wraith/shared.lua b/gamemodes/zombiesurvival/entities/weapons/weapon_zs_wraith/shared.lua index 9966547..80eea2e 100644 --- a/gamemodes/zombiesurvival/entities/weapons/weapon_zs_wraith/shared.lua +++ b/gamemodes/zombiesurvival/entities/weapons/weapon_zs_wraith/shared.lua @@ -93,7 +93,7 @@ function SWEP:DoAlert() local mouthpos = owner:EyePos() + owner:GetUp() * -3 local screampos = mouthpos + owner:GetAimVector() * 16 for _, ent in pairs(ents.FindInSphere(screampos, 92)) do - if ent:IsPlayer() and ent:Team() ~= owner:Team() then + if ent and ent:IsValid() and ent:IsPlayer() and ent:Team() ~= owner:Team() then local entearpos = ent:EyePos() local dist = screampos:Distance(entearpos) if dist <= 92 and TrueVisible(entearpos, screampos) then diff --git a/gamemodes/zombiesurvival/gamemode/init.lua b/gamemodes/zombiesurvival/gamemode/init.lua index 86d7a95..2d3d0a4 100644 --- a/gamemodes/zombiesurvival/gamemode/init.lua +++ b/gamemodes/zombiesurvival/gamemode/init.lua @@ -787,7 +787,7 @@ function GM:PlayerSelectSpawn(pl) local blocked local spawnpos = spawn:GetPos() for _, ent in pairs(ents.FindInBox(spawnpos + playermins, spawnpos + playermaxs)) do - if ent:IsPlayer() and not spawninplayer or string.sub(ent:GetClass(), 1, 5) == "prop_" then + if ent and ent:IsValid() and ent:IsPlayer() and not spawninplayer or string.sub(ent:GetClass(), 1, 5) == "prop_" then blocked = true break end @@ -1737,7 +1737,7 @@ end function GM:EvaluatePropFreeze(ent, neighbors) if not ent then for _, e in pairs(ents.GetAll()) do - if e:IsValid() then + if e and e:IsValid() then self:EvaluatePropFreeze(e) end end diff --git a/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua b/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua index 479cc94..c0df48c 100644 --- a/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua +++ b/gamemodes/zombiesurvival/gamemode/obj_entity_extend.lua @@ -153,7 +153,7 @@ end local function barricadetimer(self, timername) if self:IsValid() then for _, e in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if e:IsPlayer() and e:Alive() then + if e and e:IsValid() and e:IsPlayer() and e:Alive() then return end end @@ -169,7 +169,7 @@ function meta:TemporaryBarricadeObject() if self.IsBarricadeObject then return end for _, e in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if e:IsPlayer() and e:Alive() then + if e and e:IsValid() and e:IsPlayer() and e:Alive() then self.IsBarricadeObject = true self:CollisionRulesChanged() diff --git a/gamemodes/zombiesurvival/gamemode/obj_entity_extend_sv.lua b/gamemodes/zombiesurvival/gamemode/obj_entity_extend_sv.lua index c60bae5..f2b3c98 100644 --- a/gamemodes/zombiesurvival/gamemode/obj_entity_extend_sv.lua +++ b/gamemodes/zombiesurvival/gamemode/obj_entity_extend_sv.lua @@ -367,7 +367,7 @@ end local function GetNailOwner(nail, filter) for _, ent in pairs(ents.GetAll()) do - if ent ~= filter and ent.Nails then + if ent and ent ~= filter and ent.Nails and ent:isValid() then for __, n in pairs(ent.Nails) do if n == nail then return ent diff --git a/gamemodes/zombiesurvival/gamemode/obj_player_extend.lua b/gamemodes/zombiesurvival/gamemode/obj_player_extend.lua index cf54f90..215778f 100644 --- a/gamemodes/zombiesurvival/gamemode/obj_player_extend.lua +++ b/gamemodes/zombiesurvival/gamemode/obj_player_extend.lua @@ -444,7 +444,7 @@ end local function nocollidetimer(self, timername) if self:IsValid() then for _, e in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if e:IsPlayer() and e ~= self and GAMEMODE:ShouldCollide(self, e) then + if e and e:IsValid() and e:IsPlayer() and e ~= self and GAMEMODE:ShouldCollide(self, e) then return end end @@ -459,7 +459,7 @@ function meta:TemporaryNoCollide(force) if self:GetCollisionGroup() ~= COLLISION_GROUP_PLAYER and not force then return end for _, e in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if e:IsPlayer() and e ~= self and GAMEMODE:ShouldCollide(self, e) then + if e and e:IsValid() and e:IsPlayer() and e ~= self and GAMEMODE:ShouldCollide(self, e) then self:SetCollisionGroup(COLLISION_GROUP_DEBRIS_TRIGGER) local timername = "TemporaryNoCollide"..self:UniqueID() @@ -547,7 +547,7 @@ function meta:ActiveBarricadeGhosting(override) if self:Team() ~= TEAM_HUMAN and not override or not self:GetBarricadeGhosting() then return false end for _, ent in pairs(ents.FindInBox(self:WorldSpaceAABB())) do - if self:ShouldBarricadeGhostWith(ent) then return true end + if ent and ent:IsValid() and self:ShouldBarricadeGhostWith(ent) then return true end end return false diff --git a/gamemodes/zombiesurvival/gamemode/sh_crafts.lua b/gamemodes/zombiesurvival/gamemode/sh_crafts.lua index be69d6b..fb4c016 100644 --- a/gamemodes/zombiesurvival/gamemode/sh_crafts.lua +++ b/gamemodes/zombiesurvival/gamemode/sh_crafts.lua @@ -182,7 +182,7 @@ function GM:CanCraft(pl, craft) if not pl:IsValid() or not pl:Alive() or pl:Team() ~= TEAM_HUMAN then return false end local plpos = pl:EyePos() - local entities = ents.FindInSphere(plpos, self.CraftingRange) + local entities = ents.FindValidInSphere(plpos, self.CraftingRange) if craft.CanCraft and not craft:CanCraft(pl, entities, plpos) then return false end diff --git a/gamemodes/zombiesurvival/gamemode/sh_util.lua b/gamemodes/zombiesurvival/gamemode/sh_util.lua index cd5a27c..d64f9aa 100644 --- a/gamemodes/zombiesurvival/gamemode/sh_util.lua +++ b/gamemodes/zombiesurvival/gamemode/sh_util.lua @@ -118,9 +118,11 @@ end function util.BlastDamageEx(inflictor, attacker, epicenter, radius, damage, damagetype) local filter = inflictor for _, ent in pairs(ents.FindInSphere(epicenter, radius)) do - local nearest = ent:NearestPoint(epicenter) - if TrueVisibleFilters(epicenter, nearest, inflictor, ent) then - ent:TakeSpecialDamage(((radius - nearest:Distance(epicenter)) / radius) * damage, damagetype, attacker, inflictor, nearest) + if ent and ent:IsValid() then + local nearest = ent:NearestPoint(epicenter) + if TrueVisibleFilters(epicenter, nearest, inflictor, ent) then + ent:TakeSpecialDamage(((radius - nearest:Distance(epicenter)) / radius) * damage, damagetype, attacker, inflictor, nearest) + end end end end @@ -129,12 +131,26 @@ function util.BlastDamage2(inflictor, attacker, epicenter, radius, damage) util.BlastDamageEx(inflictor, attacker, epicenter, radius, damage, DMG_BLAST) end +function util.FindValidInSphere(pos, radius) + local ret = {} + + for _, ent in pairs(util.FindInSphere(pos, radius)) do + if ent and ent:IsValid() then + ret[#ret + 1] = ent + end + end + + return ret +end + function util.PoisonBlastDamage(inflictor, attacker, epicenter, radius, damage, noreduce) local filter = inflictor for _, ent in pairs(ents.FindInSphere(epicenter, radius)) do - local nearest = ent:NearestPoint(epicenter) - if TrueVisibleFilters(epicenter, nearest, inflictor, ent) then - ent:PoisonDamage(((radius - nearest:Distance(epicenter)) / radius) * damage, attacker, inflictor, nil, noreduce) + if ent and ent:IsValid() then + local nearest = ent:NearestPoint(epicenter) + if TrueVisibleFilters(epicenter, nearest, inflictor, ent) then + ent:PoisonDamage(((radius - nearest:Distance(epicenter)) / radius) * damage, attacker, inflictor, nil, noreduce) + end end end end diff --git a/gamemodes/zombiesurvival/gamemode/sv_profiling.lua b/gamemodes/zombiesurvival/gamemode/sv_profiling.lua index 0b41f83..af15a61 100644 --- a/gamemodes/zombiesurvival/gamemode/sv_profiling.lua +++ b/gamemodes/zombiesurvival/gamemode/sv_profiling.lua @@ -128,10 +128,12 @@ function GM:ProfilerPlayerValid(pl) -- Are they near a trigger hurt? for _, ent in pairs(ents.FindInSphere(plcenter, 256)) do - local entclass = ent:GetClass() - if entclass == "trigger_hurt" then - --print('trigger hurt') - return false + if ent and ent:IsValid() then + local entclass = ent:GetClass() + if entclass == "trigger_hurt" then + --print('trigger hurt') + return false + end end end diff --git a/gamemodes/zombiesurvival/gamemode/sv_zombieescape.lua b/gamemodes/zombiesurvival/gamemode/sv_zombieescape.lua index a7d5729..a1fb633 100644 --- a/gamemodes/zombiesurvival/gamemode/sv_zombieescape.lua +++ b/gamemodes/zombiesurvival/gamemode/sv_zombieescape.lua @@ -37,7 +37,7 @@ hook.Add("InitPostEntityMap", "zombieescape", function(fromze) end for _, ent in pairs(ents.GetAll()) do - if ent.ZEDelete then + if ent and ent.ZEDelete and ent:IsValid() then ent:Remove() end end