local immFactions = { -- иммунитет фракций
[FACTION_ADMIN] = true,
[FACTION_CITIZEN] = true,
}
local npcs = {
["npc_zombie"] = true,
["npc_headcrab"] = true,
}
local nxtThk = CurTime()
function PLUGIN:Think()
if (nxtThk < CurTime()) then
for k, v in ipairs(ents.FindByClass("npc_*")) do
if (v:IsNPC() and npcs[v:GetClass()] and !IsValid(v:GetEnemy())) then
local target = NULL
local dist = 512
for _, ply in ipairs(player.GetHumans()) do
if (IsValid(ply) and ply:IsPlayer() and ply:Alive()) then
if (immFactions[nut.faction.indices[ply:Team()]]) then continue end
local dist2 = ply:GetPos():Distance(v:GetPos())
if dist2 < dist then
dist = dist2
target = ply
end
else
v:SetEnemy(NULL)
end
end
v:SetEnemy(target)
v:UpdateEnemyMemory(target, target:GetPos())
v:SetSaveValue("m_vecLastPosition", target:GetPos())
v:SetSchedule(SCHED_FORCED_GO)
end
end
nxtThk = CurTime() + 1
end
end