-- ----------------------------------------------------------------- -- Called once when the entity is spawned (server side) -- ----------------------------------------------------------------- function ENT:Initialize() -- Model & physics self:SetModel(CONFIG.Model) self:SetHealth(100) self:SetCollisionGroup(COLLISION_GROUP_NPC)

for _, ply in ipairs(player.GetAll()) do if not IsValid(ply) or not ply:Alive() then continue end

return nearest end

-- 4️⃣ Attack if close enough and cooldown elapsed if distToTarget <= CONFIG.AttackDistance ^ 2 and CurTime() > self.NextAttack then self:AttackTarget() self.NextAttack = CurTime() + CONFIG.AttackCooldown end end end

-- Pre‑cache the scream sound to avoid hitches util.PrecacheSound(CONFIG.ScreamSound) util.PrecacheSound(CONFIG.FootstepSound) end

local dist = self:GetPos():DistToSqr(ply:GetPos()) if dist < nearestDist ^ 2 then nearest = ply nearestDist = math.sqrt(dist) end end