How can I filtre an NPC's targets? For example I have a npc_zombie, and I want it to attack players with Team() == 1 and also any entity with "krp_" at the start of their class name. At the moment they target spectators ( players on team 2 ), so if they can't target entities of a certain class name then targeting only players on team 1 is all I need.
I made a code snippet once that made an npc friendly to an entity and the entities friends, and hate everyone else, like so:
[lua]local function MakeFriendly(ply,npc)
npc:AddEntityRelationship(ply,3,99)
for _,v in ipairs(ents.FindByClass("npc_*")) do if v:Disposition(ply) == 3 then
npc:AddEntityRelationship(v,3,99)
v:AddEntityRelationship(npc,3,99)
else npc:AddEntityRelationship(v,1,99) end
end
end[/lua]
You can modify that, just like if v:Team() == 1 then set unfriendly.
Thanks, perfect
I've stopped NPCs from targeting spectators fine, but they won't attack my sentry or barrier entities. I've used this on each NPC when it spawns:
[lua]z:AddRelationship( "krp_wall D_HT 75" )
z:AddRelationship( "krp_sentry D_HT 99" )[/lua]
Where z is the NPC. Some classic zombies will attack the wall entity if it is in their way, but they always target the player as their main enemy.
Try setting the relationship to all players to a priority of 50 or something and see if it still doesn't attack the sentries. If that doesn't work, another thing you could do is have the relationship to players be a 99 priority until a krp_sentry comes into their line of sight, at which point players go down to 50 and sentries go up to 99.
[QUOTE=Entoros;16878926]Try setting the relationship to all players to a priority of 50 or something and see if it still doesn't attack the sentries. If that doesn't work, another thing you could do is have the relationship to players be a 99 priority until a krp_sentry comes into their line of sight, at which point players go down to 50 and sentries go up to 99.[/QUOTE]
At one point while trying to get it to work I had players set to "like", so the zombies completely ignored players. But they still didn't attack walls or sentries.
It's possible that the AI doesn't allow them to attack things that aren't players (but you said they attacked walls sometimes so that doesn't make sense).
Other things you could try:
1. Use AddEntityRelationship for each krp_sentry, instead of just AddRelationship.
2. It's possible that the AI's innate weapons are only made to attack certain targets (rather unlikely, but I'm reaching here). Just in case, make sure to [url=http://wiki.garrysmod.com/?title=Capabilities]add all weapon capabilities[/url] with [url=http://wiki.garrysmod.com/?title=NPC.CapabilitiesAdd]npc:CapabilitiesAdd()[/url].
[QUOTE=Entoros;16883128]It's possible that the AI doesn't allow them to attack things that aren't players (but you said they attacked walls sometimes so that doesn't make sense).
Other things you could try:
1. Use AddEntityRelationship for each krp_sentry, instead of just AddRelationship.
2. It's possible that the AI's innate weapons are only made to attack certain targets (rather unlikely, but I'm reaching here). Just in case, make sure to [url=http://wiki.garrysmod.com/?title=Capabilities]add all weapon capabilities[/url] with [url=http://wiki.garrysmod.com/?title=NPC.CapabilitiesAdd]npc:CapabilitiesAdd()[/url].[/QUOTE]
Thanks, I'll try both. Also, when the zombies spawn they just stand still untill they see a player. What would be great is if they would start heading for players immediately. I've used z:SetEnemy( ply ) on a random player on each zombie that spawns, but they still just stand there. Do I need to set their current schedule or something?
Thanks again Entoros, you've been a great help! :D
I tried both but the zombies still won't attack the sentries unless they are obstructing them. One odd thing I noticed is that although the zombies always chase me, if there is a sentry nearby they will stop a certain distance away from me and not attack me unless I walk into them. If I destroy the sentry they start attacking again.
Sorry, you need to Log In to post a reply to this thread.