so, what I want to do is detect the closest baddy to an npcs x and y location. here is what I have so far .. how can i sort the 2 arrays better?
PHP Code:
// NPC made by Prozac
if (created) {timeout=.05;}
if (timeout)
{
if (compuscount>0)
{
setarray badx,compuscount;
setarray bady,compuscount;
for(i=0; i<compuscount; i++;)
{
badx[i]=abs(compus[i].x-x);
bady[i]=abs(compus[i].y-y);
}
close=0; //close = the index of the baddy closest to npc
for(j=0; j<arraylen(badx); j++;)
{
if (j>1)
{
if (badx[j-1]>badx[j] || bady[j-1]>bady[j]) {close=j;}
}
}
showimg 1,chest.png,compus[close].x,compus[close].y;
// it will do more interesting stuff but showimg is to see which baddy
}
timeout=.05;
}