NPC Code:
if (created) {
found=0;
hearts=0;
showcharacter;
ap=99;
timeout=.1;
}
if (timeout&&found==0) {
for (this.i=int(random(0,npcscount));found=0;this.i++) {
if (npcs[this.i].hearts>0) found=1;
if (this.i>npcscount) this.i-=npcscount;
}
timeout=.1}
if (timeout&&found==1) {
if (npcs[this.i].hearts<=1) {
found==0;
timeout=.1;
i=0;
}
setcharani walk,;
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;
}
tx =npcs[this.i].x - x;
ty = npcs[this.i].y - y;
dist = (tx*tx+ty*ty)^0.5;
nx = (tx/dist)*1.4;
ny = (ty/dist)*1.4;
move nx,ny,1.4,;
if (npcs[this.i].x in |x-2,x+2|&&npcs[this.i].y in |y-2,y+2|) {
setcharani sword,;
npcs[this.i].hearts-=2;
sleep .25;
if (npcs[this.i].hearts<=0) {
found==0;
timeout=.1;
}
}
timeout=.3
}
Ok, this is supposed to find npcs that are enemies with hearts, and destroy them, then retarget, but it not only wont retarget, sometimes the first target will be a door or something. Why the heck does it do this is it my mistake or a bug in graal programming?