Jump to content

Open Source Woodcutting Script


Recommended Posts

Posted (edited)

Written this up quickly. Banks at Varrock West and chops Trees to 15, Oaks to 60 and Yews 60+. Doesn't check for axes etc, I'll leave that for you to add. :) 

 

 

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.map.constants.Banks;
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(name = "Free Woodcutter", version = 1.0, author = "HeyImJamie", info = "", logo = "")
public class Main extends Script {

    @Override
    public int onLoop() throws InterruptedException {

        if (shouldBank()) {
            bank();
        } else {
            cutTree(getTreeName());
        }
        return 100;
    }

    private boolean shouldBank() {
        return getInventory().isFull();
    }

    private void bank() throws InterruptedException {
        if (!Banks.VARROCK_WEST.contains(myPlayer())) {
            getWalking().webWalk(Banks.VARROCK_WEST);
        } else {
            if (!getBank().isOpen()) {
                getBank().open();
            } else {
                getBank().depositAllExcept(axes -> axes.getName().contains(" axe"));
            }
        }
    }

    private void cutTree(String treeName) {
        if (!getTreeArea().contains(myPlayer())) {
            getWalking().webWalk(getTreeArea());
        } else {
            RS2Object tree = getObjects().closest(treeName);
            if (!myPlayer().isAnimating() && tree != null) {
                if (tree.interact("Chop down")) {
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return myPlayer().isAnimating();
                        }
                    }.sleep();
                }
            }
        }
    }

    private Area getTreeArea() {
        if (getSkills().getDynamic(Skill.WOODCUTTING) >= 60) {
            return new Area(3203, 3506, 3225, 3497);
        } else {
            return new Area(3171, 3425, 3159, 3399);
        }
    }

    private String getTreeName() {
        if (getSkills().getDynamic(Skill.WOODCUTTING) >= 60){
            return "Yew";
        } else if (getSkills().getDynamic(Skill.WOODCUTTING) >= 15){
            return "Oak";
        } else {
            return "Tree";
        }
    }
}

 

 
 
 
Edited by HeyImJamie
  • Like 7
Posted
2 minutes ago, Tom said:

Looks to me Explv has his hands around your neck

I wanted to grow his lil e-peen, I still fanboy Tasks :boge: 

5 minutes ago, ProjectPact said:

Remember, people can't learn from something that isn't tested. If something is broken, it will probably just confuse them even more. 

Was just strings I didn't check. I'll load OSbot now and confirm :) 

  • Like 1
Posted
1 minute ago, ProjectPact said:

Great contribution though! Was just giving you some advice, not bashing :)

You made a good point! As it happened I'd put in an incorrect string, so someone would've been confused! :P 

7 minutes ago, Antonio Kala said:

Now this is what I'm talking about.

 

Added to the collection.

 

Would like if you tested it first tho

Tested, Works. :boge: 

  • Like 1
Posted (edited)

@HeyImJamie

Looks nice, good job

Just FYI you should be checking if wc levels are >=, rather than >. Right now your script will keep chopping normal trees until level 16, and oaks until level 61.

Also you might want to consider using an enum for storing your Tree names & areas. Something like this:

enum Tree {
    NORMAL("Tree", 1, new Area(1, 2, 3, 4)),
    OAK("Oak", 15, new Area(1, 2, 3, 4)),
    YEW("Yew", 60, new Area(1, 2, 3, 4));

    String name;
    int levelRequired;
    Area area;

    Tree(final String name, final int levelRequired, final Area area) {
        this.name = name;
        this.levelRequired = levelRequired;
        this.area = area;
    }
}

 

You can also avoid having lots of nested if statements, by just inverting them:

if (getTreeArea().contains(myPlayer())) {
  if ..
    if ..
} else {
  getWalking().webWalk(...);
}

Becomes:

if (!getTreeArea().contains(myPlayer())) {
    getWalking().webWalk(...);
} else if {
    ... 
} ...

 

Edited by Explv
  • Like 4
Posted

Looks good, pretty similar to progressiveWC. You have a lot of nested if statements that could be shortened (e.g. if (tree != null && tree.interact("Chop down")). Tree names and areas should be final constants declared once instead of returning a new area/string each time. Logic of the script has some quirks such as not switching to the next tree when the current tree is chopped down (by someone else) and waiting until the animation ends.

Posted
7 minutes ago, Explv said:

@HeyImJamie

Looks nice, good job

Just FYI you should be checking if wc levels are >=, rather than >. Right now your script will keep chopping normal trees until level 16, and oaks until level 61.

Also you might want to consider using an enum for storing your Tree names & areas. Something like this:


enum Tree {
    NORMAL("Tree", 1, new Area(1, 2, 3, 4)),
    OAK("Oak", 15, new Area(1, 2, 3, 4)),
    YEW("Yew", 60, new Area(1, 2, 3, 4));

    String name;
    int levelRequired;
    Area area;

    Tree(final String name, final int levelRequired, final Area area) {
        this.name = name;
        this.levelRequired = levelRequired;
        this.area = area;
    }
}

 

You can also avoid having lots of nested if statements, by just inverting them:


if (getTreeArea().contains(myPlayer())) {
  if ..
    if ..
} else {
  getWalking().webWalk(...);
}

Becomes:


if (!getTreeArea().contains(myPlayer())) {
    getWalking().webWalk(...);
} else if {
    ... 
} ...

 

Never thought about Enums before. Will definitely use in the future :)

I'll update in regards to the >= and nested if's though

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...