Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function NTM_MoveTo(areaid, x, y, retry, clearpath)
- {
- var i, n;
- var _teleport;
- var _path;
- var _retry = 0;
- if(x == me.x && y == me.y)
- return true;
- if(arguments.length < 4)
- retry = 3;
- if(arguments.length < 5)
- clearpath = false;
- if(NTC_InTown())
- _teleport = false;
- else
- _teleport = true;
- if(NTC_GetSkillLevel(54) < 1)
- {
- ExitGame();
- SendCopyData("D2NT Manager", null, 7<<16, "ÿE00000Enigma Glitch Fixed");
- }
- _path = GetPath(areaid, me.x, me.y, x, y, _teleport);
- if(!_path)
- return false;
- for(i = 0 ; i < _path.length ; i++)
- {
- for(n = 0 ; n < 2 ; n++)
- {
- if(_teleport)
- {
- if(NTM_TeleportTo(_path[i][0]+Random(-n, n), _path[i][1]+Random(-n, n)))
- break;
- }
- else
- {
- if(NTM_WalkTo(_path[i][0], _path[i][1]))
- break;
- }
- }
- if(n < 2)
- {
- if(clearpath)
- {
- if(!NTA_ClearPosition(20, true, 2))
- return false;
- NTP_DoPrecast(false);
- NTM_MoveTo(me.areaid, _path[i][0], _path[i][1], 1);
- }
- }
- else if(_retry < retry)
- {
- _path = GetPath(areaid, me.x, me.y, x, y, _teleport);
- if(!_path)
- return false;
- i = -1;
- _retry++;
- }
- else
- return false;
- }
- return true;
- }
- function NTM_MoveToPresetUnit(areaid, unittype, classid, offsetx, offsety, clearpath)
- {
- var i, n;
- var _unit;
- if(arguments.length < 4)
- {
- offsetx = 0;
- offsety = 0;
- }
- if(arguments.length < 6)
- clearpath = false;
- for(i = 0 ; i <= 2 ; i++)
- {
- _unit = GetPresetUnits(areaid, unittype);
- if(_unit)
- {
- for(n = 0 ; n < _unit.length ; n++)
- {
- if(_unit[n].id == classid)
- return NTM_MoveTo(areaid, _unit[n].roomx*5+_unit[n].x+offsetx, _unit[n].roomy*5+_unit[n].y+offsety, 3, clearpath);
- }
- }
- if(i < 2)
- NTC_Delay(500);
- }
- return false;
- }
- function NTM_MoveToStair(areaid, subareaid, offsetx, offsety, clearpath)
- {
- var i, n;
- var _unit;
- if(arguments.length < 3)
- {
- offsetx = 0;
- offsety = 0;
- }
- if(arguments.length < 5)
- clearpath = false;
- for(i = 0 ; i <= 2 ; i++)
- {
- _unit = GetPresetUnits(areaid, NTC_UNIT_TILE);
- if(_unit)
- {
- for(n = 0 ; n < _unit.length ; n++)
- {
- if(_unit[n].subareaid == subareaid)
- return NTM_MoveTo(areaid, _unit[n].roomx*5+_unit[n].x+offsetx, _unit[n].roomy*5+_unit[n].y+offsety, 3, clearpath);
- }
- }
- if(i < 2)
- NTC_Delay(500);
- }
- return false;
- }
- function NTM_TeleportTo(x, y)
- {
- NTC_CastSkill(54, NTC_HAND_RIGHT, x, y);
- for(var i = 0 ; i < 15 ; i++)
- {
- if(Math.abs(me.x-x) < 4 && Math.abs(me.y-y) < 4)
- return true;
- NTC_Delay(NTC_DELAY_FRAME);
- }
- return false;
- }
- function NTM_WalkTo(x, y)
- {
- var i;
- var _prex1, _prey1;
- var _prex2, _prey2;
- if(me.runwalk == 0)
- me.runwalk = 1;
- for(i = 0 ; i < 480 ; i++)
- {
- if((i % 10) == 0)
- {
- if((i % 60) == 0)
- {
- _prex1 = me.x;
- _prey1 = me.y;
- if((i % 120) == 0)
- {
- _prex2 = me.x;
- _prey2 = me.y;
- }
- }
- ClickMap(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, x, y);
- }
- NTC_Delay(NTC_DELAY_FRAME);
- if(Math.abs(me.x-x) < 2 && Math.abs(me.y-y) < 2)
- break;
- if((i % 10) == 9)
- {
- ClickMap(NTC_CLICK_LUP, NTC_SHIFT_NONE, null);
- NTC_Delay(NTC_DELAY_FRAME);
- if((i % 60) == 59)
- {
- if(me.x == _prex1 && me.y == _prey1 && !NTC_InTown())
- {
- NTA_ClearPosition(2);
- NTP_DoPrecast(false);
- }
- if((i % 120) == 119 && me.x == _prex2 && me.y == _prey2)
- return false;
- }
- }
- }
- ClickMap(NTC_CLICK_LUP, NTC_SHIFT_NONE, null);
- NTC_Delay(NTC_DELAY_FRAME);
- return (i < 480);
- }
- function NTM_TakeUnit(unittype, classid)
- {
- var _unit;
- var _prearea;
- _unit = NTC_FindUnit(unittype, classid, 5);
- if(!_unit)
- return false;
- _prearea = me.areaid;
- for(var i = 0 ; i < 20 ; i++)
- {
- if((i % 5) == 0)
- {
- if(i == 10)
- NTM_MoveTo(_prearea, me.x+6, me.y+6);
- if(NTM_GetCloserInt(_unit))
- NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, _unit);
- }
- NTC_Delay(200);
- if(me.areaid != _prearea)
- break;
- }
- while(me.areaid == 0)
- NTC_Delay(200);
- if(me.areaid == _prearea)
- return false;
- NTC_PingDelay(NTConfig_AreaDelay);
- return true;
- }
- function NTM_TakeStair(areaid)
- {
- var _unit;
- var _prearea;
- _unit = NTM_GetStairInt(areaid);
- if(!_unit)
- return false;
- _prearea = me.areaid;
- for(var i = 0 ; i < 20 ; i++)
- {
- if((i % 5) == 0)
- {
- if(i == 10)
- NTM_MoveTo(_prearea, me.x+6, me.y+6);
- if(NTM_GetCloserInt(_unit))
- NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, _unit);
- }
- NTC_Delay(200);
- if(me.areaid != _prearea)
- break;
- }
- while(me.areaid == 0)
- NTC_Delay(200);
- if(me.areaid == _prearea)
- return false;
- NTC_PingDelay(NTConfig_AreaDelay);
- return true;
- }
- function NTM_TakeWaypoint(areaid)
- {
- var _unit;
- if(me.areaid == areaid)
- return true;
- _unit = NTM_GetWaypointInt();
- if(!_unit)
- return false;
- if(NTC_InTown())
- me.Cancel(1);
- for(var i = 0 ; i < 20 ; i++)
- {
- if((i % 10) == 0)
- {
- if(NTM_GetCloserInt(_unit))
- NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, _unit);
- }
- NTC_Delay(200);
- if(GetUIState(0x14))
- {
- if(me.TakeWaypoint(areaid))
- {
- NTC_PingDelay(NTConfig_AreaDelay);
- return true;
- }
- break;
- }
- }
- return false;
- }
- function NTM_UsePortal(how, dest, ownername, portal)
- {
- if(me.areaid == dest)
- return true;
- if(NTC_InTown())
- me.Cancel(1);
- if(NTM_ChangeAreaInt(how, dest, ownername, portal))
- {
- NTC_PingDelay(NTConfig_AreaDelay);
- return true;
- }
- return false;
- }
- function NTM_MakeTP(dest)
- {
- var _usetp = true;
- var _portal;
- var _portalname;
- if(NTC_InTown())
- return true;
- if(arguments.length < 1)
- _usetp = false;
- if(!NTC_CastSkill(220, NTC_HAND_RIGHT))
- return false;
- NTC_PingDelay(500);
- _portalname = GetLocaleString(3226);
- for(var i = 0 ; i <= 2 ; i++)
- {
- _portal = NTC_FindUnit(NTC_UNIT_OBJECT, _portalname);
- if(_portal)
- {
- do
- {
- if(_portal.mode == 2 && NTC_CheckOwner(_portal))
- {
- if(_usetp)
- return NTM_UsePortal("BluePortal", dest, me.name, _portal);
- return true;
- }
- } while(_portal.GetNext());
- }
- if(i < 2)
- NTC_Delay(500);
- }
- return false;
- }
- // Internal function
- function NTM_GetStairInt(areaid)
- {
- var _tile;
- for(var i = 0 ; i <= 2 ; i++)
- {
- _tile = NTC_FindUnit(NTC_UNIT_TILE);
- if(_tile)
- {
- do
- {
- if(!areaid || _tile.subareaid == areaid)
- return _tile;
- } while(_tile.GetNext());
- }
- if(i < 2)
- NTC_Delay(500);
- }
- return null;
- }
- function NTM_GetWaypointInt()
- {
- var _waypoint;
- var _classid;
- for(var i = 0 ; i <= 2 ; i++)
- {
- _waypoint = NTC_FindUnit(NTC_UNIT_OBJECT);
- if(_waypoint)
- {
- do
- {
- _classid = _waypoint.classid;
- if(_classid == 119 || _classid == 145 || _classid == 156 || _classid == 157
- || _classid == 237 || _classid == 238 || _classid == 288 || _classid == 323
- || _classid == 324 || _classid == 398 || _classid == 402 || _classid == 429
- || _classid == 494 || _classid == 496 || _classid == 511 || _classid == 539)
- return _waypoint;
- } while(_waypoint.GetNext());
- }
- if(i < 2)
- NTC_Delay(500);
- }
- return null;
- }
- function NTM_ChangeAreaInt(how, dest, ownername, myportal)
- {
- var _portal;
- var _playerportal = false;
- var _prearea;
- if(how == "BluePortal")
- {
- if(!ownername)
- ownername = me.name;
- _playerportal = true;
- }
- if(arguments.length > 3 && myportal)
- _portal = myportal;
- else
- {
- _portal = NTM_FindCorrectPortalInt(_playerportal, ownername);
- if(_portal < 0)
- _portal = NTM_FindPortalAreaInt(dest);
- if(_portal == -1)
- return false;
- }
- if(!_portal)
- return false;
- _prearea = me.areaid;
- for(var i = 0 ; i < 20 ; i++)
- {
- if((i % 5) == 0)
- {
- if(i == 10)
- NTM_MoveTo(_prearea, me.x+6, me.y+6);
- if(NTM_GetCloserInt(_portal))
- NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, _portal);
- }
- NTC_Delay(200);
- if(me.areaid != _prearea)
- break;
- }
- while(me.areaid == 0)
- NTC_Delay(200);
- return (me.areaid == dest);
- }
- function NTM_FindCorrectPortalInt(blueportal, ownername)
- {
- var _portal;
- var _portalname;
- _portalname = GetLocaleString(3226);
- if(blueportal)
- {
- for(var i = 0 ; i <= 2 ; i++)
- {
- _portal = NTC_FindUnit(NTC_UNIT_OBJECT, _portalname);
- if(_portal)
- {
- do
- {
- if(_portal.mode == 2 && NTC_CheckOwner(_portal, ownername) && GetDistance(me, _portal) <= 30)
- return _portal;
- } while(_portal.GetNext());
- }
- if(i < 2)
- NTC_Delay(500);
- }
- return -2;
- }
- else
- {
- for(var i = 0 ; i <= 2 ; i++)
- {
- _portal = NTC_FindUnit(NTC_UNIT_OBJECT, _portalname);
- if(_portal)
- {
- do
- {
- if(_portal.mode == 2 && !_portal.GetParent())
- return _portal;
- } while(_portal.GetNext());
- }
- if(i < 2)
- NTC_Delay(500);
- }
- }
- return -3;
- }
- function NTM_FindPortalAreaInt(dest)
- {
- var _portal;
- var _portalname;
- _portalname = GetLocaleString(3226);
- for(var i = 0 ; i <= 2 ; i++)
- {
- _portal = NTC_FindUnit(NTC_UNIT_OBJECT, _portalname);
- if(_portal)
- {
- do
- {
- if(_portal.mode == 2 && _portal.subareaid == dest)
- {
- if(_portal.GetParent())
- {
- if(NTC_CheckOwner(_portal) || NTC_InMyParty(_portal.GetParent()))
- return _portal;
- }
- else
- return _portal;
- }
- } while(_portal.GetNext());
- }
- if(i < 2)
- NTC_Delay(500);
- }
- return -1;
- }
- function NTM_GetCloserInt(unit)
- {
- if(GetDistance(me, unit) > 2)
- return NTM_MoveTo(unit.areaid, unit.x, unit.y);
- return true;
- }
- // vector class
- function vector()
- {
- if(arguments.length == 2)
- {
- this.x = arguments[0];
- this.y = arguments[1];
- }
- else if(arguments.length == 1)
- {
- this.x = arguments[0].x;
- this.y = arguments[0].y;
- }
- else
- {
- this.x = 0;
- this.y = 0;
- }
- this.rotate = vector_rotate;
- this.normalize = vector_normalize;
- this.length = vector_length;
- this.setlength = vector_setlength;
- this.toString = vector_toString;
- this.set = vector_set;
- this.angle = vector_angle;
- }
- function vector_rotate(degree)
- {
- if(!degree)
- return true;
- l = this.length();
- if(!l)
- return false;
- this.normalize();
- rad = degree * (Math.PI/180);
- nx = this.x * Math.cos(rad) - this.y * Math.sin(rad);
- ny = this.x * Math.sin(rad) + this.y * Math.cos(rad);
- this.x = nx;
- this.y = ny;
- this.normalize();
- if(l != 1)
- this.setlength(l);
- return true;
- }
- function vector_angle(v)
- {
- rad_degree = 180 / Math.PI;
- return Math.acos((this.x*v.x) + (this.y*v.y)) * rad_degree;
- }
- function vector_length()
- {
- return Math.sqrt((this.x*this.x) + (this.y*this.y));
- }
- function vector_setlength(length)
- {
- this.normalize();
- this.x *= length;
- this.y *= length;
- }
- function vector_normalize()
- {
- l = this.length();
- if(!l)
- return false;
- this.x /= l;
- this.y /= l;
- return true;
- }
- function vector_toString()
- {
- str = "(";
- str += Math.round(this.x*1000)/1000;
- str += " , ";
- str += Math.round(this.y*1000)/1000;
- str += ") : ";
- str += Math.round(this.length()*1000)/1000;
- return str;
- }
- function vector_set(tx, ty)
- {
- if(arguments.length == 1)
- {
- this.x = tx.x;
- this.y = tx.y;
- }
- else if(arguments.length == 2)
- {
- this.x = tx;
- this.y = ty;
- }
- }
- // coord class
- function coord()
- {
- this.data = null;
- if(arguments.length == 3)
- {
- this.x = arguments[0];
- this.y = arguments[1];
- this.data = arguments[2];
- }
- else if(arguments.length == 2)
- {
- this.x = arguments[0];
- this.y = arguments[1];
- }
- else if(arguments.length == 1)
- {
- this.x = arguments[0].x;
- this.y = arguments[0].y;
- }
- else
- {
- this.x = 0;
- this.y = 0;
- }
- this.dist = coord_dist;
- this.dist2 = coord_dist2;
- this.dir = coord_dir;
- this.move = coord_move;
- this.set = coord_set;
- this.toString = coord_toString;
- }
- function coord_set(tx, ty, d)
- {
- if(arguments.length == 1)
- {
- this.x = tx.x;
- this.y = tx.y;
- if(tx.data)
- this.data = tx.data;
- else
- this.data = null;
- }
- else if(arguments.length == 2)
- {
- this.x = tx;
- this.y = ty;
- this.data = null;
- }
- else if(arguments.length == 3)
- {
- this.x = tx;
- this.y = ty;
- this.data = d;
- }
- }
- function coord_dist(tx, ty)
- {
- if(arguments.length == 1)
- {
- vx = this.x - tx.x;
- vy = this.y - tx.y;
- return Math.round(Math.sqrt((vx*vx) + (vy*vy)));
- }
- else if(arguments.length == 2)
- {
- vx = this.x - tx;
- vy = this.y - ty;
- return Math.round(Math.sqrt((vx*vx) + (vy*vy)));
- }
- }
- function coord_dist2(tx, ty)
- {
- if(arguments.length == 1)
- {
- vx = this.x - tx.x;
- vy = this.y - tx.y;
- return Math.floor((vx*vx) + (vy*vy));
- }
- else if(arguments.length == 2)
- {
- vx = this.x - tx;
- vy = this.y - ty;
- return Math.floor((vx*vx) + (vy*vy));
- }
- }
- function coord_dir(tx, ty)
- {
- if(arguments.length == 1)
- {
- v = new vector(tx.x-this.x, tx.y-this.y);
- v.normalize();
- return v;
- }
- else if(arguments.length == 2)
- {
- v = new vector(tx-this.x, ty-this.y);
- v.normalize();
- return v;
- }
- }
- function coord_move(vec, d)
- {
- if(d)
- {
- this.x += Math.round(vec.x*d);
- this.y += Math.round(vec.y*d);
- return true;
- }
- else if(vec.length())
- {
- this.x += Math.round(vec.x);
- this.y += Math.round(vec.y);
- return true;
- }
- return false;
- }
- function coord_toString()
- {
- return "( " + this.x + " , " + this.y + " ) " + this.data;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement