Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function NTM_MoveTo(area, x, y, retries, clearpath) {
- if (arguments.length < 4) {
- retries = 2;
- }
- if (me.x === x && me.y === y) {
- return true;
- }
- var i, j, midpoint, path,
- retry = 0,
- teleport = !NTC_InTown() && NTC_GetSkillLevel(54);
- if (GetDistance(me.x, me.y, x, y) <= 30 && teleport) {
- for (j = 0 ; j < 2 ; j += 1) {
- if (NTM_TeleportTo(x, y)) {
- return true;
- }
- }
- }
- path = GetPath(area, me.x, me.y, x, y, teleport);
- if (!path) {
- Print("ΓΏc1GetPath failed.");
- return false;
- }
- for (i = 0; i < path.length; i += 1) {
- midpoint = [];
- if (path[i + 1]) { // check if we have the next node
- midpoint = Midpoint(path[i], path[i + 1]);
- }
- // retry check - don't alter path if we failed previous attempt
- // check if we have a midpoint
- // don't midpont last coord
- // check adequate distance
- // check if spot is walkable
- 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)) {
- i += 1;
- path[i] = [midpoint[0], midpoint[1]];
- } else if (GetDistance(me.x, me.y, path[i][0], path[i][1]) >= 45) {
- path[i] = RecudeNode(path[i][0], path[i][1], 2); // sometimes won't tele full distance so we better reduce it a little.
- }
- for (j = 0; j < 2; j += 1) { // try 2 times before full retry
- if (teleport) {
- if (NTM_TeleportTo(path[i][0], path[i][1])) {
- break;
- }
- } else if (NTM_WalkTo(path[i][0], path[i][1])) {
- break;
- }
- }
- if (j < 2) {
- if (clearpath) {
- NTA_ClearPosition(25, true, 2);
- NTP_DoPrecast(false);
- }
- } else {
- retry += 1;
- path = GetPath(area, me.x, me.y, x, y, true);
- Print("Move retry: " + retry);
- if (!path) {
- Print("ΓΏc1GetPath fail.");
- return false;
- }
- i = -1;
- }
- if (retry > retries) {
- return false;
- }
- }
- return true;
- }
- function RecudeNode(x, y, amount) {
- var cx = x > me.x ? x - amount : x + amount,
- cy = y > me.y ? y - amount : y + amount;
- return [cx, cy];
- }
- function Midpoint(coordA, coordB) {
- return [(coordA[0] + coordB[0]) / 2, (coordA[1] + coordB[1]) / 2];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement