KT client Groovy scripting

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

Moderator: Phades

KT client Groovy scripting

Postby masterminer » Sat Dec 01, 2012 12:17 am

Hi,

I read somewhere it was suggested to make such thread. I'd like it to be only about KT scripting, so pls dont mix code samples from ark.su or other (like .bot) files
There is quite nice collection of scripts with client itself, few scripts can be found in "H&H Groovy bot " thread.

I'd like to add these. Please forgive me my fugly coding style :)

Beautiful Dream Farmer (first goes layout of catchers, number of them can be changed easily but rectangular shape has to stay):
Code: Select all
//    XXX      S- stand here
//   X   X      X- dream catcher
//   X   X
//   X   X
//   X   X
//   X  SX
//    XXX

script:
Code: Select all
import static sys.*



/************************************************
*****  Stand in Southeast Corner            *****
************************************************/



msg("scriptstart")

//def firstID = findMapObject("dreca",22,0,0)

//def firstID = first.id
class moveInfo{
   int X
   int Y
   int objX
   int objY
   }
   // X,Y - to move
   // objX,objY - object is placed there, relative to player
   
void farmit(moveInfo mov){
   int X=mov.X
   int Y=mov.Y
   int objX = mov.objX
   int objY = mov.objY
   println("X=${X}  Y=${Y}  objX=${objX}  objY=${objY}  ")
   def p = null

     if(X!=0 || Y!=0){
       mapMoveStep(X,Y)
         msg("moving to next tile")
        waitMoveend()
             Thread.sleep 200
        }   
        
             if (getCursor() != "harvest")
              {
                 sendAction("harvest");
                 waitCursor("harvest");
              }
     //p = getMyCoord()
     dreca = findObjectByNames(200,objX*11,objY*11,"dreca");
     if (dreca != null)
     {       msg("dreca found")
 
             doClick(dreca.id, 1, 0);
             //mapAbsClick(p.tileX+objX*11, p.tileY+objY*11,1,0)
             msg("first click...")
             waitMove()
             Thread.sleep 200
             doClick(dreca.id, 1, 0);
             //mapAbsClick(p.x+objX*11, p.x+objY*11,1,0)
             msg("second...")
             waitMoveend()
             Thread.sleep 200
    }else
    {
       msg("crap!")
       return
    }
    resetCursor()
 msg("backing up a bit")
 mapMove(dreca.id,-objX*11,-objY*11)
 waitMoveend()
Thread.sleep 200
             
}
  def move=new moveInfo()

 int lap = 0
 while(true){
      
  move.X= 0;move.Y= 0;move.objX= 1;move.objY= 0;farmit(move);//>
  move.X= 0;move.Y=-1;move.objX= 1;move.objY= 0;farmit(move);//>
  move.X= 0;move.Y=-1;move.objX= 1;move.objY= 0;farmit(move);//>
  move.X= 0;move.Y=-1;move.objX= 1;move.objY= 0;farmit(move);//>
  move.X= 0;move.Y=-1;move.objX= 1;move.objY= 0;farmit(move);//>
  move.X= 0;move.Y= 0;move.objX= 0;move.objY=-1;farmit(move);//^
  move.X=-1;move.Y= 0;move.objX= 0;move.objY=-1;farmit(move);//^
  move.X=-1;move.Y= 0;move.objX= 0;move.objY=-1;farmit(move);//^
  move.X= 0;move.Y= 0;move.objX=-1;move.objY= 0;farmit(move);//<
  move.X= 0;move.Y= 1;move.objX=-1;move.objY= 0;farmit(move);//<
  move.X= 0;move.Y= 1;move.objX=-1;move.objY= 0;farmit(move);//<
  move.X= 0;move.Y= 1;move.objX=-1;move.objY= 0;farmit(move);//<
  move.X= 0;move.Y= 1;move.objX=-1;move.objY= 0;farmit(move);//<
  move.X= 0;move.Y= 0;move.objX= 0;move.objY= 1;farmit(move);//V
  move.X= 1;move.Y= 0;move.objX= 0;move.objY= 1;farmit(move);//V
  move.X= 1;move.Y= 0;move.objX= 0;move.objY= 1;farmit(move);//V
  lap++
  println("LAP No. ${lap}")
}
  msg("scriptend")


modified harvest_area script to allow dropping stuff during harvesting (be it leaves of any kind or even seeds)
two first variables are responsible for this , "dropbyproduct" and "byproductname"
Code: Select all
import static sys.*
import static drunkard.*
import util.AreaWalker


/************************************************
*****  Start in Northwest Corner            *****
************************************************/

/******************************
** user modifiable variables **
******************************/

dropbyproduct = 1;      //Drop harvested stuff other than seeds/plantables during planting
byproductname = "tea-fresh" // "tobacco-fresh" "rootleaves", "tea-fresh"<-dissapears v.quickly
flower_stage = 3;       //Only need to change for Hemp, leave at 3 for others.
rePlant = 0;          // Replant seeds? 1 - Yes , 0 - No
inventory_Size = 30;    //Inventory size
use_Cupboards = 0;       // Use Cupboards? 1 - Yes , 0 - No
rouse = 0;             // 1 - Yes, 0 - No
water = 0;             // 1 - Yes, 0 - No
min_Space = 5;         //Minimum Space left in inventory
pumpkin=0;         //1- yes 0- no needs empty inventory slices&drops pumpkin to ground
/******************************
** Do not modify below       **
******************************/
masInd = 0;
current_X = 0;
current_Y = 0;
items = -1;
inventory_Space = 90;
buckets = 0;
cb_Items = 0;
waterskins = 0;

main();
/******************************
**     Delicious content     **
******************************/

void main() {
    def a = selectArea("Select area to harvest.")
    if (a == null){println("area init fail")
        return;}
    def walker = new AreaWalker(a)
    for (tile in walker.eachTile()) {
        tile_work(tile)
    }
    resetCursor()
    println("harvester ended")
}

void tile_work(tile)
 {
    if( Stamina < 65 )
     {   
     print "refill sta"
        refill_stam();
      print "refill sta end"
     }
//TODO       
//    check_Inventory();
    processHarvestTile(tile);
    if (rePlant == 1)
     {
        plantSeed ();
     }
   if(pumpkin) pumpkinate();
 }
 
/********************************************************
*****                 HARVESTING/PLANTING           *****
********************************************************/

 void processHarvestTile(tile)
  { println("Processing tile...")
     int id;
     int stage;
     def p = getMyCoord()
     id = findMapObject("", 2, tile.tileX - p.tileX, tile.tileY - p.tileY);
     if (id != null) {
         stage = getObjectBlob(id, 0);
         if (stage >= flower_stage)
          {
             if (getCursor() != "harvest")
              {
                 sendAction("harvest");
                 waitCursor("harvest");
              }
             doClick(id, 1, 0);
             waitHourglass();
             
             if (dropbyproduct)
             {
               def inhand = getDragItem()
               if(inhand!=null && inhand.isName(byproductname))
               {   
                  inhand.drop()
               }
                def sx = 0
             def sy = 0
             def inv = getInventory("Inventory")
             for (x in sx..<inv.rowCount) {
                 for (y in sy..<inv.columnCount) {      
                     def burak = inv.getItemAt(x,y)
                     if (burak != null && burak.isName(byproductname)) {
                     println("dropping "+burak.name)
                      //burak.take()
                      burak.drop()
                      //waitDrop()
                      //mapAbsClick(tile.x, tile.y,1, 0)
                       }
                     }
                     sy = 0 // to be sure to start next row with first column
                }        

     
     
   
            }
             
          }
      }

 
 
void plantSeed() {
   def BestItem=null;
   int MaxQ=0;
    for (item in getInventory("Inventory").getItems()) {
        if (isSeed(item)) {
            if (item.getQuality()>MaxQ) {
            MaxQ=item.getQuality();
            BestItem=item;
         }
        }
    }
   if (BestItem==null) return;
   int ix=BestItem.row;
   int iy=BestItem.column;
   BestItem.take();
   waitDrag();
   mapInteractClick(0, 0, 0);
    Thread.sleep 100;
   // If seed planting failed, return it to inventory
   if (hasDragItem())
    {
      getInventory("Inventory").drop(ix, iy);
    }
}

static boolean isSeed(item)
{
  if (item.isName("carrot") ||
     item.isName("peapod") ||
     item.isName ("seed-grape") ||
     item.isName ("flaxseed") ||
     item.isName ("seed-wheat") ||
     item.isName ("seed-pumpkin") ||
     item.isName ("seed-carrot") ||
     item.isName ("seed-pepper") ||
     item.isName ("seed-hemp") ||
     item.isName ("seed-hops") ||
     item.isName ("seed-poppy") ||
     item.isName ("seed-tea") ||
     (item.isName ("beetroot") && !item.isName ("leaves") && !item.isName ("Weird")))
   return true
   else
   return false
}


/********************************************************
*****               OTHER                           *****
********************************************************/

void resetCursor()
 {
    if (getCursor() != "arw")
     {
        mapClick(0,0,3,0);
        waitCursor("arw");
         }
 }
 
 void refill_stam()
{

       if( rouse == 1 )
        {
           say(":rouse");
           while(Stamina < 95) Thread.sleep(100);
        }
       if( water == 1 )
        {
           resetCursor();
           mapAbsClick(getMyCoordX(), getMyCoordY(),1, 0);
           drinkWater(true);
           while(Stamina < 90) Thread.sleep(100);
        }
}

void pumpkinate()
{
Thread.sleep(300)
for (item in getInventory("Inventory").getItems())
 {
        if (item.isName("pumpkin"))
        {
         item.act()
         waitContextMenu().select("Slice")
        }
 }
Thread.sleep(300)
for (item in getInventory("Inventory").getItems())
 {
        if (item.isName("flesh")||item.isName("seed"))
        {
            item.take()
            waitDrag()
            drop()
        }
 }

}


modified plant area script. normally it refuses to start if there is something lying on ground, like straw or fibres, its just 1 commented out line but its easier to post whole script
Code: Select all
import static sys.*
import util.AreaWalker

// select harvest area
def area = selectArea("Select area to plant.")
if (area == null)
    return;
// sort seeds
println "Gathering seeds..."
def inv = waitInventory()
openAll(inv)
def seeds = getBagsSeeds() + getSeeds(inv)
if (seeds.size() == 0) {
    println "No seeds to plant."
    return
}
println "Sorting seeds..."
seeds.sort { a, b -> b.q - a.q }
println "Best seed q: ${seeds.first().q}"
// plant
int i = 0
def walker = new AreaWalker(area)
for (tile in walker.eachTile()) {
   println "Processing tile"
    def p = getMyCoord()
    if (getTileType(tile) != TileType.PLOWED)
        continue; // don't plow and move to next tile
                //if (findMapObject("", 1, tile.tileX - p.tileX, tile.tileY - p.tileY) > 0)continue; // something already planted
       
    def s = seeds.getAt(i)
    if (s == null) return // no more seeds
    def seed = s.bag.getItemAt(s.sx, s.sy);
    if (seed == null) return
    seed.take()
    waitDrag()
    mapAbsInteractClick(tile.x, tile.y, 0)
    waitDrop()
    i++
}

class SeedInfo { def q; def bag; def sx; def sy }

/** Returns all seeds from seedbags. */
def getBagsSeeds() {
    def seeds = []
    for (seedbag in findWindows("Seedbag"))
        seeds += getSeeds(seedbag.inventory)
    return seeds
}

/** Returns all seeds from the iventory. */
def getSeeds(cont) {
    def seeds = []
    for (seed in cont.items) {
        if (!isSeed(seed))
            continue;
        seeds.add(new SeedInfo(
            q:seed.quality,
            bag:cont,
            sx:seed.row,
            sy:seed.column))
    }
    return seeds
}

boolean isSeed(item) {
    return !item.isName("bag-seed")
}

/** Opens all seedbags in the given container. */
void openAll(inv) {
    for (item in inv.items)
        if (item.isName("bag-seed-f")) {
            item.act()
            Thread.sleep 100 // wait a bit
        }
    Thread.sleep 500
}


Beetroot farming ( i find this tiny script terribly useful :) though all it does it moves only beetroots to container, leaves leaves ( :> ) in inventory ) Open cupboard first.
Its very easy to modify it for moving other stuff to cupboards by replacing "rootleaves"
Code: Select all
import static sys.*

 def inv = waitInventory()
 def cupboard = getInventory("Cupboard")
    def sx = 0
    def sy = 0
   
    for (x in sx..<inv.rowCount) {
        for (y in sy..<inv.columnCount) {
           
            def burak = inv.getItemAt(x,y)
            if (burak != null && !burak.isName("rootleaves")) {
                burak.transfer()
             
              } 

      }
      sy = 0 // to be sure to start next row with first column
    }


More useful names for collect.groovy scripts (shipped with client)
Code: Select all
//name="flower-poppy"
//name="straw"
name="flaxfibre"
//name="flaxseed"
//name="rootleaves"
//name="tea-fresh"
//name="wood"      //wood blocks
//name="board"      //will r-click on cupboards, if in range :)


Wood stockpiling bot:
What i did was to use ark.su logging and "dumpster" bots, but then i was left with huge pile of logs and no script to move it to my village.
During writing it, I notices getBuffs() method return array of nulls :/ Is it a bug or im doign it wrong...? Anyway, this forced me to do work-around.
Also, this script isnt 100% lag-proof, even though I ensured twice that logs *will* be dropped (by checking position... if there is a way to check if player is carrying anything, that would be proper way to do it)
So, prepare glass and bucket with wine, have hf on wood pile, and ofc have a village claim :)
Script drops logs 4 tiles north of VC, (easy to adjust).
It waits after drikiing wine for buff to wear off.
It may lag and break when trying to drop log.
It also displays how much logs are still left on HF and how much of them are around VC. But this method counts *all* logs visible, so it doesnt have to be exact numbers.
it doesnt check if you run out of wine so eventually you will find yourself in forest with full TW and no wine :/
Good luck :D
Code: Select all
import static sys.*
import static drunkard.*
import haven.*


def vc=findObjectByNames(50,"vclaim")
def woodtile = new Position(vc.x,vc.y-44)
def logcount=0
static void waitMoveend() {
    while (true) {
        Thread.sleep 500
        if (!isMoving())
            break;
   }
}

void movearoundvc(){
   def vc=findObjectByNames(50,"vclaim")
   def woodtile = new Position(vc.x,vc.y-44)

   Position mypos = getMyCoord()

   Position vcpos = new Position(vc.x,vc.y)
   

   vc2stockx=vcpos.tileX-woodtile.tileX
   vc2stocky=vcpos.tileY-woodtile.tileY
   me2stockx=mypos.tileX-woodtile.tileX
   me2stocky=mypos.tileY-woodtile.tileY
      //msg("vc2stockx=${vc2stockx};vc2stocky=${vc2stocky};")
      //msg("me2stockx=${me2stockx};me2stocky=${me2stocky};")
   //move a lil bit:
      mapAbsClick(mypos.x+1,mypos.y+1,1,0)
      waitMoveend()
   if(vc2stockx>=me2stockx && vc2stocky>=me2stocky){

      //msg("move normally1")   
      }
   if(vc2stockx>=me2stockx && vc2stocky<me2stocky){
      //msg("move left")   
      mapMove(vc.id,-30,11)
      waitMove()
      mapMove(vc.id,-30,0)
      waitMove()
      }
   if(vc2stockx<me2stockx && vc2stocky>=me2stocky){
      //msg("move right")   
      //mapMove(vc.id,30,11)
      //waitMove()
      mapMove(vc.id,30,0)
      waitMove()
      }
      
   if(vc2stockx<me2stockx && vc2stocky<me2stocky){
      //msg("move right")   
      mapMove(vc.id,30,11)
      waitMove()
      mapMove(vc.id,30,0)
      waitMove()
      
         
      }      
   //msg("done going around vc")    
}


static boolean gotoHF(){
   sendAction("theTrav", "hearth")
   Thread.sleep 200;
   waitHourglass()
   Thread.sleep 200;
//count logs in area

   def logcount=0
   def gobs=getGobs()
      for (gob in gobs){
         if (gob.resname.contains("/log")){
            logcount++
            }
         }
   
   println("Logs still at HF: ${logcount}")
   
   def hf = findObjectByName("hearth-play",20)
/*
   mapMove(hf,0,55)
   waitMove()
   mapMove(hf,0,0)
   waitMove()
*/
   if (getStamina() > 60) {
    sendAction("plow")
    waitCursor("dig")
         mapClick(0, 0, 1, 0)
         waitHourglass()
    }
   //plow at HF to assure stamina drain, wine will feed u too much otherwise
      def result= !(findObjectByName("vclaim",200)!=0)
}
static boolean gotoVC(){
   sendAction("theTrav", "village")
   Thread.sleep 200;
   waitHourglass()
   Thread.sleep 200;
      def result = !(findObjectByName("hearth-play",20)!=0)
   
}
 boolean picklog(){
   thelog = findObjectByName("log",40)
   if (thelog!=null){
      sendAction("carry")
      waitCursor("chi")
      doClick(thelog,1,0)
      waitMove()
      }
      else return false
      
return true
      
}

boolean reduceTW(){
   
   def inv = waitInventory()
   def glass;
   def bucket;
   def b_pos;
   for(item in inv.items){
      if(item.isName("bucket-wine")){
         bucket=item;   
      }
      if(item.isName("glass-wine")){
         glass=item;   
      }

   }
      b_pos= new Coord(bucket.row,bucket.column)

        // take bucket
                bucket.take()
                waitDrag()
                // click on flask
                glass.interact()
                Thread.sleep 500
                // put bucket back
                inv.drop(b_pos.x, b_pos.y)
                waitDrop()
                // drink
                drink(glass)
            
               
                   
   return gotoVC()
      
}
static void drink(item) {
    assert !item.isTooltip("Empty")
    item.act()
    waitContextMenu().select("Drink")
    waitHourglass()
   
}

msg("Bot started")

while(true)
{
def needtowait = false
   
      gotoHF()
      if(!picklog()){   msg("no more logs found");   return}
      
      while (!gotoVC()) {
         if(reduceTW()){
            
            buffs=getBuffs()  //this crap returns nulls instead of ScriptBuff object
            while(buffs.size()>1){
               
               //needs to be looped and re-checked,
               //if u wait 2.5min by using sleep, lag will break it
               
            //im assuming here that only little TW buff stays after alcohol buff wears off, can cause problems
            //if your wine is so good it drops TW to 0 in one glass, change 1 to 0 while(buffs.size()>1)
            //if you have more long-term buffs,change to 1+those buffs
            Thread.sleep 1000   
            }
         
         break;
         }
      }
   movearoundvc()
   
   mapMove(vc.id,0,-44)
      waitMove()
      
      def moving=true
      while(moving){ //re-check cause of lag
         def mypos=getMyCoord()
         if(mypos.x==woodtile.x && mypos.y==woodtile.y){
            moving = false;
            break;
            }
         Thread.sleep 50      
         }
   def mypos=getMyCoord()
   mapAbsClick(mypos.x,mypos.y,3,1)
   Thread.sleep 300
   
   logcount=0
   def gobs=getGobs()
      for (gob in gobs){
         if (gob.resname.contains("/log")){
            logcount++
            }
         }
   println("Logs at VC: ${logcount}")
}
msg("Bot ended")


Planting grass (over plowed ground or mudflat, script doesnt check if its possible to plant)
First, its re-used plant_area script. Second, press a,n,g *then* run script. This is because i dunno how to select this action using sendAction() command
Code: Select all
import static sys.*
import util.AreaWalker

// select harvest area
def area = selectArea("Select area to plant.")
if (area == null)
    return;
// sort seeds
println "Gathering seeds..."
def inv = waitInventory()
openAll(inv)
def seeds = getBagsSeeds() + getSeeds(inv)
if (seeds.size() == 0) {
    println "No seeds to plant."
    return
}
println "Sorting seeds..."
seeds.sort { a, b -> b.q - a.q }
println "Best seed q: ${seeds.first().q}"
// plant
int i = 0
def walker = new AreaWalker(area)
for (tile in walker.eachTile()) {
   println("tile:${tile.x}:${tile.y} to walk")
    def p = getMyCoord()
    if (getTileType(tile) == TileType.GRASS){
       println("grass found,skipping")
       continue;
     }
        // don't plant and move to next tile
   
    println "trying to plant it"
       
        mapAbsClick(tile.x, tile.y, 1,0)
        
        println("tile:${tile.x}:${tile.y} planted")
        waitMove()
        //sleep 300
    println "done"
   
}
  println "script done"
class SeedInfo { def q; def bag; def sx; def sy }

/** Returns all seeds from seedbags. */
def getBagsSeeds() {
    def seeds = []
    for (seedbag in findWindows("Seedbag"))
        seeds += getSeeds(seedbag.inventory)
    return seeds
}

/** Returns all seeds from the iventory. */
def getSeeds(cont) {
    def seeds = []
    for (seed in cont.items) {
        if (!isSeed(seed))
            continue;
        seeds.add(new SeedInfo(
            q:seed.quality,
            bag:cont,
            sx:seed.row,
            sy:seed.column))
    }
    return seeds
}

boolean isSeed(item) {
    return !item.isName("bag-seed")
}

/** Opens all seedbags in the given container. */
void openAll(inv) {
    for (item in inv.items)
        if (item.isName("bag-seed-f")) {
            item.act()
            Thread.sleep 100 // wait a bit
        }
    Thread.sleep 500
}


Tanning tube filling bot:
This was my first script ;) There is just one issue (aside of lag beign able to break it sometimes), if tube is full and has bark in it, i.e. color isnt blue but brown-ish, script will probably break and stop on such tube (once its full).
make sure an empty bucket is at first row & column of your inventory when script starts.
script requires certain layout of tanning tubes, i hope you can adjust script for your use:
layout:
Code: Select all
    TTT 
  T.....T
  T.....T
  T..W..T
  T.....T



Script for Tanning tube filling bot:
Code: Select all
import static sys.*
import haven.UI
   

def well = findObjectByNames(50, "well")

Coord tube1 = [3,1]
Coord tube2 = [3,0]
Coord tube3 = [3,-1]
Coord tube4 = [3,-2]

Coord tube5 = [1,-3]
Coord tube6 = [0,-3]
Coord tube7 = [-1,-3]

Coord tube8 = [-3,-2]
Coord tube9 = [-3,-1]
Coord tube10 = [-3,0]
Coord tube11 = [-3,1]



println "Tanning tube filling bot started"
    def inv = waitInventory()
   
if (inv != null) {
bucket = inv.getItemAt(0,0)
bucket.take()
waitDrag()
   if(well !=null)
   {
   
//tubes east of well
   for (x in 0..<10){

      filltube(2,1,tube1,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(2,0,tube2,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(2,-1,tube3,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(2,-2,tube4,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
//tubes north of well   
   for (x in 0..<10){
      filltube(1,-2,tube2,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(0,-2,tube3,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(-1,-2,tube4,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
//tubes west of well
   for (x in 0..<10){

      filltube(-2,-2,tube1,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(-2,-1,tube2,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(-2,0,tube3,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   for (x in 0..<10){
      filltube(-2,1,tube4,well.id)
      if( getDragItem().isName("bucket-water") )
       {break;}
   }
   
      
      
   }else
   {
       println "No well found!"
       return   
   }

}else{
    println "No inventory opened!"
    return
}
void filltube(int movex,int movey, Coord tube,int wellid)
{
bucket=getDragItem()

 if (bucket != null){
 println("filling bucket...")
      mapInteractClick(wellid, 3)
      
      waitBucket()
 println("moving to tube...")      
      mapMove(wellid,movex*11,movey*11+2)     //<- move relative to well to stand next to tube
      waitMoveend()
 println("filling tube...")   
       w=findObjectByNames(2,"ttub")
       if(w!=null)   
      {
      println("tube  found")
       //mapClick(tube.x*12,tube.y*12,3,0) // r-click relative to player
         if (w.resname.contains('ttubw') )
         {
            println("tub is full");
            return
         }
       
      mapInteractClick(w.id,0)
      Thread.sleep 200
      println("tube  filled!")
      waitMove()
      
      }else println("tube not found")
 }else{
   println("no item at hand")
   return   
 }
}
void waitBucket()
{
if( getDragItem() != null)
   {
   while(true)
      {
      if ( getDragItem().isName("bucket-water") )
      { 
           break;
      }     
      Thread.sleep 500
      }
    }
}

println "Tube bot ended!"

static void waitMoveend() {
    while (true) {
        Thread.sleep 500
        if (!isMoving())
            break;
   }
}


Last but not least:
Probably the most ugly script of mine but it works great.
Brickmaking:
Uses 8 kilns in 2 rows:
layout:
Code: Select all
// Kx = kilns, 2 rows, 2 tiles road between them
// C = brick cornerpost
// S = approx start position
// note: K2 is directly north of K5

//      K1K2K3K4
// C   S
//      
//         K5K6K7K8



Script for brickmaking:
Its very chatty ;) comment out all msg() if u want.

At the bottom there are 4 main methods, comment them out when needed.

Code: Select all


import static sys.*
msg("start")


void putfuel(int ID){
   mapMove(ID,0,26)
   msg("ehh")
   waitMove()
   for(item in waitInventory().items){
      
      if (item.isName("branch")){
      item.take()
      waitDrag()
      break;   
      }
      }
def MOD = 1;
   msg("moving to 1")
   mapMove(ID,0,28-7)
   msg("ehh1")
   waitMove()
   def nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
   
   msg("moving to 5")
   mapMove(ID,3*11,28+7)
   msg("ehh5")
   waitMove()
    nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
   
   msg("moving to 2")
   mapMove(ID,3*11,28-7)
   waitMove()
    nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
    
   msg("moving to 6")
   mapMove(ID,3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
   
   msg("moving to 3")
   mapMove(ID,3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
   
   msg("moving to 7")
   mapMove(ID,3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
   
   msg("moving to 4")
   mapMove(ID,3*11+3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
   
   msg("moving to 8")
   mapMove(ID,3*11+3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByName("kiln",3)
   if(nearestK == 0){msg("crap!");return;}
   mapInteractClick(nearestK,MOD)
   waitMove()
}    
    
void lightthem (int ID) {
      mapMove(ID,0,26)
   msg("ehh")
   waitMove()

def BTN = 3   
def MOD = 0
   msg("moving to 1")
   mapMove(ID,0,28-7)
   msg("ehh1")
   waitMove()
   def nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   //mapMove(nearestK.id,0,0)
   doClick(nearestK.id,BTN,MOD)
   msg("ehh2")
   waitMove()
   msg("ehh3")
   waitInventory("Kiln")
   msg("ehh4")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200
   
   msg("moving to 5")
   mapMove(ID,3*11,28+7)
   msg("ehh5")
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   waitInventory("Kiln")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200

   msg("moving to 2")
   mapMove(ID,3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   waitInventory("Kiln")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200
   
   msg("moving to 6")
   mapMove(ID,3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   waitInventory("Kiln")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200
   
   msg("moving to 3")
   mapMove(ID,3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   waitInventory("Kiln")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200
   
   msg("moving to 7")
   mapMove(ID,3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   waitInventory("Kiln")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200
   
   msg("moving to 4")
   mapMove(ID,3*11+3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   waitInventory("Kiln")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200
   
   msg("moving to 8")
   mapMove(ID,3*11+3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()   
   waitInventory("Kiln")
   findWindow("Kiln")?.findButton("Light")?.click()
   Thread.sleep 200
   
}
boolean transferallitems( ){
   inv = waitInventory("Inventory")
   from = waitInventory("Kiln")   
   int invsize=inv.rowCount * inv.columnCount;
   for (brick in from.items){
      if(brick.isName("brick"))
      {
         brick.transfer()
      }
   }
   if(inv.items.size()>=invsize)
   {
   return false   
   }
   else return true
   
}
boolean emptykilns (int ID) {
      mapMove(ID,0,26)
   msg("ehh")
   waitMove()

def BTN = 3   
def MOD = 0
def inv = null
   msg("moving to 1")
   mapMove(ID,0,28-7)
   msg("ehh1")
   waitMove()
   def nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   //mapMove(nearestK.id,0,0)
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200
   
   msg("moving to 5")
   mapMove(ID,3*11,28+7)
   msg("ehh5")
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200

   msg("moving to 2")
   mapMove(ID,3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200
   
   msg("moving to 6")
   mapMove(ID,3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200
   
   msg("moving to 3")
   mapMove(ID,3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200
   
   msg("moving to 7")
   mapMove(ID,3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200
   
   msg("moving to 4")
   mapMove(ID,3*11+3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200
   
   msg("moving to 8")
   mapMove(ID,3*11+3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()   
   kinv = waitInventory("Kiln")
   if(!transferallitems())return false;
   Thread.sleep 200
   
   return true
}

void putbrickstocorner(int ID){
def corner = selectObject("Select cornerpost")
def allempty = false
   while(allempty==false)
   {
      allempty = emptykilns(ID)
      if(findWindow("Inventory")!=null){
         findWindow("Inventory").close()
         }
      mapMove(ID,0,26)
      waitMove()
      doClick(corner.id,3,0)
      waitMove()
      Thread.sleep 300
      def box = findWindow('Brickwall')?.findBuildBox('Brick')
      inv = waitInventory("Inventory")
      for(item in inv.items)
         {
            box.transferTo(1)   
         }
      mapMove(ID,-10,26)
      waitMove()

      
   }

}
boolean transferallclay(){
      inv = waitInventory("Inventory")
      kinv= waitInventory("Kiln")
      for(item in inv.items)
         {
            if(item.isName("clay")){
               kinv.transferTo(1)   
            }
         }
         for(item in inv.items){
            if(item.isName("clay"))return false   ;
         }
               
return true   
}
void putclaytokilns(int ID){
      mapMove(ID,0,26)
   msg("ehh")
   waitMove()

def BTN = 3   
def MOD = 0
def inv = null
   msg("moving to 1")
   mapMove(ID,0,28-7)
   msg("ehh1")
   waitMove()
   def nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200
   
   msg("moving to 5")
   mapMove(ID,3*11,28+7)
   msg("ehh5")
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200

   msg("moving to 2")
   mapMove(ID,3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200
   
   msg("moving to 6")
   mapMove(ID,3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200
   
   msg("moving to 3")
   mapMove(ID,3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200
   
   msg("moving to 7")
   mapMove(ID,3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200
   
   msg("moving to 4")
   mapMove(ID,3*11+3*11+3*11,28-7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200
   
   msg("moving to 8")
   mapMove(ID,3*11+3*11+3*11+3*11,28+7)
   waitMove()
    nearestK = findObjectByNames(3,"kiln")
   if(nearestK == 0){msg("crap!");return;}
   doClick(nearestK.id,BTN,MOD)
   waitMove()   
   kinv = waitInventory("Kiln")
   if(transferallclay())return;
   Thread.sleep 200
   
msg("still some clay left in inv")
   
}

def kiln = findObjectByNames(6,"kiln")
   
   
//=======
// Main methods:
//
   putclaytokilns(kiln.id)
   //putfuel(kiln.id) //adds 1 branch per kiln
   //lightthem(kiln.id)
   //putbrickstocorner(kiln.id)

   
msg("end")


Last edited by masterminer on Sun Dec 02, 2012 6:05 pm, edited 4 times in total.
masterminer
 
Posts: 8
Joined: Wed Nov 14, 2012 5:41 pm

Re: KT client Groovy scripting

Postby masterminer » Sat Dec 01, 2012 12:20 am

Those 2 are required for most scripts to work, i myself added them to sys.groovy
Code: Select all
//normal waitMove() bugs out when there is no actual move. I.e. when you stand in the same spot and call it again.
static void waitMoveend() {
    while (true) {
        Thread.sleep 500
        if (!isMoving())
            break;
   }
}

Code: Select all
static void msg(String s){
   println(s)
   }
masterminer
 
Posts: 8
Joined: Wed Nov 14, 2012 5:41 pm

Re: KT client Groovy scripting

Postby DDDsDD999 » Sat Dec 01, 2012 1:12 am

Cool stuff, even though scripts for these tasks have been shared in the pande/oddi party after being reinvented at least 5 times each. Good thing they're at least public now and with lay-out documentation.
Image
Image
Image
Image
Image
User avatar
DDDsDD999
 
Posts: 5669
Joined: Fri Jul 02, 2010 12:31 am

Re: KT client Groovy scripting

Postby borka » Sat Dec 01, 2012 1:34 am

Neat! Every script example prolly helps those who want to do their own ones. Best way to learn scripting. ty! :D
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: KT client Groovy scripting

Postby Jojjkano » Sat Dec 01, 2012 6:04 pm

Good stuff, thanks for sharing. :D
Image
User avatar
Jojjkano
 
Posts: 417
Joined: Tue Apr 10, 2012 8:23 pm

Re: KT client Groovy scripting

Postby dafels » Sat Dec 01, 2012 6:04 pm

Thanks for these scripts.
Does anyone have a working paving script?
User avatar
dafels
 
Posts: 2994
Joined: Sun Nov 14, 2010 7:49 pm

Re: KT client Groovy scripting

Postby masterminer » Sat Dec 01, 2012 6:41 pm

I think grass planting script can be easily reworked into paving bot, but because i have nothing to pave I couldnt test it properly. the action name is "laystone" (to use with sendAction() command)

EDIT: i updated wood stockpiling bot. it now drains stamina & hunger more (much more :D ) efficiently. It also displays how much logs are still left on HF and how much of them are around VC. But this method counts *all* logs visible, so it doesnt have to be exact numbers.

...

EDIT: updated brick bot so it doesnt break when failing to find cornerpost (due to lag).
masterminer
 
Posts: 8
Joined: Wed Nov 14, 2012 5:41 pm

Re: KT client Groovy scripting

Postby Sarchi » Mon Dec 03, 2012 7:43 am

Too bad there's no one playing to actually use these scripts.
User avatar
Sarchi
 
Posts: 2517
Joined: Sat Jun 12, 2010 1:14 am
Location: 109, -37

Re: KT client Groovy scripting

Postby masterminer » Fri Dec 07, 2012 8:04 am

Unfortunately, no more cool scripts for you :/
Because of recent attacks on my settlement i refuse to play in constant threat of being shot doing daily stuff.
I have returned after over a year to play for 2 reasons:
1- it was fun
2- lag made most people quit and it felt much safer.
now, "people" are back.
And I was about to share sweet steel making script...
Just a note to whoever it was, if you plan ramming my brickwalls, you'll have an unpleasant surprize. I dropped everything valuable to ground before i left and I hope you'll rage :D
masterminer
 
Posts: 8
Joined: Wed Nov 14, 2012 5:41 pm


Return to The Wizards' Tower

Who is online

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