Jump to content

Chop and Burn


Recommended Posts

Posted

Hi all! I was wondering if somebody could help me with my script. It chops trees alright but once the inventory is full it will not light them.

 


import java.awt.Graphics2D;

import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.utility.ConditionalSleep;
import org.osbot.rs07.api.map.Area;



@ScriptManifest(author = "Tias", info = "Cuts trees and burns logs", name = "Choppy and Burny", version = 0, logo = "")
public class Main extends Script {

    @Override
    public void onStart() {
        log("Let's get started!");
    }

    @Override
    public int onLoop() throws InterruptedException {

        int runEnergy = settings.getRunEnergy();
        if (runEnergy > 50 && !settings.isRunning()) {
            settings.setRunning(true);
        }


        RS2Object tree = getObjects().closest(obj -> obj != null && obj.getName().equals("Tree") && getMap().canReach(obj)); //What tree to chop.
        if (!myPlayer().isAnimating() && !getInventory().isFull()) {
            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 doesn't see a tree it moves the camera and then moves.
                Area treeArea = new Area(3143, 3239, 3198, 3205);
                getCamera().toEntity(tree);
                log("Searching for a tree...");
                if (getWalking().webWalk(treeArea)) {
                    log("Walking to trees...");
                    new ConditionalSleep(5000, 6000) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return false;
                        }
                    };
                }
            }
            else if (getInventory().isFull()) {
                log("Burning  logs");
                while (inventory.contains("Logs")) {
                    log("looop");

                    if (inventory.isItemSelected()) { inventory.deselectItem(); }

                    if(!(myPlayer().isAnimating()) && inventory.interact("Use", "Tinderbox")) {
                        if (inventory.isItemSelected() && inventory.interactWithNameThatContains("Use", "Logs")) {
                            new ConditionalSleep(3000) {
                                @Override
                                public boolean condition() {
                                    return (myPlayer().isAnimating());
                                }
                            }.sleep();
                        }
                    }
                }
            }
        }

        return random(200, 300);
    }

    @Override
    public void onExit() {
        log("Thanks for running!");
    }

    @Override
    public void onPaint(Graphics2D g) {

    }

}

 

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