SNPC - FindEnemy Schedule(Help)

I’m trying to make an SNPC run to a position if the player is not within range and then if the player enters his range again, I would like the NPC to run at the player like he normally would if I were to spawn him close to me.

This is my current code:
// data.Radius = 512
local ForceThisPos = Vector(159.44537353516, 240.50567626953, -148)
function ENT:TaskStart_FindEnemy( data )
local enemy = NULL
local et = ents.FindInSphere( self:GetPos(), data.Radius )
for k, v in ipairs(et) do

	if (v:IsValid() && v != self && v:GetClass() == data.Class) then 
		enemy = v
		player.GetByID(1):ChatPrint("Targeting You")
		self:SetEnemy(enemy, true)
		self:UpdateEnemyMemory(enemy, enemy:GetPos()) 
		enemy = NULL
player.GetByID(1):ChatPrint("Couldnt find target")

The NPC itself:
function ENT:SelectSchedule()

local schdChase = ai_schedule.New( "AIFighter Chase" ) //creates the schedule used for this npc

schdChase:AddTask( "FindEnemy", 		{ Class = "player", Radius = self.ViewDistance } )
schdChase:EngTask( "TASK_GET_PATH_TO_ENEMY", 0 )
schdChase:EngTask( "TASK_RUN_PATH_TIMED", 0.1 )
schdChase:EngTask( "TASK_WAIT", 0.1 )

local close = false
local tbl = player.GetAll()
for k,v in pairs(tbl) do
	if v:GetPos():Distance(self:GetPos()) < 120 then
		close = true

if close then
	schdChase:EngTask( "TASK_STOP_MOVING", 			0 )
	schdChase:EngTask( "TASK_FACE_ENEMY", 			0 )
	schdChase:AddTask( "PlaySequence", 				{ Name = "swing", Speed = 3 } )

self:StartSchedule( schdChase ) 


When I spawn it far away from me it runs to the specified Vector then stops. But, when I get 500 units or less to it I get told that I am being targeted, but the SNPC will not attack me even though it is being told to.

the map you are using needs to have nodes.

i know for a fact that gm_construct has nodes so try it on that

I am testing it on gm_construct.

They do not attack me after, self:SetSchedule(SCHED_FORCED_GO_RUN) is called.

If I get within the units i set of 75 for the attack animation then they attack me.

Is SetSchedule blocking the radius/forloop and what would be a workaround?

what is self.ViewDistance set to?

it will only work if the contact is within that range

data.Radius = 512
Same thing.

its not the same thing actually

data is not ENT (or self)

you need to declare ViewDistance on self or it will be nil (unless you already have)

im assuming because it says you are being targetted that its moving towards you?

Sorry trying to be more descriptive.
ENT.ViewDistance = 500
The distance is already set. The npc doesnt track me though AKA update its schedule when it sees me.

Quoted: If I get within the units i set of 75 for the attack animation then they attack me (THIS IS AFTER THE FORCED RUN)

ok but does it chase after you?

Okay i’m going to explain this again.

I spawn the zombie close to me. It chases me. I get too far away from it, then it runs to the indicated Vector. I run close enough to it so it can chase me again but it doesn’t chase me. It sets me as the enemy.

Would you rather have me say what I would like it to do? Then see if you can come up with something/

ye just post what you want it to do an ill give it a go

i should point out that SNPCs arent really my forte but i can work them a little :stuck_out_tongue:

I know this will sound stupid but are you sure that its not reading you as an enemy then when it gets back the the vector it still reads you as an enemy but will only follow a “new” enemy? Have you tried it with other players?

I want the NPC to attack players only in a sphere around itself of 512.
I want them to chase the player till the player gets 512 away from the NPC.
Once the player gets far enough away I want the NPC to run back to a specific Vector on the map and stay there.
After that I want the NPC to attack players who go inside the circle again.

[editline]24th July 2012[/editline]

It doesn’t matter. I am a player and that is what it’s checking for.

you need to make a schedule for chasing the player (which you already have) and one for going to the vector.

when it the target moves out of the radius set the schedule to the one that tells it to go to the vector.

once the npc is at the vector switch it to the finding one.

make sense?

Yeah but not to sound dense or anything, but I don’t know how to set the schedule to one that sets a vector. I wouldn’t know how to set it up being the 2nd day working with NPCS.

ye me neither lol i dont work with SNPCs so… i will me later on though

Hopefully someone figures something out then. The way that this script was before though was that you could be any distance and it would attack you and I didn’t like that so I decided to look into SNPC’s and they’re pretty sweet to mess with. But a pain in the ass to make 'em work.

yep lol theres section on the old gmod wiki mirror on SNPCs im assuming you have looked into it but just for the sake of it heres the link:

Yeah I have seen that before. I’m actually using this guys base from his running zombies. I’m planning on making 3 bases.

Works great because you can use any ragdoll because of bone matrix function:

IIRC for some odd reason SNPC’s enemy/attacking system is very glitchy. When I was working with them in a gamemode I made a while back, I noticed sometimes they wouldn’t target you, or the SNPC WOULD target you, but it wouldn’t attack you. You’d be better off trying to use source NPC’s

What do you mean by source NPC’s?