Union Client Scripts

Forum for alternative clients, mods & discussions on the same.

Moderator: Phades

Union Client Scripts

Postby robinx » Sun May 26, 2013 11:41 am

Do any of you have any scripts on client union they would like to share? if so, please send them in this topic :)

if anyone knows how to start farm bot in union client, please let me know the answer: D

Edit by borka: url of Union public Announcement in HnH russian forums
http://www.havenandhearth.ru/viewtopic.php?f=17&t=1522

Edit2: Source Code at GitHub:
https://github.com/APXEOLOG/hnh_union
robinx
 
Posts: 106
Joined: Sat Jul 16, 2011 2:40 pm

Union FARM BOT

Postby A684 » Mon May 27, 2013 11:57 am

Hello, I would like to ask what you need to fix it to make it work? after start-up and selecting plants issued: Script finished
P.S: read the documentation, did not understand: \

Image
A684
 
Posts: 14
Joined: Sat Jan 01, 2011 1:47 pm

Re: Union Client Scripts

Postby WitchKiller34 » Mon May 27, 2013 6:45 pm

Here are the fixed farmer and taker scripts:

note: farmer needs to have water bucket(s) & waterflask/skin, if water runs out then script stops... also have a shovel in the inventory to speed it up and consume less water.
Code: Select all
//#! name = Farmer
//#! uniq = farmer_apxproductions
//#! icon = gfx/invobjs/seed-hops
// Globals
var inventory = checkInventory();
var harvester;

// Settings
var actionTimeout = 1000 * 60 * 2;   // Lag timeout
var cannotPlantTimeout = 1000 * 10;   // Non-plowed tile timeout
var cropRadius = 3;               // Ðàäèóñ â êîòîðì èäåò ïîèñê (âåðõ, ïðàâî, íèç, ëåâî)

// Flags
var stopFlag = false;

/* =========================================================================== */
/* ==============================   ÌÎÐÊÎÂÊÀ   ============================== */
/* =========================================================================== */
function CarrotHarvester() {
    this.cropName = "plants/carrot";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/carrot";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 4;                  // Ñòàäèÿ îáðàáîòêè
}
CarrotHarvester.prototype.processHarvestedGoods = function() {
    inventory = checkInventory();
   
   var seeds = inventory.getItems(this.cropSeedName);
   var free = inventory.freeSlots();
   var i = 0;
   if (free < 3) {
      inventory.sortItems(seeds, "quality", false);
      for (i = 0; i < 3 - free; i++) {
         // Åñòü ìîðêîâü åñëè ãîëîäåí
         if (jGetHungry() < 95) {
            if (seeds[i].isActual()) {
               seeds[i].iact();
               jWaitPopup(actionTimeout);
               jSelectContextMenu("Eat");
               waitUnActual(seeds[i]);
            }
         }
         // Âûáðîñèòü ëèøêó
         if (seeds[i].isActual()) {
            seeds[i].drop();
         }
      }
   }
};

/* =========================================================================== */
/* ==============================   ÑÂÅÊËÀ      ============================== */
/* =========================================================================== */
function BeetHarvester() {
    this.cropName = "plants/beetroot";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/beetroot";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 3;                  // Ñòàäèÿ îáðàáîòêè
}
BeetHarvester.prototype.processHarvestedGoods = function() {
    inventory = checkInventory();
   
   var seeds = inventory.getItems(this.cropSeedName);
   var free = inventory.freeSlots();
   var i = 0;
   //dropsleaves
   var leaves = inventory.getItems("beetrootleaves");
   if(leaves.length > 0)
      if(leaves[0].isActual())
         leaves[0].dropSuchAll();
   while(leaves.length > 0)
   {
      leaves = inventory.getItems("beetrootleaves");
      jSleep(500);
   }
   if (free < 6) {
      inventory.sortItems(seeds, "quality", false);
      for (i = 0; i < 4 - free; i++) {
         if (jGetHungry() < 95) {
            if (seeds[i].isActual()) {
               seeds[i].iact();
               jWaitPopup(actionTimeout);
               jSelectContextMenu("Eat");
               waitUnActual(seeds[i]);
            }
         }
         if (seeds[i].isActual()) {
            seeds[i].drop();
         }
      }
   }
};

/* =========================================================================== */
/* ==============================   ÂÈÍÎÃÐÀÄ   ============================== */
/* =========================================================================== */
function WineHarvester() {
    this.cropName = "plants/wine";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/seed-grape";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.packName = "invobjs/grapes";
   this.cropStage = 3;                  // Ñòàäèÿ îáðàáîòêè
   this.barrelID = 0; //id of barrel
   this.pressID = 0; //id of winepress
   this.containerID = 0;
   this.startCoord = jCoord(0, 0);
   this.fieldSize = jCoord(0, 0);
   this.offsMove = jCoord(2, 0);
}

WineHarvester.prototype.selectObjects = function() {
   var bar = jSelectObject("Select barrel...");
   if(bar.name().indexOf("barrel") == -1)
   {
      jToConsole("ERROR: This is not a barrel!");
      return false;
   }
   else this.barrelID = bar;
   var pr = jSelectObject("Select winepress...");
   if(pr.name().indexOf("winepress") == -1)
   {
      jToConsole("ERROR: This is not a press!");
      return false;
   }
   else this.pressID = pr;
   var cnt = jSelectObject("Select container (chest/lchest)...");
   if(cnt.name().indexOf("cclosed") == -1 && cnt.name().indexOf("lchest") == -1)
   {
      jToConsole("ERROR: This is not a container!");
      return false;
   }
   else this.containerID = cnt;
   return true;
}

WineHarvester.prototype.selectRect = function() {
   var offs = jCoord(0, 0);
   var size = jCoord(1, 1);
   var confirm = false;
   jDrawGroundRect(offs, size);
   var blist = ["West", "East", "North", "South", "Inc width", "Inc height", "Dec width", "Dec height", "Confirm", "Exit"];
   var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(105, blist.length * 25 + 15), "Test");
   var label = jGUILabel(selectWindow, jCoord(5, 5), "Select grapes area.");
   for(var i = 0; i < blist.length; i++)
      jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
   selectWindow.toggleCloseButton();
   var btext = "";
   while(btext != "Exit"){
      btext = selectWindow.waitButtonClick();
      if(btext == blist[0]) offs.x--;
      if(btext == blist[1]) offs.x++;
      if(btext == blist[2]) offs.y--;
      if(btext == blist[3]) offs.y++;
      if(btext == blist[4]) size.x++;
      if(btext == blist[5]) size.y++;
      if(btext == blist[6]) if(size.x > 1) size.x--;
      if(btext == blist[7]) if(size.y > 1) size.y--;
      if(btext == blist[8]) {confirm = true; break;}
      jDrawGroundRect(offs, size);
   }
   selectWindow.destroy();
   jDrawGroundRect(offs, jCoord(0, 0));
   this.startCoord = jMyCoords().add(offs.mul(11));
   this.fieldSize = size;
   return confirm;
}

WineHarvester.prototype.processHarvesting = function() {
   var result = false;
   var grapes = jGetObjectsInRect(this.startCoord, this.fieldSize, this.cropStage, [this.cropName]);
   inventory = checkInventory();
   var cuts = Math.floor((inventory.freeSlots() - 1)/3); //õóéïèçäà
   if(cuts > 8) cuts = 8;
   var currentgrape = 0;
   while(1)
   {
      if(currentgrape >= grapes.length) {result = true; break;}
      //cursor
      if(!jIsCursor("harvest")) {
         jSendAction("harvest");
         jWaitCursor("harvest", actionTimeout);
      }
      //harvesting grapes
      for(var i = 0; i < cuts; i++)
      {
         if(jGetStamina() < 50) drinkWater();
         if(currentgrape >= grapes.length) break;
         jDoClick(grapes[currentgrape], 1, 0);
         jWaitProgress(actionTimeout);
         currentgrape++;
      }
      //got pack of grapes
      resetCursor();
      //goes to press
      jAbsClick(this.pressID.position().add(this.offsMove.mul(11)), 1, 0);
      jWaitMove(actionTimeout);
      jDoClick(this.pressID, 3, 0);
      jWaitWindow("Winepress", actionTimeout);
      //no window in lag/etc
      jSleep(100);
      if(!jHaveWindow("Winepress")) {result = false; break;}
      //transfers all grapes to winepress
      inventory.getItems(this.packName)[0].transferSuchAll();
      //waits transfering
      while(inventory.getItems(this.packName).length > 0)
         jSleep(300);
      //making juice
      jGetWindow("Winepress").pushButton(1);
      while(jGetWindow("Winepress").getInventories()[0].getItems(this.packName).length > 0)
         jSleep(500);
      //lifts press
      var pc = this.pressID.position();// memorizing press coords
      jSendAction("carry");
      jWaitCursor("chi", actionTimeout);
      //lag
      if(!jIsCursor("chi")) {result = false; break;}
      jDoClick(this.pressID, 1, 0);
      jSleep(1500);
      /*while(!jAvatarIsCarrying(jGetMyID()))
         jSleep(200);*/
      //juice to barrel
      jDoClick(this.barrelID, 3, 0);
      jWaitMove(actionTimeout);
      jSleep(2000);
      //placing press back
      jAbsClick(pc, 3, 0);
      jWaitMove(actionTimeout);
      /*while(jAvatarIsCarrying(jGetMyID()))
         jSleep(200);*/
      //getting seeds from press
      jDoClick(this.pressID, 3, 0);
      jWaitWindow("Winepress", actionTimeout);
      //no window in lag/etc
      jSleep(100);
      if(!jHaveWindow("Winepress")) {result = false; break;}
      //transfer to pack seeds
      jGetWindow("Winepress").getInventories()[0].getItems("")[0].transferSuchAll();
      while(jGetWindow("Winepress").getInventories()[0].getItems("").length > 0)
         jSleep(200);
      //offset move
      jMoveStep(this.offsMove);
      jWaitMove(actionTimeout);
      //going to lchect
      var lc = this.containerID.position().add(this.offsMove.mul(11));
      jAbsClick(lc, 1, 0);
      jWaitMove(actionTimeout);
      jDoClick(this.containerID, 3, 0);
      jWaitWindow("Chest", actionTimeout);
      //no window in lag/etc
      jSleep(100);
      if(!jHaveWindow("Chest")) {result = false; break;}
      var bags = jGetWindow("Chest").getInventories()[0].getItems("invobjs/bag-seed");
      var cbag = 0; //current bag
      inventory = checkInventory();
      //transferring seeds, btw i hate loftar
      while(inventory.getItems(this.cropSeedName).length >= 1)
      {
         if(cbag >= bags.length) {result = true; break;}
         var cnt = inventory.getItems(this.cropSeedName).length; //inventory count
         bags[cbag].iact();
         //opens seedbag
         while(!jHaveWindow("Seedbag"))
            jSleep(200);
         //check for free slots
         if(jGetWindow("Seedbag").getInventories()[0].freeSlots() == 0)
         {
            jGetWindow("Seedbag").close();
            while(jHaveWindow("Seedbag"))
               jSleep(200);
            cbag++;
            continue;
         }
         jSleep(100);
         var free = jGetWindow("Seedbag").getInventories()[0].freeSlots(); //free slots in seedbag
         inventory.getItems(this.cropSeedName)[0].transferSuchAll();
         while(inventory.getItems(this.cropSeedName).length > Math.abs(cnt - free))
            jSleep(200);
         jGetWindow("Seedbag").close();
         while(jHaveWindow("Seedbag"))
            jSleep(200);
         cbag++;
      }
      //èäèòå íà õóé, ìíå ëåíü ÷òîòî äåëàòü ñ ýòèìè ñåìåíàìè
      if(result == true) {inventory.getItems(this.cropSeedName)[0].dropSuchAll(); jSleep(1000); break;} //break if all bags r full
      //checks barrel
      var bc = this.barrelID.position().add(this.offsMove.mul(11));
      jAbsClick(bc, 1, 0);
      jWaitMove(actionTimeout);
      jDoClick(this.barrelID, 3, 0);
      while(!jHaveWindow("Barrel"))
         jSleep(500);
      //barrel label
      var blbl = jGetWindow("Barrel").getLabelText(1);
      if(blbl.indexOf("100.0") != -1) {result = true; break;} //breaks if barrel is full
   }//1
   return result;
}

WineHarvester.prototype.plantGrapes = function() {
   jMoveStep(this.offsMove);
   jWaitMove(actionTimeout);
   //going to lchect
   var lc = this.containerID.position().add(this.offsMove.mul(11));
   jAbsClick(lc, 1, 0);
   jWaitMove(actionTimeout);
   jDoClick(this.containerID, 3, 0);
   jWaitWindow("Chest", actionTimeout);
   //no window in lag/etc
   jSleep(100);
   if(!jHaveWindow("Chest")) return false;
   jGetWindow("Chest").getInventories()[0].getItems("invobjs/bag-seed-f")[0].transferSuchAll();
   jSleep(1000);
   inventory = checkInventory();
   var fullbags = inventory.getItems("invobjs/bag-seed-f");
   for(var i = 0; i < fullbags.length; i++)
      fullbags[i].iact();
   while(jGetWindows("Seedbag").length < fullbags.length)
      jSleep(200);
   var swnds = jGetWindows("Seedbag");
   var allseeds = [];
   for(var i = 0; i < swnds.length; i++)
   {
      var sinvs = swnds[i].getInventories()[0].getItems(this.cropSeedName);
      for(var j = 0; j < sinvs.length; j++)
         allseeds.push(sinvs[j]);
   }
   //allseeds.sort(sortFunction2); //à Àðõ õóé!
   var cseed = 0;
   var overflow = false;
   jAbsClick(jTilify(this.startCoord), 1, 0);
   jWaitMove(actionTimeout);
   for(var i = 0; i < this.fieldSize.x; i++) {
      if(overflow == true) break;
      for(var j = 0; j < this.fieldSize.y; j++) {
         if(cseed >= allseeds.length) {overflow = true; break;}
         if(jGetStamina() < 50) drinkWater();
         jAbsClick(this.startCoord.add(i*11, j*11));
         jWaitMove(actionTimeout);
         if(jFindObjectByName(this.cropName, 3) != 0) continue;
         plantNewCrop(this, false);
         /*if(!jGetTileType(jCoord(0, 0)) != 9) plowTile();
         allseeds[cseed].take();
         jWaitDrag(actionTimeout);
         jAbsInteractClick(jCoord(0, 0), 3, 0);
         jWaitDrop(actionTimeout);
         jSleep(100);*/
         cseed++;
      }
      jSleep(100);
   }
   jToConsole("test");
}
/* =========================================================================== */
/* ==============================   ÊÎÍÎÏËß      ============================== */
/* =========================================================================== */
function HempHarvester() {
    this.cropName = "plants/hemp";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/seed-hemp";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 4;                  // Ñòàäèÿ îáðàáîòêè
   bagsSeedsSorter(this);
}
HempHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================   ËÅÍ         ============================== */
/* =========================================================================== */
function FlaxHarvester() {
    this.cropName = "plants/flax";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/flaxseed";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 3;                  // Ñòàäèÿ îáðàáîòêè
}
FlaxHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================   ÏÅÐÅÖ      ============================== */
/* =========================================================================== */
function PepperHarvester() {
    this.cropName = "plants/pepper";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/seed-pepper";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 3;                  // Ñòàäèÿ îáðàáîòêè
}
PepperHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================   ×ÀÉ       ============================== */
/* =========================================================================== */
function TeaHarvester() {
    this.cropName = "plants/tea";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/seed-tea";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 3;                  // Ñòàäèÿ îáðàáîòêè
   this.leaveName = "invobjs/tea-fresh";
   this.containerID = 0;
}
TeaHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};

TeaHarvester.prototype.selectObjects = function() {
   var cnt = jSelectObject("Select container (chest/lchest)...");
   if(cnt.name().indexOf("cclosed") == -1 && cnt.name().indexOf("lchest") == -1)
   {
      jToConsole("ERROR: This is not a container!");
      return false;
   }
   else this.containerID = cnt;
   return true;
}
/* =========================================================================== */
/* ==============================      ÌÀÊ      ============================== */
/* =========================================================================== */
function PoppyHarvester() {
    this.cropName = "plants/poppy";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "invobjs/seed-poppy";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 4;                  // Ñòàäèÿ îáðàáîòêè
}
PoppyHarvester.prototype.processHarvestedGoods = function() {
   bagsSeedsSorter(this);
};

/* =========================================================================== */
/* ==============================   ÏØÅÍÈ×ÊÀ   ============================== */
/* =========================================================================== */
function WheatHarvester() {
    this.cropName = "plants/wheat";      // Èìÿ êðîïà êîòîðûé íóæíî õàðâåñòèòü
    this.cropSeedName = "wheat";   // Èìÿ ñåìå÷êè êîòîðóþ íóæíî ñàæàòü
   this.cropStage = 3;                  // Ñòàäèÿ îáðàáîòêè
}
WheatHarvester.prototype.processHarvestedGoods = function() {
    bagsSeedsSorter(this);
};
/*==============================Êðîï÷èêè============================================*/

function bagsSeedsSorter(harv) {
   inventory = checkInventory();
   var bags = inventory.getItems("invobjs/bag-seed");
   var free = inventory.freeSlots();
   var fslots = 0;
   
   if (bags.length > 0) {
      var windows = jGetWindows("Seedbag");
      if (windows.length > 0) {
         var seeds = [];
         var maxseedscount = bags.length * 9;
         //getting seeds from all seedbags into array
         for (var i = 0; i < windows.length; i++) {
            var inv = waitInventory(windows[i], 0);
            fslots += inv.freeSlots();
            var bufseeds = inv.getItems(harv.cropSeedName);
            for (var j = 0; j < bufseeds.length; j++) {
               seeds.push(bufseeds[j]);
            }
         }
         //from inventory to same array
         var invseeds = inventory.getItems(harv.cropSeedName);
         for (var j = 0; j < invseeds.length; j++) {
            seeds.push(invseeds[j]);
         }
         //calculation quality of all seeds
         var allq = 0;
         for (var j = 0; j < seeds.length; j++) {
            allq += seeds[j].quality();
         }
         //medium quality
         var mediumrange = (allq / seeds.length) - 1;
         //correcting medium q
         //too many seeds
         if(fslots < 9)
            mediumrange += 1;
         
         if (seeds.length > maxseedscount * 0.75) {
            for (var j = 0; j < seeds.length; j++) {
               if (seeds[j].quality() <= mediumrange) seeds[j].drop();
            }
            organizeBags(inventory, harv.cropSeedName);
         }
      }//bags windows
   }
   if (inventory.freeSlots() < 4 && bags.length < 1) {
      inventory.sortItems(inventory.getItems(harv.cropSeedName), "quality", false);
      for (i = 0; i < 3 - free; i++) {
         if (seeds[i].isActual()) {
            seeds[i].drop();
         }
      }
   }
}

function organizeBags(inv, name) {
   var bagw = jGetWindows("Seedbag");
   if(bagw.length < 1) return;
   var fullb, nextb;
   fullb = 0;
   nextb = bagw.length - 1;
   while(1)
   {
      if(fullb == nextb) break; //breaks if filling bag == last bag
      if(bagw[fullb].getInventories()[0].freeSlots() == 0) {
         fullb++;
         continue;
      }
      if(bagw[nextb].getInventories()[0].freeSlots() == 9) {
         nextb--;
         continue;
      }
      var freeSlot = bagw[fullb].getInventories()[0].freeSlotsCoords()[0]; //getting 1st empty slot at current filling bag
      var seed = bagw[nextb].getInventories()[0].getItems(name)[0];    //getting 1st seed at current emptying bag
      seed.take();
      jWaitDrag();
      bagw[fullb].getInventories()[0].drop(freeSlot); //drops to filling bag
      jWaitDrop();
   }
}

function openAllSeedbags() {
   inv = checkInventory();
   var bags = inv.getItems("invobjs/bag-seed");
   if(bags.length < 1)
      return;
   for(var i = 0; i < bags.length; i++)
      if(bags[i].isActual())
         bags[i].iact();
   while(jGetWindows("Seedbag").length != bags.length)
      jSleep(300);
}

function waitUnActual(item) {
   while (item.isActual()) {
      jSleep(100);
   }
}

function resetCursor() {
   if (!jIsCursor("arw")) {
      jAbsClick(jCoord(0, 0), 3, 0);
      jWaitCursor("arw", actionTimeout);
   }
}

function checkInventory() {
   if(!jHaveWindow("Inventory")) {
      jToggleInventory();
      while(!jHaveWindow("Inventory"))
         jSleep(100);
   }
   return jGetWindow("Inventory").getInventories()[0];
}

function checkEquipment() {
   if(!jHaveWindow("Equipment")) {
      jToggleEquipment();
      while(!jHaveWindow("Equipment"))
         jSleep(100);
   }
   return jGetJSEquip();
}

function waitInventoryObject(inv, objname) {
   while (true) {
      var objs = inv.getItems(objname);
      if (objs.length > 0) break;
      else jSleep(100);
   }   
}

function waitUnActual(item) {
   while (item.isActual()) {
      jSleep(100);
   }
}

function drinkWater() {
   if (jGetStamina() > 80) return;
   inventory = checkInventory();
   var buckets = inventory.getItems("bucket-water");
   if (buckets.length > 0) {
      inventory.sortItems(buckets, "amount", false);
      var bucket = buckets[0];
      var bucket_coord = bucket.coord();
      if (bucket.isActual()) {
         bucket.take();
         jWaitDrag();
         var flasks = inventory.getItems("waterflask", "waterskin");
         if (flasks.length > 0) {
            var flask = flasks[0];
            if (flask.isActual()) {
               flask.itemact(0);
               jSleep(500);
               inventory.drop(bucket_coord);
               jWaitDrop();
            }
         }
      }
   }
   var flasks = inventory.getItems("waterflask", "waterskin");
   if (flasks.length > 0) {
      var flask = flasks[0];
      if (flask.isActual()) {
         flask.iact();
         if (jWaitPopup(actionTimeout)) {
            jSelectContextMenu("Drink");
            jWaitProgress();
         } else {
            // No water
            stopFlag = true;
         }
      }
   }
}

function TileInfo(crd) {
   this.coord = crd;
}

function findCrop(harv) {
   var objid = 0;
   for (var i = 0; i < cropRadius; i++) {
      objid = (jFindObjectWithOffset(harv.cropName, 1, jCoord(0, i))); // down
      if (objid && objid.blob(0) == harv.cropStage) return objid;
   }
   for (var i = 0; i < cropRadius; i++) {
      objid = jFindObjectWithOffset(harv.cropName, 1, jCoord(0, -i)); // up
      if (objid && objid.blob(0) == harv.cropStage) return objid;
   }
   for (var i = 0; i < cropRadius; i++) {
      objid = jFindObjectWithOffset(harv.cropName, 1, jCoord(i, 0)); // right
      if (objid && objid.blob(0) == harv.cropStage) return objid;
   }
   for (var i = 0; i < cropRadius; i++) {
      objid = jFindObjectWithOffset(harv.cropName, 1, jCoord(-i, 0));// left
      if (objid && objid.blob(0) == harv.cropStage) return objid;
   }
   objid = jFindObjectByName(harv.cropName, cropRadius);
   if (objid.blob(0) != harv.cropStage) objid = -1;
   return objid;
}

function dropItem(coord) {
   var items = inventory.getItems("");
   for (var i = 0; i < items.length; i++) {
      if (items[i].coord().x == coord.x && items[i].coord().y == coord.y) {
         items[i].drop();
         break;
      }
   }   
}

function waitDragName(name) {
   while (true) {
      var item = jGetDraggingItem();
      if (item != null) {
         if (item.resName() != null) {
         if (item.resName().indexOf(name) >= 0) {
            break;
         } else {
            jSleep(100);
         }
         } else jSleep(100);
      } else {
         break;
      }
   }
}

function equipScythe() {
   var equip = checkEquipment();
   var scythe = inventory.getItems("scythe")[0];
   if (!scythe) return;
   if (equip.resName(6).indexOf("shovel") >= 0) {
      equip.takeAt(6);
      jWaitDrag(actionTimeout);
      inventory.drop(scythe.coord());
      jSleep(1000);
      waitDragName("scythe");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
}

function equipShovel() { // From scythe
   var equip = checkEquipment();
   var shovel = inventory.getItems("shovel")[0];
   if (!shovel) return;
   if (equip.resName(6).indexOf("scythe") >= 0) {
      dropItem(shovel.coord().add(0, 2));
      equip.takeAt(6);
      jWaitDrag(actionTimeout);
      inventory.drop(shovel.coord());
      jSleep(1000);
      waitDragName("shovel");
      equip.dropTo(6);
      jWaitDrop(actionTimeout);
   }
}

function plowTile() {
   drinkWater();
   equipShovel();
   jSendAction("plow");
   jWaitCursor("dig", actionTimeout);
   jOffsetClick(jCoord(0, 0), 1, 0);
   jWaitProgress();
   jOffsetClick(jCoord(0, 0), 3, 0);
   jWaitCursor("arw", actionTimeout);
}

function sayArea(text) {
   var chats = jGetChats();
   for (var i = 0; i < chats.length; i++) {
      if (chats[i].chatName().indexOf("Area Chat") >= 0) {
         chats[i].sendMessage(text);
         break;
      }
   }
}

function sortFunction2(a, b) {
   if (!a.isActual() || !b.isActual()) return 0;
   else return a.quality() - b.quality();
}

function sortFunction(a, b) {
   if (!a.isActual() || !b.isActual()) return 0;
   if (a.quality() < b.quality()) return 1;
   if (a.quality() > b.quality()) return -1;
   return 0;
}

function waitInventory(wnd, index) {
   while (wnd.getInventories().length <= 0) {
      jSleep(100);
   }
   return wnd.getInventories()[index];
}

function plantNewCrop(harv, notrecursive) {
   jSleep(300);
   inventory = checkInventory();
   var plantedSeed = null;
   var windows = jGetWindows("Seedbag");
   var seedbags = inventory.getItems("invobjs/bag-seed-f");
   if (seedbags.length > 0) {
      var seeds = [];
      for (var i = 0; i < windows.length; i++) {
         var inv = waitInventory(windows[i], 0);
         if (inv) {
            var bufseeds = inv.getItems(harv.cropSeedName);
            for (var j = 0; j < bufseeds.length; j++) {
               seeds.push(bufseeds[j]);
            }
         }
      }
      var invseeds = inventory.getItems(harv.cropSeedName);
      for (var j = 0; j < invseeds.length; j++) {
         seeds.push(invseeds[j]);
      }
      var sorted_seeds = seeds.sort(sortFunction);
      plantedSeed = sorted_seeds[0];
   } else {
      var invseeds = inventory.getItems(harv.cropSeedName);
      if (invseeds.length > 0) {
         inventory.sortItems(invseeds, "quality", true);
         plantedSeed = invseeds[0];
      }
   }
   
   if (plantedSeed) {
      // Plow tile if needed
      if (jGetTileType(jCoord(0, 0)) != 9) {
         plowTile();
      }
      if (plantedSeed.isActual()) {
         plantedSeed.take();
         jWaitDrag();
         jInteractClick(jCoord(0, 0), 0);
         if (!jWaitDrop(cannotPlantTimeout)) {
            jWaitDrop();
            if (notrecursive) return;
            plowTile();
            plantNewCrop(harv, true);
         }
      } else {
         if (!notrecursive) plantNewCrop(harv, true);
         else jPrint("Double fail on non-actual seed");
      }
   }
}

function waitPFEndMove() {
   while (true) {
      jWaitEndMove();
      jSleep(500);
      if (!jIsMoving()) {
         return;
      }
   }
}

function main() {
   jDropLastWindow();
   openAllSeedbags();
   var blist = ["Carrot", "Poppy", "Wheat", "Hemp", "Beetroot", "Grapes", "Tea", "Flax", "Pepper", "Exit"];
   var selectWindow = jGUIWindow(jCoord(250, 250), jCoord(110, blist.length * 25 + 15), "Farming");
   var label = jGUILabel(selectWindow, jCoord(5, 5), "Select crop type:");
   for(var i = 0; i < blist.length; i++)
      jGUIButton(selectWindow, jCoord(5, 25 + i*25),  100, blist[i]);
   selectWindow.toggleCloseButton();
   var btext = selectWindow.waitButtonClick();
   if(btext == blist[0]) harvester = new CarrotHarvester();
   if(btext == blist[1]) harvester = new PoppyHarvester();
   if(btext == blist[2]) harvester = new WheatHarvester();
   if(btext == blist[3]) harvester = new HempHarvester();
   if(btext == blist[4]) harvester = new BeetHarvester();
   if(btext == blist[5]) {
      selectWindow.destroy();
      harvester = new WineHarvester();
      if(!harvester.selectObjects()) return;
      if(!harvester.selectRect()) return;
      if(!harvester.processHarvesting()) return;
      harvester.plantGrapes();
      return;
   }
   if(btext == blist[6]) {
      harvester = new TeaHarvester();
      if(!harvester.selectObjects()) return;
   }
   if(btext == blist[7]) harvester = new FlaxHarvester();
   if(btext == blist[8]) harvester = new PepperHarvester();
   if(btext == blist[blist.length - 1]) {selectWindow.destroy(); return;}
   selectWindow.destroy();
   while (!stopFlag) {
      var crop = findCrop(harvester);
      if (crop == -1) break; // No crops found
      drinkWater();
      equipScythe();
      if (!jIsPathFree(crop.position())) {
         resetCursor();
         jPFMove(crop.position());
         jWaitStartMove();
         waitPFEndMove();
         while (jIsMoving() || jMyCoords().dist(crop.position()) > 1) {
            jSleep(100);
         }
      }
      jSendAction("harvest");
      jWaitCursor("harvest", actionTimeout);
      jDoClick(crop.getID(), 1, 0);
      jWaitProgress();
      harvester.processHarvestedGoods();
      plantNewCrop(harvester, false);
   }
}

main();


Code: Select all
//#! name = Taker
//#! tooltip = Take items from ground
//#! uniq = taker_apxproductions

include("jBotAPI");

var selected = jSelectObject("Select object");
var resname = selected.name();
var obj = jFindObjectByName(resname, 15);
while (obj != 0 && checkInventory().freeSlots() > 0) {
   jDoClick(obj.getID(), 3, 0);
   jWaitMove(1000);
   jSleep(100);
   if (jGetDraggingItem()) {
      jDropObject(0);
      break;
   }
   obj = jFindObjectByName(resname, 15);
}
Last edited by WitchKiller34 on Mon May 27, 2013 7:56 pm, edited 2 times in total.
User avatar
WitchKiller34
 
Posts: 37
Joined: Tue Jan 24, 2012 5:49 am

Re: Union Client Scripts

Postby borka » Mon May 27, 2013 6:54 pm

neat - what about a pastebin with line numbers?
User avatar
borka
 
Posts: 9965
Joined: Thu Feb 03, 2011 7:47 pm
Location: World of Sprucecap

Re: Union Client Scripts

Postby NOOBY93 » Tue May 28, 2013 1:19 am

Where to put the script so it's usable
What extension should it be
How to make the cmd window close itself (or just closable), it's annoying to have double window for each client
Jalpha wrote:I believe in my interpretation of things.
User avatar
NOOBY93
 
Posts: 6528
Joined: Tue Aug 09, 2011 1:12 pm

Re: Union Client Scripts

Postby borka » Tue May 28, 2013 1:22 am

script folder
.jbot
take pause out ?

read documentation...http://unionclient.ru/doc/jbot/
Avatar by SacreDoom
Java 8 - manually downloads - good to check for actual versions url here:
viewtopic.php?f=42&t=40331
Remember what the dormouse said: Feed your head Feed your head
User avatar
borka
 
Posts: 9965
Joined: Thu Feb 03, 2011 7:47 pm
Location: World of Sprucecap

Re: Union Client Scripts

Postby NOOBY93 » Tue May 28, 2013 1:31 am

Didn't work (remove pause) but I figured it out. Had to add -r at the end.
And btw the documentation is gibberish even if I do translate "from Russian". It's just random letters.
Jalpha wrote:I believe in my interpretation of things.
User avatar
NOOBY93
 
Posts: 6528
Joined: Tue Aug 09, 2011 1:12 pm

Re: Union Client Scripts

Postby borka » Tue May 28, 2013 2:50 am

sorry that i didn't find time to finish the english translation yet ...
User avatar
borka
 
Posts: 9965
Joined: Thu Feb 03, 2011 7:47 pm
Location: World of Sprucecap

Re: Union Client Scripts

Postby NOOBY93 » Tue May 28, 2013 2:52 am

Wtf does the Taker script do...?
Take stuff from ground?
Why?
Edit: And is there any other scripts? Like a starve script...? I'm curious.
Jalpha wrote:I believe in my interpretation of things.
User avatar
NOOBY93
 
Posts: 6528
Joined: Tue Aug 09, 2011 1:12 pm

Re: Union Client Scripts

Postby borka » Tue May 28, 2013 3:10 am

//#! name = Taker
//#! tooltip = Take items from ground

:roll:

runstarv.jbot
Code: Select all
//#! tooltip = Starving by 4x speed
//#! name = Starving Bot
//#! uniq = dfccd2e6-1cd5-495d-8947-9f0d6d4059aa

include("jBotAPI");

function main() {
   while (jGetHungry() > 50) {
      jSetSpeed(3);
      jMoveStep(jCoord(80, 0));
      jWaitStartMove(30000);
      drinkWater();
      jWaitEndMove(30000);
      jWaitEndProgress(30000);
      jMoveStep(jCoord(-80, 0));
      jWaitStartMove(30000);
      drinkWater();
      jWaitEndMove(30000);
      jWaitEndProgress(30000);
   }
}

main();


cellar_digger.jbot
Code: Select all
//#! name = CellarDigger
//#! uniq = cellardigger_apxproductions

include("jBotAPI");

function main() {
   var cellar_door = jFindObjectByName("arch/door-cellar", 10);
   if (cellar_door == 0) return;
   while (true) {
      drinkWater();
      jDoClick(cellar_door, 3, 0);
      jWaitProgress(1000 * 60 * 10);
      jOffsetClick(jCoord(1, 1), 3, 0);
      jWaitMove(1000 * 60);
      var bumling = jFindObjectByName("bumlings/02", 10);
      while (bumling != 0) {
         drinkWater();
         jDoClick(bumling, 3, 0);
         if (jWaitPopup(actionTimeout)) {
            jSelectContextMenu("Chip stone");
            jWaitStartProgress();
            while (jHaveHourglass()) {
               var stones = inventory.getItems("stone");
               for (var i = 0; i < stones.length; i++) {
                  stones[i].drop();
               }
               jSleep(1000);
            }
         }
         bumling = jFindObjectByName("bumlings/02", 10);
      }
   }
}

main();


well2barrel.jbot
Code: Select all
//#! tooltip = This script fills barrels with water from well
//#! name = Well to Barrel
//#! uniq = WELLTOBARRELBOT

//function checks inventory
//and opens it, if it closed
function checkInventory()
{
   if(!jHaveWindow("Inventory"))
   {
      jToggleInventory();
      while(!jHaveWindow("Inventory"))
         jSleep(100);
   }
}

//like main() at C
function main()
{
   var iw = jGetInputWidget(250, 250, "Input raduis", "Input barrel searching radius (tiles):");
   var RAD = 0;
   if(iw != null)
   {
      if(iw.waitForPress(45000))
      {
         RAD = iw.intValue();
         iw.close();
      }
      else return;
   }
   if (RAD == 0) RAD = 6;
   var well = jFindObjectByName("well", 10); //well
   var barrels = jGetObjects(RAD, jCoord(0, 0), "barrel"); //array of barrels
   if(barrels[0] == 0)
      {
         jInGamePrint("Cannot find barrels. Script failed.");
         return;
      }
   //if no wells around
   if(!well)
   {
      jInGamePrint("Cannot find a well. Script failed.");
      return;
   }
   //well founded
   checkInventory();
   for(var i in barrels)
   {
   //if no barrels at array
   if(barrels[i] == 0)
      break;
   while(1)
   {
      var bucket = jGetWindow("Inventory").getInventories()[0].getItems("buckete")[0];
      if(bucket == null)
         break;
      var bc = bucket.coord();
      bucket.take();
      jWaitDrag(5000);
      jSleep(100);
      jObjectInteractClick(well, 0); //RMB at well
      var drag = jGetDraggingItem();
      //waits for the filled bucket
      while(drag.resName().indexOf("water") == -1)
         jSleep(100);
      jGetWindow("Inventory").getInventories()[0].drop(bc);
      jWaitDrop(5000);
      jSleep(100);
      jDoClick(barrels[i], 3, 0);
      //waits for barrel window
      jWaitWindow("Barrel");
      jSleep(1000);
      if(jGetWindow("Barrel").getLabelText(1).indexOf("100.0") != -1) //barrel is full
      {
         //empty bucket
         var bucket2 = jGetWindow("Inventory").getInventories()[0].getItems("bucket-water")[0];
         bucket2.iact();
         jWaitPopup(5000);
         jSelectContextMenu("Empty");
         while(bucket2.resName().indexOf("water") > -1)
            jSleep(100);
         jDoClick(well, 1, 0);
         jSleep(700);
         break; //from while(1)
      }
      //if barrel isn't full
      var bucket2 = jGetWindow("Inventory").getInventories()[0].getItems("bucket-water")[0];
      var bc2 = bucket2.coord();
      bucket2.take();
      jWaitDrag(5000);
      jObjectInteractClick(barrels[i], 0); //RMB at barrel
      var drag2 = jGetDraggingItem();
      while(drag2.resName().indexOf("buckete") == -1)
         jSleep(100);
      jGetWindow("Inventory").getInventories()[0].drop(bc2);
      jWaitDrop(5000);
      jSleep(100);
   }//while 1
   }//for all barrels
}

//calls the main
jDropLastWindow();
main();
User avatar
borka
 
Posts: 9965
Joined: Thu Feb 03, 2011 7:47 pm
Location: World of Sprucecap

Next

Return to The Wizards' Tower

Who is online

Users browsing this forum: Claude [Bot] and 0 guests