For some reason the NPC’s never actually attack the ‘core’ entity. Even though you can tell that the ‘core’ is closest. They only attack players, and when there are no players alive, they just stay where they are and stare at the ‘core’.
Their relationship with the core is D_HT with a value of 999.
[lua]
// npc_control.lua
function _R.Vector:DistanceSqr( vec )
return (self - vec):LengthSqr()
end
function NPCThink( )
local npcs = ents.FindByClass( "npc_*" )
local AllCores = ents.FindByClass( "info_game_core" )
local core = AllCores[1]
local plyTbl = player.GetAll()
for _,npc in pairs( npcs ) do
table.sort( plyTbl, function( a, b )
return npc:GetPos():DistanceSqr( a:GetPos() ) < npc:GetPos():DistanceSqr( b:GetPos() )
end )
if npc:GetPos():Distance( plyTbl[1]:GetPos() ) < npc:GetPos():Distance( core:GetPos() ) then
npc:SetEnemy( plyTbl[1], true )
npc:SetTarget( plyTbl[1] )
npc:UpdateEnemyMemory( plyTbl[1], plyTbl[1]:GetPos() )
npc:NavSetGoal( plyTbl[1]:GetPos() )
else
npc:SetEnemy( core, true )
npc:SetTarget( core )
npc:UpdateEnemyMemory( core, core:GetPos() )
npc:NavSetGoal( core:GetPos() )
end
end
end
timer.Create( “npc_think”, 10, 0, NPCThink )
[/lua]
Does anyone know of a solution?