Advertisement
kolton

Untitled

Dec 30th, 2011
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.13 KB | None | 0 0
  1. function main() {
  2. var i, mercHP, LifeMax, ManaMax,
  3. quitFlag = false,
  4. NTLW_timerLastDrink = [];
  5.  
  6. include("common/NTCommon.dbl");
  7. include("D2Bot.js");
  8. NTC_IncludeConfig();
  9. print("ÿc3Start ToolsThread script");
  10. NT_LoadConfig();
  11.  
  12. for (i = 0; i < 5; i = i + 1) {
  13. NTLW_timerLastDrink[i] = 0;
  14. }
  15.  
  16. // Reset core chicken
  17. me.chickenhp = 0;
  18. me.chickenmp = 0;
  19.  
  20. // General functions
  21. function getPotion(pottype) {
  22. var i, length,
  23. items = me.getItems();
  24.  
  25. if (!items) {
  26. return false;
  27. }
  28.  
  29. for (i = 0, length = items.length; i < length; i = i + 1) {
  30. if (pottype === 78 && items[i].mode === 0 && items[i].location === 3 && items[i].itemType === 78) {
  31. print("ÿc2NTLWÿc1::ÿc2Drinking rejuventation potion from inventory.");
  32. return copyUnit(items[i]);
  33. }
  34.  
  35. if (items[i].mode === 2 && items[i].itemType === pottype) {
  36. return copyUnit(items[i]);
  37. }
  38. }
  39.  
  40. return false;
  41. }
  42.  
  43. function togglePause() {
  44. var script = getScript("default.dbj");
  45.  
  46. if (script) {
  47. if (script.running) {
  48. print("ÿc1Pausing.");
  49. script.pause();
  50. } else {
  51. print("ÿc2Resuming.");
  52. script.resume();
  53. }
  54. }
  55. }
  56.  
  57. function drinkPotion(type) {
  58. var pottype, potion,
  59. tNow = getTickCount();
  60.  
  61. if (type !== 2 && type !== 4) {
  62. if (NTLW_timerLastDrink[type] && (tNow - NTLW_timerLastDrink[type] < 4000)) {
  63. return false;
  64. }
  65. }
  66.  
  67. if (me.mode === 0 || me.mode === 17) {
  68. return false;
  69. }
  70.  
  71. switch (type) {
  72. case 0:
  73. case 3:
  74. pottype = 76;
  75. break;
  76. case 1:
  77. pottype = 77;
  78. break;
  79. default:
  80. pottype = 78;
  81. break;
  82. }
  83.  
  84. potion = getPotion(pottype);
  85.  
  86. if (potion) {
  87. if (me.mode === 0 || me.mode === 17) {
  88. return false;
  89. }
  90.  
  91. if (type < 3) {
  92. potion.interact();
  93. } else {
  94. clickItem(2, potion);
  95. }
  96.  
  97. NTLW_timerLastDrink[type] = getTickCount();
  98.  
  99. return true;
  100. }
  101.  
  102. return false;
  103. }
  104.  
  105. // Event functions
  106. function LifeWatch(life) {
  107. if (NTConfig_LifeThresh > 0 && life < Math.floor(me.hpmax * NTConfig_LifeThresh / 100)) {
  108. drinkPotion(0);
  109. }
  110.  
  111. if (NTConfig_LifeRejuvThresh > 0 && life < Math.floor(me.hpmax * NTConfig_LifeRejuvThresh / 100)) {
  112. drinkPotion(2);
  113. }
  114.  
  115. if (NTConfig_LifeChicken > 0 && !NTC_InTown() && life <= Math.floor(me.hpmax * NTConfig_LifeChicken / 100)) {
  116. removeEventListener("melife", LifeWatch);
  117. D2Bot.updateChickens();
  118. D2Bot.printToConsole("Life Chicken - " + me.hp + "/" + me.hpmax + " (" + getArea().name + ");1");
  119. me.chickenhp = me.hpmax; // Just to trigger the core chicken
  120. }
  121. }
  122.  
  123. function ManaWatch(mana) {
  124. if (NTConfig_ManaThresh > 0 && mana < Math.floor(me.mpmax * NTConfig_ManaThresh / 100)) {
  125. drinkPotion(1);
  126. }
  127.  
  128. if (NTConfig_ManaRejuvThresh > 0 && mana < Math.floor(me.mpmax * NTConfig_ManaRejuvThresh / 100)) {
  129. drinkPotion(2);
  130. }
  131.  
  132. if (NTConfig_ManaChicken > 0 && !NTC_InTown() && mana <= Math.floor(me.mpmax * NTConfig_ManaChicken / 100)) {
  133. removeEventListener("memana", ManaWatch);
  134. D2Bot.updateChickens();
  135. D2Bot.printToConsole("Mana Chicken - " + me.mp + "/" + me.mpmax + " (" + getArea().name + ");1");
  136. me.chickenmp = me.mpmax; // Just to trigger the core chicken
  137. }
  138. }
  139.  
  140. function QuitWithLeader(mode, param1, param2, name1, name2) {
  141. if (mode === 0 || mode === 1 || mode === 3) {
  142. print(name1 + (mode === 0 ? " timed out" : " left"));
  143.  
  144. if (QuitList.indexOf(name1) > -1) {
  145. quitFlag = true;
  146. }
  147. }
  148. }
  149.  
  150. addEventListener("gameevent", QuitWithLeader);
  151. addEventListener("melife", LifeWatch);
  152. addEventListener("memana", ManaWatch);
  153. addEventListener("keyup",
  154. function (key) {
  155. switch (key) {
  156. case 19: // Pause/Break key
  157. togglePause();
  158. break;
  159. }
  160. }
  161. );
  162.  
  163. while (me.ingame) {
  164. if (NTConfig_UseMerc && !NTC_InTown()) {
  165. mercHP = getMercHP();
  166.  
  167. if (mercHP > 0) {
  168. if (mercHP < NTConfig_MercChicken) {
  169. quit();
  170. break;
  171. }
  172.  
  173. if (mercHP < NTConfig_MercRejuvThresh) {
  174. drinkPotion(4);
  175. } else if (mercHP < NTConfig_MercLifeThresh) {
  176. drinkPotion(3);
  177. }
  178. }
  179. }
  180.  
  181. if (quitFlag) {
  182. quit();
  183. break;
  184. }
  185.  
  186. delay(50);
  187. }
  188. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement