Union Client Scripts

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

Moderator: Phades

Re: Union Client Scripts

Postby Leny-m » Mon Mar 17, 2014 1:13 pm

Anybody experiencing null pointer sometimes when using jGetWindow? It kinda ruins the whole script 'cause it's a code issue so there's no way around it from the script. Adjusting the source helps a bit. Now you need to make sure you that you wait until jGetWindow returns non-null object so you can store it and use it later on.

Code: Select all
    public static JSWindow getWindow(String name) {
        try {
            Widget root = UI.instance.root;
            for (Widget wdg = root.child; wdg != null; wdg = wdg.next) {
                if (wdg instanceof Window) {
                    if (((Window) wdg).cap.text.equals(name)) {
                        return new JSWindow(UI.instance.getId(wdg));
                    }
                }
            }
        } catch (Exception ex) {
            return null;
        }
        return null;
    }
Image Image Image Image Image
Leny
User avatar
Leny-m
 
Posts: 109
Joined: Sat Dec 17, 2011 8:04 pm

Re: Union Client Scripts

Postby Strandmullen » Mon Mar 17, 2014 4:06 pm

shampizle wrote:anyone have a paver script?

I just made one. Start in top left corner, enter width and length and it'll do the job.
It will only go for as long as you have stones in your inventory though.
I've not had the time to do much testing yet but I think it should work fine.

Code: Select all
//#! tooltip = Pave a rectangle of custom width and length. Start in top left corner.
//#! name = Paver
//#! icon = gfx/invobjs/stone
//#! uniq = paver

//By Strandmullen

var width;
var length;

var actionTimeout = 1000 * 60 * 1;

function optionsMenu() {
   widthMenu = jGetInputWidget(250, 250, "Paver", "Input total width east:");
   widthMenu.waitForPress(actionTimeout);
   width = widthMenu.intValue()
   widthMenu.close();
   
   lengthMenu = jGetInputWidget(250, 250, "Paver", "Input total length south:");
   lengthMenu.waitForPress(actionTimeout);
   length = lengthMenu.intValue()
   lengthMenu.close();
}

function selectLayStone() {
   jSendDoubleAction("stoneroad", "stone");
   jWaitCursor("dig", actionTimeout);
}

function layStone() {
   tile = jGetNearestTileCoord(1);
   jOffsetClick(tile, 1);
   jSleep(500);
   jWaitProgress(actionTimeout);
}

function main() {
   optionsMenu();
   selectLayStone();

   direction = 1;
   layStone();
   for (i = 0; i < width; i++) {
      for (j = 0; j < length-1; j++) {
         jMoveStep(jCoord(0, direction));
         jWaitMove(actionTimeout);
         layStone();
      }
      direction *= -1;
      
      if (i != width - 1) {
         jMoveStep(jCoord(1, 0));
         jWaitMove(actionTimeout);
         layStone();
      }
   }
}

main();
User avatar
Strandmullen
 
Posts: 452
Joined: Sat Mar 31, 2012 11:37 pm
Location: Sweden

Re: Union Client Scripts

Postby Leny-m » Mon Mar 17, 2014 4:51 pm

Strandmullen wrote:
shampizle wrote:anyone have a paver script?

I just made one. Start in top left corner, enter width and length and it'll do the job.
It will only go for as long as you have stones in your inventory though.
I've not had the time to do much testing yet but I think it should work fine.

Code: Select all
//#! tooltip = Pave a rectangle of custom width and length. Start in top left corner.
//#! name = Paver
//#! icon = gfx/invobjs/stone
//#! uniq = paver

//By Strandmullen

var width;
var length;

var actionTimeout = 1000 * 60 * 1;

function optionsMenu() {
   widthMenu = jGetInputWidget(250, 250, "Paver", "Input total width east:");
   widthMenu.waitForPress(actionTimeout);
   width = widthMenu.intValue()
   widthMenu.close();
   
   lengthMenu = jGetInputWidget(250, 250, "Paver", "Input total length south:");
   lengthMenu.waitForPress(actionTimeout);
   length = lengthMenu.intValue()
   lengthMenu.close();
}

function selectLayStone() {
   jSendDoubleAction("stoneroad", "stone");
   jWaitCursor("dig", actionTimeout);
}

function layStone() {
   tile = jGetNearestTileCoord(1);
   jOffsetClick(tile, 1);
   jSleep(500);
   jWaitProgress(actionTimeout);
}

function main() {
   optionsMenu();
   selectLayStone();

   direction = 1;
   layStone();
   for (i = 0; i < width; i++) {
      for (j = 0; j < length-1; j++) {
         jMoveStep(jCoord(0, direction));
         jWaitMove(actionTimeout);
         layStone();
      }
      direction *= -1;
      
      if (i != width - 1) {
         jMoveStep(jCoord(1, 0));
         jWaitMove(actionTimeout);
         layStone();
      }
   }
}

main();


I'd go for something like: search for nearby tiles that have been plowed and pave them. So you can actualy make turns and stuff.
Image Image Image Image Image
Leny
User avatar
Leny-m
 
Posts: 109
Joined: Sat Dec 17, 2011 8:04 pm

Re: Union Client Scripts

Postby Strandmullen » Mon Mar 17, 2014 5:04 pm

Leny-m wrote:I'd go for something like: search for nearby tiles that have been plowed and pave them. So you can actualy make turns and stuff.

I see how this could make it easier to do some things, although it would come with problems. Firstly, you would have to first plow ground which doesn't need to be plowed to be paved, like grass. Secondly, it would make the script pave nearby plowed tiles even if you don't want those tiles to be paved, a farm for example.
User avatar
Strandmullen
 
Posts: 452
Joined: Sat Mar 31, 2012 11:37 pm
Location: Sweden

Re: Union Client Scripts

Postby Leny-m » Wed Mar 19, 2014 3:25 pm

Strandmullen wrote:
Leny-m wrote:I'd go for something like: search for nearby tiles that have been plowed and pave them. So you can actualy make turns and stuff.

I see how this could make it easier to do some things, although it would come with problems. Firstly, you would have to first plow ground which doesn't need to be plowed to be paved, like grass. Secondly, it would make the script pave nearby plowed tiles even if you don't want those tiles to be paved, a farm for example.


Out of those two (selecting a rectangle, letting it pave plowed ground) I prefer using the former script. I usualy make single tile paths for my bots to walk on and this helped me immensly. I just wanted to share my experience and an idea ;)
Image Image Image Image Image
Leny
User avatar
Leny-m
 
Posts: 109
Joined: Sat Dec 17, 2011 8:04 pm

Re: Union Client Scripts

Postby shampizle » Wed Mar 26, 2014 3:13 am

I had this working before i reformated my HHD now it doesn't work i get no errors it says it starts then finishs not even a second later any thoughts

Code: Select all
//#! uniq = WOODCUTTER
//#! tooltip = Cut trees and tp logs to totem
//#! name = Woodcutter
//#! icon = gfx/invobjs/small/log

include("jBotAPI");

//// Logs need ////////////////////////////////////
var logsMax = 200;

//// Where to drop logs, offset from totem ////////
var waypoints =
[
   [6, 0],
//   [-6, 0],
//   [-47, -35],
//   [-55, 2],
];

///////////////////////////////////////////////////
function Finish(itext)
{
   jPrint("Exit - "+itext);
   jExit();
}

function DropFromCursor()
{
   while (jIsDragging())
   {
      jDropObject(0);
      jSleep(300);
   }
}
function DropWoodBlocksFromInv()
{
   var inv = checkInventory();
   var items = inv.getItems("wood");
   if (items.length > 0)
   {   
      items[0].dropSuchAll();
      //waits dropping
      while (inv.getItems("wood").length > 0) jSleep(300);
   }
}
function DropFromInv(resName)
{
   var inv = checkInventory();
   var items = inv.getItems(resName);
   if (items.length > 0)
   {   
      items[0].dropSuchAll();
      //waits dropping
      while (inv.getItems(resName).length > 0) jSleep(300);
   }
}
function FromCursorToInv(resName)
{
   DropFromCursor();
   var res = jFindObjectByName(resName, 1);
   if (res != null)
   {
      res.doClick(3, 0);
      jSleep(500);
      if (jIsDragging()) DropFromCursor();
   }
}
function GetInvFree()
{
   var inv = checkInventory();
   return inv.freeSlots();
}
function GetInvResCount(resName)
{
   var inv = checkInventory();
   var invItems = inv.getItems(resName);
   return invItems.length;
}
function GetWindow(objWndName)
{
   var wnd;
   while (true)
   {
      wnd = jGetWindow(objWndName);
      if (wnd != null) return wnd;
      jSleep(300);
   }
}

//---------------------------------------------------------------------
// chop trees
//---------------------------------------------------------------------
function TakeAxe()
{
   var inv = checkInventory();
   var equip = checkEquipment();
   if (equip.name(6) == "Stone Axe") return;
   if (equip.name(7) == "Stone Axe") return;
   while (true)
   {
      equip.transfer(6);
      equip.transfer(7);
      if (equip.name(6) == "") break;
      if (equip.name(7) == "") break;
      jSleep(300);
   }

   DropFromCursor();

   var axe = inv.getItems("axe");
   if (axe.length == 0) Finish("no axe");
   while (!jIsDragging())
   {
      axe[0].take();
      jSleep(300);
   }
   while (jIsDragging())
   {
      equip.dropTo(6);
      jSleep(300);
   }
}
function TakeShovel()
{
   var inv = checkInventory();
   var equip = checkEquipment();
   if (equip.name(6) == "Shovel") return;
   if (equip.name(7) == "Shovel") return;
   while (true)
   {
      equip.transfer(6);
      equip.transfer(7);
      if (equip.name(6) == "") break;
      if (equip.name(7) == "") break;
      jSleep(300);
   }

   DropFromCursor();

   var shovel = inv.getItems("shovel");
   if (shovel.length == 0) Finish("no shovel");
   while (!jIsDragging())
   {
      shovel[0].take();
      jSleep(300);
   }
   while (jIsDragging())
   {
      equip.dropTo(6);
      jSleep(300);
   }
}

function RemoveStump(stump)
{
   resetCursor();
   DropFromCursor();
   DropWoodBlocksFromInv();

   drinkWater();

   TakeShovel();

   stump.doClick(3, 0);
   jWaitPopup(actionTimeout);
   if (jHavePopup())
   {
      jSelectContextMenu("Remove");
      jWaitProgress(actionTimeout);
   }

   DropFromCursor();
   DropWoodBlocksFromInv();
}

function ChopTree(tree)
{
   resetCursor();
   DropFromCursor();
   DropWoodBlocksFromInv();

   //drinkWater();

   TakeAxe();

   tree.doClick(3, 0);
   jWaitPopup(actionTimeout);
   if (jHavePopup())
   {
      jSelectContextMenu("Chop");
      jWaitProgress(actionTimeout);
   }
   jSleep(500);
}

function TakeLog()
{
   var offsetAround = [[11, 11], [11, 0], [11, -11], [0, 11], [0, -11], [-11, 11], [-11, 0], [-11, -11]];
   var treesList = ["/stump", "/trees/fir", "/trees/pine"];

   while (true)
   {
      jSleep(1000);

      if (!MoveRandomDirection(3)) return false;

      if (!noMoreWine())
      {      
         var logsAll = jGetObjects(45, jCoord(0, 0), "/trees/log");
         for (var i = 0; i < logsAll.length; i++)
         {
            var log = logsAll[i];
            if (!jIsPathFree(log.position()))   continue;

            // debug
            //MoveToPos(log.position());
            MoveToPosSafe(log.position());

            resetCursor();
            DropFromCursor();
         
            var me = jGob(jGetMyID());
            jSendAction("carry");
            jWaitCursor("chi", actionTimeout);
            log.doClick(1, 0);
            while (!me.isCarrying())
            {
               jSleep(1000);
            }
            return true;
         }
      }

      // no log avaliable - chop tree and remove stumps
      treeEnd:
      for (var k = 0; k < treesList.length; k++)
      {
         var treesAll = jGetObjects(75, jCoord(0, 0), treesList[k]);
         for (var i = 0; i < treesAll.length; i++)
         {
            var tree = treesAll[i];

            var num = -1;   
            for (var n = 0; n < offsetAround.length; n++)
            {
               var pos = jCoord(tree.position().x + offsetAround[n][0], tree.position().y + offsetAround[n][1]);
               if (jIsPathFree(pos))
               {
                  num = n;
                  break;
               }
            }   
            if (num == -1) continue;

            var startPos = jMyCoords();

            var pos = jCoord(tree.position().x + offsetAround[num][0], tree.position().y + offsetAround[num][1]);
            // debug
            //MoveToPos(pos);
            MoveToPosSafe(pos);
      
            // debug
            //if (CheckHostile()) return false;

            if ((tree.name() == "gfx/terobjs/trees/pine/stump") || (tree.name() == "gfx/terobjs/trees/fir/stump"))
            {
               RemoveStump(tree);
            }
            else
            {
               ChopTree(tree);
            }

            // debug
            //MoveToPos(startPos);
            MoveToPosSafe(startPos);

            break treeEnd;
         }
      }
   }
   Finish("no more trees in range");
   return true;
}

function TeleportToTotem()
{
   DropFromCursor();
   DropWoodBlocksFromInv();

   // drink wine
   if (travelCount() > 85)
   {
      while (noMoreWine())
      {
         jSleep(2*1000);
         return false;
      }
      drinkWine();
   }
   
   // teleport
   jSendDoubleAction("theTrav", "village");
   jWaitProgress(actionTimeout);

   while (true)
   {
      if (jFindObjectByName("vclaim", 10) != null) break;
      jSleep(1000);
   }
   return true;
}

function UnloadWoodLog()
{
   // ïðèâÿçêà
   var totem = jFindObjectByName("vclaim", 10);
   if (totem == null) Finish("no totem O_o");

   // move to factory
   var initPos = totem.position();
   var startPos = jCoord(0, 0);
   for (var i = 0; i < waypoints.length; i++)
   {
      MoveToPosSafe(jCoord(initPos.x + (waypoints[i][0] - startPos.x)*11, initPos.y + (waypoints[i][1] - startPos.y)*11));
   }

   // drop
   var me = jGob(jGetMyID());
   if (me == null) Finish("no me? O_o");
   if(me.isCarrying())
   {
      jAbsClick(jMyCoords(), 3, 0);
      while (me.isCarrying())
      {
         jSleep(1000);
      }
   }

   // print count
   var logsList = jGetObjects(2, jCoord(0, 0), "/trees/log");
   jPrint("logs count = "+logsList.length);
   return logsList.length;
}

function ChopAndDeliverTrees()
{
   var equip = checkEquipment();
   var axeEquipped = false;
   if (equip.name(6) == "Stone Axe") axeEquipped = true;
   if (equip.name(7) == "Stone Axe") axeEquipped = true;
   var shovelEquipped = false;
   if (equip.name(6) == "Shovel") shovelEquipped = true;

   var inv = checkInventory();
   var axe = inv.getItems("axe");
   var shovel = inv.getItems("shovel");
   var buckets = inv.getItems("bucket-wine");
   var glass = inv.getItems("glass-wine");
   if (((axe.length == 0)&&(!axeEquipped))||((shovel.length == 0)&&(!shovelEquipped))||(buckets.length == 0)||(glass.length == 0))
   {
      sayArea("Need axe, shovel, bucket with wine and wine glass!");
      Finish("Must be equipped with axe, shovel, bucket with wine and wine glass.");
   }

   jSetSpeed(1);
   TeleportHF();
   while (true)
   {
      if (!TakeLog())
      { // hostile spotted!
         jPrint("fukin bear!");
         TeleportToTotem();
         sayArea("fukin bear!");
         WaitRespawn();
         continue;
      }
      if (!TeleportToTotem())
      {
         jLogout();
         Finish("finished. cannot teleport to totem. possibly no wine.")
      }
      var logsCount = UnloadWoodLog();
      if (logsCount > logsMax)
      {
         Finish("work done. "+logsMax+" logs ready.");
      }
      TeleportHF();
   }
}

//---------------------------------------------------------------------
function main()
{
   jDropLastWindow();

   ChopAndDeliverTrees();
}

main();


And thanks for the paver!!!!
User avatar
shampizle
 
Posts: 590
Joined: Sat Oct 20, 2012 1:14 am

Re: Union Client Scripts

Postby Arcanist » Wed Mar 26, 2014 5:32 am

shamplzle, there are a bunch of functions that are missing, that would likely be in the jbotapi
I'd suggest not using the API in the future as it only leads to problems.

edit:
Yeah, I added in a few of what I think the missing functions might be, but there are a few that I can't guess.
You'll need to get the API from your source again.

That's a well written script btw, it has a lot of checks and stuff, which unfortunately makes it hard to edit.

Alternately you can use my logger, with many functions taken from APX
User avatar
Arcanist
 
Posts: 2664
Joined: Mon Mar 19, 2012 2:01 pm

Re: Union Client Scripts

Postby shampizle » Wed Mar 26, 2014 4:11 pm

Cheese script error

Image


Woodcutter error
Image
User avatar
shampizle
 
Posts: 590
Joined: Sat Oct 20, 2012 1:14 am

Re: Union Client Scripts

Postby Arcanist » Fri Mar 28, 2014 11:45 am

shampizle wrote:Cheese script error

Image



Woodcutter error
Image


Are you incapable of understanding, or editing them yourself?

The first one says it ERROR IN LINE 52, missing }

And I've already said the problem with the woodcutter. You have an incomplete API file, so some functions called in the woodcutter script which should be in the API, are not.
User avatar
Arcanist
 
Posts: 2664
Joined: Mon Mar 19, 2012 2:01 pm

Re: Union Client Scripts

Postby shampizle » Fri Mar 28, 2014 7:00 pm

woodcutter works fine with EVERYONE else that uses it and this one is new so dont get all fucking snippy with me its a new error if u dont want to help then dont talk

and yes i have no idea about coding
User avatar
shampizle
 
Posts: 590
Joined: Sat Oct 20, 2012 1:14 am

PreviousNext

Return to The Wizards' Tower

Who is online

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