Advertisement
kolton

Untitled

Dec 3rd, 2011
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function NTM_MoveTo(area, x, y, retries, clearpath) {
  2.     if (arguments.length < 4) {
  3.         retries = 2;
  4.     }
  5.    
  6.     if (me.x === x && me.y === y) {
  7.         return true;
  8.     }
  9.    
  10.     var i, j, midpoint, path,
  11.         retry = 0,
  12.         teleport = !NTC_InTown() && NTC_GetSkillLevel(54);
  13.    
  14.     if (GetDistance(me.x, me.y, x, y) <= 30 && teleport) {
  15.         for (j = 0 ; j < 2 ; j += 1) {
  16.             if (NTM_TeleportTo(x, y)) {
  17.                 return true;
  18.             }
  19.         }
  20.     }
  21.    
  22.     path = GetPath(area, me.x, me.y, x, y, teleport);
  23.    
  24.     if (!path) {
  25.         Print("ΓΏc1GetPath failed.");
  26.        
  27.         return false;
  28.     }
  29.    
  30.     for (i = 0; i < path.length; i += 1) {
  31.         midpoint = [];
  32.        
  33.         if (path[i + 1]) { // check if we have the next node
  34.             midpoint = Midpoint(path[i], path[i + 1]);
  35.         }
  36.        
  37.         // retry check - don't alter path if we failed previous attempt
  38.         // check if we have a midpoint
  39.         // don't midpont last coord
  40.         // check adequate distance
  41.         // check if spot is walkable
  42.         if (retry === 0 && midpoint.length && i !== path.length - 1 && GetDistance(me.x, me.y, midpoint[0], midpoint[1]) <= 45 && CheckCollision(me.areaid, midpoint[0], midpoint[1], 1)) {
  43.             i += 1;
  44.             path[i] = [midpoint[0], midpoint[1]];
  45.         } else if (GetDistance(me.x, me.y, path[i][0], path[i][1]) >= 45) {
  46.             path[i] = RecudeNode(path[i][0], path[i][1], 2); // sometimes won't tele full distance so we better reduce it a little.
  47.         }
  48.        
  49.         for (j = 0; j < 2; j += 1) { // try 2 times before full retry
  50.             if (teleport) {
  51.                 if (NTM_TeleportTo(path[i][0], path[i][1])) {
  52.                     break;
  53.                 }
  54.             } else if (NTM_WalkTo(path[i][0], path[i][1])) {
  55.                 break;
  56.             }
  57.         }
  58.        
  59.         if (j < 2) {
  60.             if (clearpath) {
  61.                 NTA_ClearPosition(25, true, 2);
  62.                 NTP_DoPrecast(false);
  63.             }
  64.         } else {
  65.             retry += 1;
  66.             path = GetPath(area, me.x, me.y, x, y, true);
  67.            
  68.             Print("Move retry: " + retry);
  69.            
  70.             if (!path) {
  71.                 Print("ΓΏc1GetPath fail.");
  72.                
  73.                 return false;
  74.             }
  75.            
  76.             i = -1;
  77.         }
  78.        
  79.         if (retry > retries) {
  80.             return false;
  81.         }
  82.     }
  83.    
  84.     return true;
  85. }
  86.  
  87. function RecudeNode(x, y, amount) {
  88.     var cx = x > me.x ? x - amount : x + amount,
  89.         cy = y > me.y ? y - amount : y + amount;
  90.        
  91.     return [cx, cy];
  92. }
  93.  
  94. function Midpoint(coordA, coordB) {
  95.     return [(coordA[0] + coordB[0]) / 2, (coordA[1] + coordB[1]) / 2];
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement