Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function main() {
- var i, mercHP, LifeMax, ManaMax,
- quitFlag = false,
- NTLW_timerLastDrink = [];
- include("common/NTCommon.dbl");
- include("D2Bot.js");
- NTC_IncludeConfig();
- print("ÿc3Start ToolsThread script");
- NT_LoadConfig();
- for (i = 0; i < 5; i = i + 1) {
- NTLW_timerLastDrink[i] = 0;
- }
- // Reset core chicken
- me.chickenhp = 0;
- me.chickenmp = 0;
- // General functions
- function getPotion(pottype) {
- var i, length,
- items = me.getItems();
- if (!items) {
- return false;
- }
- for (i = 0, length = items.length; i < length; i = i + 1) {
- if (pottype === 78 && items[i].mode === 0 && items[i].location === 3 && items[i].itemType === 78) {
- print("ÿc2NTLWÿc1::ÿc2Drinking rejuventation potion from inventory.");
- return copyUnit(items[i]);
- }
- if (items[i].mode === 2 && items[i].itemType === pottype) {
- return copyUnit(items[i]);
- }
- }
- return false;
- }
- function togglePause() {
- var script = getScript("default.dbj");
- if (script) {
- if (script.running) {
- print("ÿc1Pausing.");
- script.pause();
- } else {
- print("ÿc2Resuming.");
- script.resume();
- }
- }
- }
- function drinkPotion(type) {
- var pottype, potion,
- tNow = getTickCount();
- if (type !== 2 && type !== 4) {
- if (NTLW_timerLastDrink[type] && (tNow - NTLW_timerLastDrink[type] < 4000)) {
- return false;
- }
- }
- if (me.mode === 0 || me.mode === 17) {
- return false;
- }
- switch (type) {
- case 0:
- case 3:
- pottype = 76;
- break;
- case 1:
- pottype = 77;
- break;
- default:
- pottype = 78;
- break;
- }
- potion = getPotion(pottype);
- if (potion) {
- if (me.mode === 0 || me.mode === 17) {
- return false;
- }
- if (type < 3) {
- potion.interact();
- } else {
- clickItem(2, potion);
- }
- NTLW_timerLastDrink[type] = getTickCount();
- return true;
- }
- return false;
- }
- // Event functions
- function LifeWatch(life) {
- if (NTConfig_LifeThresh > 0 && life < Math.floor(me.hpmax * NTConfig_LifeThresh / 100)) {
- drinkPotion(0);
- }
- if (NTConfig_LifeRejuvThresh > 0 && life < Math.floor(me.hpmax * NTConfig_LifeRejuvThresh / 100)) {
- drinkPotion(2);
- }
- if (NTConfig_LifeChicken > 0 && !NTC_InTown() && life <= Math.floor(me.hpmax * NTConfig_LifeChicken / 100)) {
- removeEventListener("melife", LifeWatch);
- D2Bot.updateChickens();
- D2Bot.printToConsole("Life Chicken - " + me.hp + "/" + me.hpmax + " (" + getArea().name + ");1");
- me.chickenhp = me.hpmax; // Just to trigger the core chicken
- }
- }
- function ManaWatch(mana) {
- if (NTConfig_ManaThresh > 0 && mana < Math.floor(me.mpmax * NTConfig_ManaThresh / 100)) {
- drinkPotion(1);
- }
- if (NTConfig_ManaRejuvThresh > 0 && mana < Math.floor(me.mpmax * NTConfig_ManaRejuvThresh / 100)) {
- drinkPotion(2);
- }
- if (NTConfig_ManaChicken > 0 && !NTC_InTown() && mana <= Math.floor(me.mpmax * NTConfig_ManaChicken / 100)) {
- removeEventListener("memana", ManaWatch);
- D2Bot.updateChickens();
- D2Bot.printToConsole("Mana Chicken - " + me.mp + "/" + me.mpmax + " (" + getArea().name + ");1");
- me.chickenmp = me.mpmax; // Just to trigger the core chicken
- }
- }
- function QuitWithLeader(mode, param1, param2, name1, name2) {
- if (mode === 0 || mode === 1 || mode === 3) {
- print(name1 + (mode === 0 ? " timed out" : " left"));
- if (QuitList.indexOf(name1) > -1) {
- quitFlag = true;
- }
- }
- }
- addEventListener("gameevent", QuitWithLeader);
- addEventListener("melife", LifeWatch);
- addEventListener("memana", ManaWatch);
- addEventListener("keyup",
- function (key) {
- switch (key) {
- case 19: // Pause/Break key
- togglePause();
- break;
- }
- }
- );
- while (me.ingame) {
- if (NTConfig_UseMerc && !NTC_InTown()) {
- mercHP = getMercHP();
- if (mercHP > 0) {
- if (mercHP < NTConfig_MercChicken) {
- quit();
- break;
- }
- if (mercHP < NTConfig_MercRejuvThresh) {
- drinkPotion(4);
- } else if (mercHP < NTConfig_MercLifeThresh) {
- drinkPotion(3);
- }
- }
- }
- if (quitFlag) {
- quit();
- break;
- }
- delay(50);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement