In response to Spunky_Girl
while(get_dist(src,'target') > 'follow range')
if(get_dist(src,'target') > 'attack range')
step_towards(src,'target')
else
//Your combat stuff
sleep('delay')
if('alive') loc=locate(initial(x),initial(y),initial(z))


That should help. I also suggest having all NPC AI be relative to the client. By this I mean use a loop like Stat() to check for any of your NPCs in the area and having that make them move randomly or aggro. There's no sense having NPC interaction in NPCs that aren't noticed by clients.
In response to Lummox JR
I'm using a mood datum like what Kuraudo suggested and just need something like...
if(npc in orange(x,npc.spawn_loc))
//continue with AI
else return_to_spawn()


Unfortunately, that doesn't work. I think the issue lies with how I am setting NPCs' spawn_loc variable.

mob/npc/New()
..()
//I tried...
for(var/turf/t in orange(0,src))
src.spawn_loc = t
break

//also
src.spawn_loc = locate() in src.loc
In response to Spunky_Girl
Spunky_Girl wrote:
I'm using a mood datum like what Kuraudo suggested and just need something like...
> if(npc in orange(x,npc.spawn_loc))
> //continue with AI
> else return_to_spawn()
>

Unfortunately, that doesn't work. I think the issue lies with how I am setting NPCs' spawn_loc variable.

Well the only way to tell is to actually look at the value of spawn_loc to confirm it's right. But I recommend against simple binary logic here, since the end effect would be like having the creature on a leash where they absolutely can never pass a certain point. For good AI you're better off giving them a range in which they feel comfortable, and making them increasingly less comfortable as they slip outside of that range.

> mob/npc/New()
> ..()
> //I tried...
> for(var/turf/t in orange(0,src))
> src.spawn_loc = t
> break
>
> //also
> src.spawn_loc = locate() in src.loc
>


The first method should work, but isn't very good because there's no reason to use a loop. The second method is wrong, because src.loc is what you need, not locate() in src.loc. You can't locate() a turf inside another turf; it will always spit out a null.

Lummox JR
Page: 1 2