Jump to content

{Beginner} Simple woodcutting script need help


Recommended Posts

Posted

I'm making a woodcutting script but I have ran into an issue, when I get a full inventory of logs my character will walk to the back but will not deposit the logs but instead run back to the trees and try to cut them down. This making my character run back and forth. Script is below, I don't know what to add to fix this. If you guys have any other recommendations to add to the script or tips let me know, Thanks.

@Override
public void onStart() throws InterruptedException {
    super.onStart();


    int wcLvl = getSkills().getStatic(Skill.WOODCUTTING);

    if (getInventory().isEmptyExcept("Bronze axe", "Iron axe", "Steel Axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe",
            "Dragon axe")) ;


}



    @Override
public int onLoop() throws InterruptedException {


    Player player = myPlayer();

    RS2Object Tree = getObjects().closest(new Filter<RS2Object>() {
        @Override
        public boolean match(RS2Object rs2Object) {
            return rs2Object != null && rs2Object.getName().equals("Tree") && rs2Object.exists() && getMap().canReach(rs2Object);
        }
    });

    if (Banks.VARROCK_WEST.contains(myPosition()) && bankbooth != null && !getBank().isOpen()) {
        getBank().withdraw("Steel axe",1);
    }
    if (Tree != null)
        if (Tree.isVisible()) {
            getWalking().walk(Tree.getPosition());
            getCamera().toEntity(Tree);
            if (Tree.getPosition().distance(myPosition()) > 6) ;
            if (!myPlayer().isAnimating())
                if (Tree.interact("Chop down")) ;
            getMouse().moveOutsideScreen();
            sleep(random(301, 2999));


        } else {

            RS2Object bankBooth = getObjects().closest("Bank booth");

            if (getInventory().isFull()) getWalking().webWalk(BANK_AREA);
           

            log("Inventory full walking to bank");

            if (Banks.VARROCK_WEST.contains(myPosition()) && bankbooth != null && !getBank().isOpen()) {
                getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe");


                log("interacting with bank");
                bankBooth.interact("Bank");
            } else if (getBank().isOpen()) {

                int wcLvl = getSkills().getStatic(Skill.WOODCUTTING);

                log("Depositing Logs");

                getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe");

                if (wcLvl >= 6 && getInventory().contains("Bronze axe", "Iron axe") && getBank().contains("Steel axe")) {

                    log("withdrawing shitty axe");
                    getBank().deposit("Bronze axe", 1);
                    getBank().withdraw("Steel axe", 1);



                }


            }

        }return 0;}}
Posted (edited)

I'd also recommend making some methods and take a look at conditional sleeps.

It's running back and forth because both your banking if statement and your chopping if statement can both be valid at the same time.

Also, change the return from 0 to like 600 or so as it'll help reduce CPU usage etc

Edited by Castro_
  • Like 1
Posted
22 minutes ago, Imthabawse said:

Perhaps split the script into 2 methods

Private void chop () {

// chop code here

Private void bank () {

// bank code here

 

Definitely feel this here. The readability of this code should jump out at you. 

 

1 hour ago, 12we12qw12 said:

I'm making a woodcutting script but I have ran into an issue, when I get a full inventory of logs my character will walk to the back but will not deposit the logs but instead run back to the trees and try to cut them down. This making my character run back and forth. Script is below, I don't know what to add to fix this. If you guys have any other recommendations to add to the script or tips let me know, Thanks.


    int wcLvl = getSkills().getStatic(Skill.WOODCUTTING);

    if (getInventory().isEmptyExcept("Bronze axe", "Iron axe", "Steel Axe", "Black axe", "Mithril axe", "Adamant axe", "Rune axe",
            "Dragon axe")) ;
}
.......

    if (Banks.VARROCK_WEST.contains(myPosition()) && bankbooth != null && !getBank().isOpen()) {
        getBank().withdraw("Steel axe",1);
    }
           

I would look into flow control for help with this...

Posted (edited)

There are many logical errors, go over each line and make sure they make sense. I highly recommend using { } properly, otherwise it will be super confusing, the entire 'if (Tree != null) is a one line if statement extending 50 lines, also format the code it should be more readable, which software are you using for coding?

Split up the logic into two, so you have player_woodcutting, and player_banking:

The woodcutting part isn't done, you gotta do that yourself:

	    @Override
    public int onLoop() throws InterruptedException {
        if (getInventory().isFull()) {
            /*
             * If inventory full, go bank
             */
            if (!Banks.VARROCK_WEST.contains(myPlayer())) {
                getWalking().webWalk(Banks.VARROCK_EAST);
            } else {
                if (!getBank().isOpen()) {
                    getBank().open();
                    return 1;
                }
                if (getBank().depositAllExcept("Bronze axe", "Iron axe", "Steel axe", "Black axe",
                        "Mithril axe", "Adamant axe", "Rune axe", "Dragon axe")) {
                    log("Deposited everything except axe");
                }
            }
        } else {
            /*
             * Inventory not full yet, keep woodcutting.
             */
            RS2Object treeObject = getObjects().closest(a -> a.getName().equalsIgnoreCase("Tree"));
            if (treeObject != null) {
                if (treeObject.interact("Chop-down")) {
                    log("Clicked chop!");
                }
            }
        }
        return 0;
    }
	

Edited by Czar
Posted (edited)

Yeah the logic in this code makes no sense. Also, you should almost NEVER return 0.

Please, do yourself a favor and look here: https://www.w3schools.com/java/java_conditions.asp

This will explain how each statement works. After looking this over you should have a better understanding - even without experience. It's easier than you would think 😛

At the bottom of the page there are also exercises for practice.

Good luck.

 

Edited by AsBakedAsCake

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