ID:141027
 
Code:
for(var/mob/human/m in oview(1))


Problem description:
Ok, this is really simple, but I don't know how to do it...
When I use this code on NPCs for example, to make NPCs attack players, it works for the first time... But if the player dies for the NPC or run away, the NPC doesn't attack any other player... That is because he attacks only the player "m"... How can I do a way to after the players is not on his view, to resent this "m"?

Sorry, I don't know if you got it :S
If you're using a for() loop like that, it should loop through all the players, one at a time. Also, try "oview(1,src)". The oview() proc has an implied usr as its center, and it may be affecting it somehow.
This for() loop should also be in a while() loop so your NPC can constantly look around for targets. Not the best way to handle NPC loops, but it works.
while(src) //while the NPC exists
sleep(10) //time between loops
for(var/mob/human/m in oview(1,src))
//blah blah
break //stop the for() loop after one player to not confuse the NPC
//or else it will jump around attacking everyone in no time
//this block of code will all repeat itself as long as src exists.
In response to Kaiochao
By the way, there's a trick to using for() to find a valid target, like so:

while(src.hp >= 0)
//M should be the type of what we're looking for
var/mob/human/M
for(M in oview(src))
//check if M fits any other, non-type conditions
//in this case: is it still alive?
if(M.hp >= 0)
//here's the trick: if we break, the value stays in M even after we leave the loop
break
//if the loop never breaks, M is set to null at the end of the for() loop

//after the for() loop, we can check if we found something: if M is non-null, we found something
if(M)
step_towards(src,M)
else
step_rand(src)
sleep(10)
In response to Kaiochao
THanks a lot Kaiochao... :)