View Single Post
  #1  
Old 06-27-2009, 10:57 PM
Prozac Prozac is offline
one of the good guys
Prozac's Avatar
Join Date: Jan 2006
Posts: 245
Prozac is on a distinguished road
Send a message via AIM to Prozac
sorting for lowest array values

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=0i<compuscounti++;)  
      {
      
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=0j<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;

Reply With Quote