Jump to content

My first Woodcutting Script 1-15


Recommended Posts

Posted
import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.api.model.Player;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.utility.ConditionalSleep;

@ScriptManifest(author = "Duhrealtim", name = "1-15 WoodCutter", info = "My First Script", version = 0.1, logo = "")
public final class Woodcut extends Script {

  //Areas
  private final Area treeArea = new Area(3197, 3205, 3180, 3229);
  private final Area lumbridgeBankArea = new Area(3208, 3218, 3209, 3219);


  @Override
  public int onLoop() throws InterruptedException {
    //Keeps looping
    if (getInventory().getEmptySlotCount() != 0) {
      RS2Object tree = getObjects().closest(obj -> obj != null && obj.getName().equals("Tree")
              && getMap().canReach(obj)); //tree to chop
      if (!myPlayer().isAnimating()) {
        if (tree != null) {
          if (tree.interact("Chop down")) {
            new ConditionalSleep(5000, 2000) {
              @Override
              public boolean condition() throws InterruptedException {
                return false;
              }
            }.sleep();
          }
        }
      } else if (tree == null) { // if it dont see tree it moves
        getCamera().toEntity(tree);
        log("Searching for a tree");
        if (getWalking().webWalk(treeArea)) {
          log("Walking to trees");
          new ConditionalSleep(5100, 6100) {
            @Override
            public boolean condition() throws InterruptedException {
              return false;
            }
          };
        }
      }
    } else {
      log("Inventory Full."); //Walks to bank
      if (getWalking().webWalk(Banks.LUMBRIDGE_UPPER)) { //What bank it banks at.
        log("Walking to bank...");
        new ConditionalSleep(5000, 1000) {
          @Override
          public boolean condition() throws InterruptedException {
            return true;
          }
        };
        Entity depoBox = objects.closest("Bank deposit box"); //Opens deposit box and deposits logs.
        if (depoBox != null) {
          new ConditionalSleep(2000, 5000) {
            @Override
            public boolean condition() throws InterruptedException {
              return true;
            }
          };
          if (depoBox.interact("Deposit")) {
            while (!depositBox.isOpen()) {
              new ConditionalSleep(2000, 5000) {
                @Override
                public boolean condition() throws InterruptedException {
                  return true;
                }
              };
            }
            depositBox.depositAllExcept("Bronze axe");
getWalking().webWalk(treeArea);
          }
        }
      }
    }
    return 1000;
  }



  }

 

 

 

My very first script. Still trying to learn how to make it progressive.

  • Like 3
Posted

Take a look at ConditionalSleep's Api docs again, your usage is incorrect. https://osbot.org/api/org/osbot/rs07/utility/ConditionalSleep.html. You really need to be overriding condition() and using that to determine when to stop sleeping. Right now you are just sleeping and hoping 5000ms is enough if you CS is returning false. Also every ConditionalSleep where you are just returning true imminently does nothing. 

For example

if (tree.interact("Chop down")) {
  new ConditionalSleep(5000, 2000) {
    @Override
      public boolean condition() throws InterruptedException {
      return false;
    }
  }.sleep();
}

I think your intention is to attempt to chop down a tree, then sleep until the tree is chopped down. In which case it should be something like...
 

if (tree.interact("Chop down")) {
  new ConditionalSleep(5000, 2000) {
    @Override
    public boolean condition() throws InterruptedException {
		// As long condition() resolves to false, Conditional sleep will continue sleeping (if it hasn't been 5seconds yet).
		// When you are woodcutting, myPlayer().isAnimating() returns true. 
		// I want to my script to wait until the woodcutting animation is complete (meaning the tree is chopped down)
		// so by !myPlayer().isAnimating() (note the ! in the beginning)
		// The script will wait until your character stops chopping (aka stops animating) before checking for the next tree. 
    	
		return !myPlayer().isAnimating(); 
    }
  }.sleep();
}

 
  • Like 3

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...