Advertisement
kolton

Untitled

Oct 18th, 2011
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var _leaderName = "nnqqrands", // ~~~~EDIT THIS~~~~CaSe SeNsItIvE~~~~
  2.     _attack = true, // ~~~~EDIT THIS~~~~true OR false~~~~
  3.     _messages = true; // white 'Say' messages
  4.  
  5. /*
  6. * Follower by kolton
  7. * To initiate the follow sequence make a TP and send command "1".
  8. *
  9. * Commands:
  10. *   1 - take leader's tp from town / move to leader's town
  11. *   2 - take leader's tp to town
  12. *   3 - town manager
  13. *   a - attack toggle for all
  14. *   <charname> a - attack toggle for <charname>
  15. *   aon - attack on for all
  16. *   <charname> aon - attack on for <charname>
  17. *   aoff - attack off for all
  18. *   <charname> aoff - attack off for <charname>
  19. *   bo - barbarian precast
  20. *   <charname> att <skillid> - change skill for <charname>
  21. *   c - get corpse
  22. *   p - pick items
  23. *   r - revive
  24. *   s - toggle stop
  25. *   <charname> s - toggle stop <charname>
  26. *   <charname> tp - make a TP. Needs a TP tome if not using custom libs.
  27. *   quit - exit game
  28. *
  29. *   a2-5 - move to appropriate act (after quest) !NOTE: Disable 'no sound' or game will crash!
  30. *   talk <npc name> - talk to a npc in town
  31. */
  32.  
  33. var _leader, _leaderUnit, _split, _sender, _msg, _piece, _msgtick, _result,
  34.     _stop = false;
  35.  
  36. function NTMain() {
  37.     Include("libs/common/NTCommon.ntl");
  38.     NTC_IncludeLibs();
  39.     NTC_IncludeConfig("NTBot/char_configs");
  40.  
  41.     NT_LoadConfig();
  42.     NTSI_LoadNIPFiles("NTBot/item_configs");
  43.    
  44.     NTA_Initialize();
  45.  
  46.     RegisterEvent(EVENT_GAMEMSG,
  47.         function (msg, type) {
  48.             if (type === 0 && msg.indexOf(_leaderName) > -1) {
  49.                 _split = msg.split(":");
  50.                
  51.                 if (_split.length >= 1 && _split[1] != undefined) {
  52.                     _sender = _split[0].substring(3, _split[0].length - 3);
  53.                     _msg = _split[1].substring(1);
  54.                    
  55.                     if (_sender === _leaderName) {
  56.                         switch (_msg) {
  57.                         case "a": // attack toggle for everyone
  58.                         case (me.name + " a"): // individual attack toggle
  59.                             if (_attack) {
  60.                                 _attack = false;
  61.                                
  62.                                 Say("/w " + _leaderName + " Attack off");
  63.                             } else {
  64.                                 _attack = true;
  65.                                
  66.                                 Say("/w " + _leaderName + " Attack on");
  67.                             }
  68.                             break;
  69.                         case "aoff": // attack off for everyone
  70.                         case (me.name + " aoff"): // individual attack off
  71.                             Delay(150);
  72.                            
  73.                             _attack = false;
  74.                            
  75.                             Say("/w " + _leaderName + " Attack off");
  76.                             break;
  77.                         case "aon": // attack on for everyone
  78.                         case (me.name + " aon"): // individual attack off
  79.                             Delay(150);
  80.                            
  81.                             _attack = true;
  82.                            
  83.                             Say("/w " + _leaderName + " Attack on");
  84.                             break;
  85.                         case "c": // get corpse
  86.                             NTT_GetCorpses();
  87.                             break;
  88.                         case "p": // pick items
  89.                             Say("/w " + _leaderName + " Picking items.");
  90.                             NTSI_PickItems();
  91.                             break;
  92.                         case "r": // revive
  93.                             if (me.mode === 0 || me.mode === 17) {
  94.                                 Say("/w " + _leaderName + " Reviving...");
  95.                                 me.Cancel(0);
  96.                                 me.Cancel(1);
  97.                                 Delay(1000);
  98.                                
  99.                                 if (NTTM_TownMove("portalspot")) {
  100.                                     Say("/w " + _leaderName + " I'M ALIVE!!!");
  101.                                 }
  102.                             }
  103.                            
  104.                             break;
  105.                         case "1": // take leader's tp to outside of town / change act if leader is in another town
  106.                             if (NTC_InTown() && NTC_InTown(_leader)) {
  107.                                 Say("/w " + _leaderName + " Going to leader's town.");
  108.                                 NTTM_CheckAct(CheckLeaderAct());
  109.                                 NTTM_TownMove("portalspot");
  110.                             } else if(NTC_InTown()) {
  111.                                 Say("/w " + _leaderName + " Taking portal to leader.");
  112.                                 NTTM_CheckAct(CheckLeaderAct());
  113.                                 NTTM_TownMove("portalspot");
  114.                                 NTM_UsePortal(null, null, _leaderName);
  115.                                
  116.                                 if (_attack) {
  117.                                     ClearPosition();
  118.                                 }
  119.                             }
  120.                             break;
  121.                         case "2": // take leader's tp to town
  122.                             if (!NTC_InTown()) {
  123.                                 Delay(150);
  124.                                 Say("/w " + _leaderName + " Going to town.");
  125.                                 NTM_UsePortal(null, null, _leaderName);
  126.                             }
  127.                            
  128.                             break;
  129.                         case "3": // town manager
  130.                             if (NTC_InTown()) {
  131.                                 Say("/w " + _leaderName + " Running town manager.");
  132.                                 NTTMGR_TownManager();
  133.                                 NTTM_TownMove("portalspot");
  134.                                 Say("/w " + _leaderName + " Ready.");
  135.                             }
  136.                            
  137.                             break;
  138.                         case "quit": // exit game
  139.                             Say("/w " + _leaderName + " Good riddance.");
  140.                             Delay(500);
  141.                             ExitGame();
  142.                             break;
  143.                         case "bo": // barbarian precast
  144.                             if (me.classid == 4) {
  145.                                 NTP_DoPrecast(true);
  146.                             }
  147.                            
  148.                             break;
  149.                         case "a2": // change act
  150.                         case "a3":
  151.                         case "a4":
  152.                         case "a5":
  153.                             ChangeAct(parseInt(_msg[1], 10));
  154.                             break;
  155.                         case "s": // stop toggle
  156.                         case (me.name + " s"): // individual stop toggle
  157.                             if (_stop) {
  158.                                 _stop = false;
  159.                                
  160.                                 Say("/w " + _leaderName + " resuming");
  161.                             } else {
  162.                                 _stop = true;
  163.                                
  164.                                 Say("/w " + _leaderName + " stopping");
  165.                             }
  166.                            
  167.                             break;
  168.                         case (me.name + " tp"):
  169.                             if (NTC_InTown()) {
  170.                                 FL_Say("I'm in town.");
  171.                                 break;
  172.                             }
  173.                            
  174.                             if (!NTM_MakeTP()) {
  175.                                 FL_Say("Out of scrolls!");
  176.                             }
  177.                            
  178.                             break;
  179.                         }
  180.                     }
  181.                    
  182.                     if (msg.indexOf("talk") > -1) {
  183.                         Talk(msg.split(" ")[2]);
  184.                         NTTM_TownMove("portalspot");
  185.                     }
  186.                    
  187.                     if ((msg.indexOf(me.name) > -1 || msg.indexOf("all ") > -1) && msg.indexOf(" att ") > -1) {
  188.                         _piece = msg.split("att ");
  189.                        
  190.                         if (_piece && me.classid === 1) {
  191.                             Say("/w " + _leaderName + " Attack skill is " + parseInt(_piece[1]));
  192.                             NTConfig_AttackSkill[1] = parseInt(_piece[1]);
  193.                             NTConfig_AttackSkill[3] = parseInt(_piece[1]);
  194.                         }
  195.                     }
  196.                 }
  197.             } else if (type === 4 && msg.indexOf(_leaderName) > -1 && (msg.indexOf("weaken") > -1 || msg.indexOf("timeout") > -1)) {
  198.                 Delay(500);
  199.                 ExitGame();
  200.             }
  201.         }
  202.     );
  203.    
  204.     /*if (NTC_InTown()) {
  205.         NTTMGR_TownManager();
  206.     }*/
  207.    
  208.     if (!GetLeader(_leaderName)) {
  209.         FL_Say("Leader not found or improperly configured file.");
  210.         NTC_Delay(1000);
  211.         ExitGame();
  212.     } else {
  213.         FL_Say("Leader found.");
  214.     }
  215.    
  216.     NTC_PingDelay(200);
  217.    
  218.     while (!NTC_InMyParty(_leaderName)) {
  219.         NTC_Delay(500);
  220.     }
  221.    
  222.     FL_Say("Partied.");
  223.     NTTM_TownMove("portalspot");
  224.    
  225.     while (NTC_InTown()) {
  226.         NTC_Delay(250);
  227.     }
  228.    
  229.     FL_Say("Initiate loop.");
  230.    
  231.     _leaderUnit = GetLeaderUnit(_leaderName);
  232.     _msgtick = GetTickCount();
  233.    
  234.     while (NTC_InMyParty(_leaderName)) { // main loop
  235.         while (!_leaderUnit) {
  236.             if (GetTickCount() - _msgtick > 3000) {
  237.                 FL_Say("Leader unit not found!");
  238.                
  239.                 _msgtick = GetTickCount();
  240.             }
  241.            
  242.             _leaderUnit = GetLeaderUnit(_leaderName);
  243.            
  244.             Delay(500);
  245.         }
  246.    
  247.         while (_stop) {
  248.             NTC_Delay(200);
  249.         }
  250.        
  251.         if (GetDistance(me, _leaderUnit) <= 50) {
  252.             NTM_GetCloserInt(_leaderUnit);
  253.             NTP_DoPrecast(false);
  254.         }
  255.        
  256.         if (_attack) {
  257.             ClearPosition(15);
  258.         }
  259.        
  260.         if (_leader.areaid !== me.areaid && !NTC_InTown()) {
  261.             while (_leader.areaid === 0) {
  262.                 Delay(100);
  263.             }
  264.            
  265.             _result = CheckExit(_leader.areaid);
  266.            
  267.             if (_result) {
  268.                 switch (_result) {
  269.                 case 1:
  270.                     FL_Say("Taking stairs.");
  271.                     Delay(500);
  272.                     NTM_TakeStair(_leader.areaid);
  273.                     break;
  274.                 case 2:
  275.                     FL_Say("Using portal.");
  276.                     Delay(500);
  277.                     NTM_UsePortal(null, _leader.areaid);
  278.                     break;
  279.                 case 3:
  280.                     FL_Say("Taking waypoint.");
  281.                     Delay(500);
  282.                     NTM_TakeWaypoint(_leader.areaid);
  283.                     break;
  284.                 case 4:
  285.                     FL_Say("Special transit.");
  286.                     break;
  287.                 }
  288.                
  289.                 while (me.areaid === 0) {
  290.                     Delay(100);
  291.                 }
  292.                
  293.                 _leaderUnit = GetLeaderUnit(_leaderName);
  294.             }
  295.         }
  296.        
  297.         if (NTC_InTown()) {
  298.             NTTM_TownMove("portalspot");
  299.            
  300.             while (NTC_InTown()) {
  301.                 NTC_Delay(250);
  302.             }
  303.         }
  304.        
  305.         NTC_Delay(25);
  306.     }
  307.    
  308.     NTC_SendMsgToScript("NTBotGame.ntj", "SCRIPT_END");
  309. }
  310.  
  311. //===============================================================================================================
  312.  
  313. function GetLeaderUnit(name) {
  314.     var _unit = NTC_FindUnit(NTC_UNIT_PLAYER);
  315.    
  316.     if (_unit) {
  317.         do {
  318.             if (_unit.name === name) {
  319.                 return _unit;
  320.             }
  321.         } while (_unit.GetNext());
  322.     }
  323.    
  324.     return false;
  325. }
  326.  
  327. function GetLeader(name) {
  328.     _leader = GetPlayerUnit();
  329.    
  330.     if (_leader) {
  331.         do {
  332.             if (_leader.name === name) {
  333.                 return _leader;
  334.             }
  335.         } while (_leader.GetNext());
  336.     }
  337.    
  338.     return false;
  339. }
  340.  
  341. function CheckLeaderAct() {
  342.     if (_leader.areaid <= 39) {
  343.         return 1;
  344.     } else if(_leader.areaid >= 40 && _leader.areaid <= 74) {
  345.         return 2;
  346.     } else if(_leader.areaid >= 75 && _leader.areaid <= 102) {
  347.         return 3;
  348.     } else if(_leader.areaid >= 103 && _leader.areaid <= 108) {
  349.         return 4;
  350.     }
  351.    
  352.     return 5;
  353. }
  354.  
  355. function CheckExit(area) {
  356.     var _unit = GetPresetUnits(me.areaid, NTC_UNIT_TILE);
  357.    
  358.     if (_unit) {
  359.         for (var i = 0; i < _unit.length; i += 1) {
  360.             if (_unit[i].subareaid === area) {
  361.                 return 1;
  362.             }
  363.         }
  364.     }
  365.    
  366.     _unit = NTC_FindUnit(NTC_UNIT_OBJECT, GetLocaleString(3226));
  367.    
  368.     if (_unit) {
  369.         do {
  370.             if (_unit.subareaid === area || _unit.subareaid === area + 256 || _unit.subareaid === area + 768) {
  371.                 return 2;
  372.             }
  373.         } while (_unit.GetNext());
  374.     }
  375.    
  376.     if (NTC_InTown(_leader)) {
  377.         _unit = NTM_GetWaypointInt();
  378.        
  379.         if (_unit) {
  380.             return 3;
  381.         }
  382.     }
  383.    
  384.     if((me.areaid === 74 && area === 54 || me.areaid === 54 && area === 74)) { // arcane portal
  385.         NTM_TakeUnit(NTC_UNIT_OBJECT, 298);
  386.         return 4;
  387.     }
  388.    
  389.     if (me.areaid >= 66 && me.areaid <= 72 && area === 73) { // duriel's wall
  390.         NTM_TakeUnit(NTC_UNIT_OBJECT, 100);
  391.         return 4;
  392.     }
  393.    
  394.     return 0;
  395. }
  396.  
  397. function FL_Say(msg) {
  398.     if (_messages) {
  399.         Say(msg);
  400.     }
  401.    
  402.     return true;
  403. }
  404.  
  405. function QuestInteract(npc) {
  406.     var i;
  407.    
  408.     NTM_GetCloserInt(npc);
  409.    
  410.     for (i = 0; i < 20; i += 1) {
  411.         if (i % 5 === 0) {
  412.             NTC_DoClick(NTC_CLICK_LDOWN, NTC_SHIFT_NONE, npc);
  413.         }
  414.        
  415.         if (i % 10 === 9) {
  416.             while (!GetUIState(0x09)) {
  417.                 me.Cancel(0);
  418.                 NTC_Delay(100);
  419.             }
  420.            
  421.             me.Cancel(1);
  422.             break;
  423.         }
  424.        
  425.         NTC_Delay(200);
  426.     }
  427. }
  428.  
  429. function Talk(name) {
  430.     if (!NTC_InTown()) {
  431.         FL_Say("I'm not in town!");
  432.         return false;
  433.     }
  434.    
  435.     var npc,
  436.         names = ["gheed", "charsi", "akara", "kashya", "cain", "warriv", "fara", "lysander", "greiz",
  437.             "elzix", "jehryn", "meshif", "drognan", "atma", "alkor", "asheara", "ormus", "hratli",
  438.             "halbu", "tyrael", "jamella", "larzuk", "malah", "qual-kehk", "anya", "nihlathak"];
  439.    
  440.     if (names.indexOf(name.toLowerCase()) < 0) {
  441.         FL_Say("Invalid NPC name.");
  442.         return false;
  443.     }
  444.    
  445.     if (!NTTM_TownMove(name.toLowerCase() === "jehryn" ? "palace" : name)) {
  446.         return false;
  447.     }
  448.    
  449.     npc = NTC_FindUnit(1);
  450.    
  451.     if (npc) {
  452.         do {       
  453.             if (npc.name.replace(/ /g, "").toLowerCase() === name) {
  454.                 QuestInteract(npc);
  455.                 return true;
  456.             }
  457.         } while (npc.GetNext());
  458.     }
  459.    
  460.     return false;
  461. }
  462.  
  463. function ChangeAct(act) {
  464.     var npc, portal;
  465.    
  466.     switch (act) {
  467.     case 2:
  468.         NTTM_TownMove("warriv");
  469.        
  470.         npc = NTC_FindUnit(1, 155);
  471.        
  472.         if (npc) {
  473.             QuestInteract(npc);
  474.            
  475.             if (NTT_DoInteract(npc)) {
  476.                 me.SelectNPCMenu(0x0D36);
  477.             }
  478.         }
  479.        
  480.         break;
  481.     case 3:
  482.         NTTM_TownMove("palace");
  483.        
  484.         npc = NTC_FindUnit(1, 201);
  485.        
  486.         if (npc) {
  487.             QuestInteract(npc);
  488.         }
  489.        
  490.         NTTM_TownMove("meshif");
  491.        
  492.         npc = NTC_FindUnit(1, 210);
  493.        
  494.         if (npc) {
  495.             QuestInteract(npc);
  496.            
  497.             if (NTT_DoInteract(npc)) {
  498.                 me.SelectNPCMenu(0x0D38);
  499.             }
  500.         }
  501.        
  502.         break;
  503.     case 4:
  504.         NTTM_TownMove("cain");
  505.        
  506.         npc = NTC_FindUnit(1, 245);
  507.        
  508.         if (npc) {
  509.             QuestInteract(npc);
  510.         }
  511.        
  512.         NTTM_TownMove("portalspot");
  513.        
  514.         if (me.areaid !== 102) {
  515.             NTM_UsePortal(null, 102, null);
  516.         }
  517.        
  518.         target = NTC_FindUnit(2, 342, 20);
  519.        
  520.         NTM_MoveTo(target.areaid, target.x - 3, target.y - 1);
  521.         NTM_TakeUnit(NTC_UNIT_OBJECT, 342);
  522.        
  523.         break;
  524.     case 5:
  525.         NTTM_TownMove("tyrael");
  526.  
  527.         npc = NTC_FindUnit(1, NTC_NPC_ID_TYREAL_ACT_4);
  528.  
  529.         if(npc) {
  530.             QuestInteract(npc);
  531.            
  532.             if (NTT_DoInteract(npc)) {
  533.                 me.SelectNPCMenu(0x58D2);
  534.             }
  535.         }
  536.     }
  537.    
  538.     while (!me.areaid) {
  539.         NTC_Delay(500);
  540.     }
  541.    
  542.     NTC_PingDelay(2000);
  543.     NTTM_TownMove("portalspot");
  544.     Say("Act change successful");
  545. }
  546.  
  547. function ClearPosition(range) {
  548.     var i, orgx, orgy, monList, skipList, target, result,
  549.         tele = NTC_GetSkillLevel(54),
  550.         attackcount = 0;
  551.        
  552.     if (NTConfig_AttackSkill[1] < 0 || NTConfig_AttackSkill[3] < 0) {
  553.         Print("ΓΏc1Set your attacks, noob!");
  554.         return false;
  555.     }
  556.    
  557.     if (!arguments.length) {
  558.         range = 20;
  559.     }
  560.    
  561.     orgx = me.x;
  562.     orgy = me.y;
  563.     skipList = [];
  564.    
  565.     MainLoop : while (_attack && attackcount < 300) {
  566.         monList = [];
  567.         target = NTC_FindUnit(NTC_UNIT_MONSTER);
  568.        
  569.         if (target) {
  570.             do {
  571.                 if (skipList.indexOf(target.gid) < 0) {
  572.                     if (target.IsAttackable()) {
  573.                         if (NTA_IsValidMonster(target)) {
  574.                             if (GetDistance(orgx, orgy, target.x, target.y) <= range && (CheckCollision(me, target, 1) || tele)) {
  575.                                 monList.push(new NTA_MonsterStats(target));
  576.                             }
  577.                         }
  578.                     } else {
  579.                         skipList.push(target.gid);
  580.                     }
  581.                 }
  582.             } while (target.GetNext());
  583.         }
  584.        
  585.         if (monList.length === 0) {
  586.             break;
  587.         }
  588.        
  589.         monList.sort(SortMonsters);
  590.        
  591.         target = NTC_FindUnit(NTC_UNIT_MONSTER, monList[0].gid);
  592.        
  593.         if (target && target.IsAttackable()) {
  594.             result = NTA_Attack(target, attackcount % 30 === 0);
  595.             //Say("!Attacking " + target.name + " " + target.classid);
  596.            
  597.             switch (result) {
  598.             case 1:
  599.                 skipList.push(target.gid);
  600.                 monList.shift();
  601.                 break;
  602.             case 2:
  603.             case 3:
  604.                 attackcount += 1;
  605.                 break;
  606.             default:
  607.                 return false;
  608.             }
  609.         } else {
  610.             monList.shift();
  611.         }
  612.     }
  613.    
  614.     return true;
  615. }
  616.  
  617. function SortMonsters(unitA, unitB) {
  618.     var monID = [58, 59, 60, 61, 62, 101, 102, 103, 104, 105, 229, 278, 279, 280, 281, 282, 312, 645, 646, 647, 667, 668, 669, 670];
  619.    
  620.     if (monID.indexOf(unitA.classid) > -1) {
  621.         return -1;
  622.     } else if (GetDistance(me.x, me.y, unitA.x, unitA.y) < GetDistance(me.x, me.y, unitB.x, unitB.y)) {
  623.         return -1;
  624.     }
  625.    
  626.     return 1;
  627. }
  628.  
  629. function NTA_MonsterStats(unit) {
  630.     this.name = unit.name;
  631.     this.x = unit.x;
  632.     this.y = unit.y;
  633.     this.gid = unit.gid;
  634.     this.hp = unit.hp;
  635.     this.classid = unit.classid;
  636.     this.spectype = unit.spectype;
  637. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement