ID:144557
 
Code:
mob
Villager
icon = 'M-norm.dmi'
icon_state = "Normal"
strength = 2
defense = 1
level = 5
dex = 1
money = 10
player = 0
New()
Wander()
..()
proc/Wander()
while(src) //without this your code only runs once
sleep(20) //without this it runs so fast it freezes the game
for(var/mob/M in view(9)) //this defines M during the while code
var/distanced = get_step_to(src,M,9)
if(!distanced)
if(M.player == 1)
if(M in oview(1))
walk(src,0)
if(!M.client) //if no mob return
return..()
else
NPCZ(M) // attack proc here
deathcheck(M)
else
step_towards(src,M) //this might be a better code to use to give more arguments
else
walk_rand(src,20)
else
walk_rand(src,20)


Problem description:
The NPCs will walk around fine and come towards me, but sometimes they skip a few squares and when they are standing next to me attacking me I want them to stop moving but if there are other npcs attacking me at the same time, they all move.

mob/var/target//set up a target var so we can use it

mob
Villager
icon = 'M-norm.dmi'
icon_state = "Normal"
strength = 2
defense = 1
level = 5
dex = 1
money = 10
player = 0
New()
..()
spawn() Wander()
proc/Wander()
while(src)//while src is still there
if(src.target==null||src.target:health<=0)//if src target is null or is under health is under 0
walk_rand(src)//walk src rand
for(var/mob/M in view(9))//for all mobs in view 9
if(M in oview(9)&&M.player==1&&M.client)//if is in oview 9 and is M.Player==1 and is a client
src.target=M//src target is that M
else//else
if(src.target in oview(1))//if src target is in oview 1
NPCZ(src.target)//attack it
deathcheck(src.target)//check if the target is dead
else//if is not in oview 1
step_towards(src,src.target)//step towards src target
spawn(rand(10,25)) Wander()


Not sure if I didi this right but give it a go and let me know.

- Dark Emrald