Wtf? did my post get removed?
I'll rewrite it.
Maybe you should break after finding the npc?
NPC Code:
if (npcs[this.i].x>x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {dir=3}
if (npcs[this.i].x<x&&(abs(npcs[this.i].x-x)>abs(npcs[this.i].y-y))) {dir=1}
if (npcs[this.i].y>y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {dir=2}
if (npcs[this.i].y<y&&(abs(npcs[this.i].x-x)<abs(npcs[this.i].y-y))) {dir=0}
You can use getdir() or the move option.
NPC Code:
dir=getdir(npcs[this.i].x-x,npcs[this.i].y-y);
the move look unsmooth. use option 2.