Jump to content

need help chopping trees only in area


dunderzutt

Recommended Posts

Script is from HeyImJamie, i'm tryna learn from it. Right now it clicks trees outside the area I selected "(3119, 3221, 3104, 3217);" then it runs back into area and creating a loop of clicking outside area then moving back into area etc etc. Would appreciate any help! thanks!



package core;
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.DRAYNOR.contains(myPlayer())) {
            getWalking().webWalk(Banks.DRAYNOR);
        } 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(3119, 3221, 3104, 3217);
        }
    }

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

Link to comment
Share on other sites

47 minutes ago, dunderzutt said:


            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();

Add your area when getting the object
 RS2Object tree = getObjects().closest(getTreeArea(), getTreeName());

Edited by FuryShark
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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