Jump to content

Tree cutting help!


Recommended Posts

Posted

Hi, 

 

I'm still new to scripting and learning java while scripting..

 

but here is the code, I was wondering how would I tell the bot to only cut trees that are in the tree area? Even if it is visible, I don't want the bot to click trees that are not in the area?

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import java.awt.*;

/**
 * Created by Phaibooty on 1/11/2017.
 */

@ScriptManifest(author = "Phaibooty", info = "Chops Logs Only", name ="LogWoodcutter", version = 1, logo ="")
public class SimpleWoodcutter extends Script {

    final String tree_name = "Tree";
    final Area BANK_AREA = new Area(3092,3040,3097,3246);
    final Area Tree_Area = new Area(3103,3226,3114,3233);
    final int BANK_BOOTH_ID = 23961;

    @[member=Override]
    //Code used at Start
    public void onStart() {
        log("lets get started!");
        log("This is where the code begins.");

    }

    @[member=Override]
        public int onLoop() throws InterruptedException {

        if(!inventory.isFull()){
            //Chop
        	
        	if(Tree_Area.contains(myPlayer())){
            Entity tree = objects.closest(tree_name);
            if (tree != null) {
                if (tree.isVisible()) {
                	if(!myPlayer().isAnimating()){
                		if(!myPlayer().isMoving()){
                    tree.interact("Chop down");
                    sleep(random(700,800));
                	}
                } 
            } else {
                    camera.toEntity(tree);
                }
            }
        } else {
        	getWalking().webWalk(Tree_Area);
        }
        }else {
            //bank
        	if (BANK_AREA.contains(myPlayer())){
        		Entity bankbooth = objects.closest(BANK_BOOTH_ID);
        		
        		if(bank.isOpen()){
        			bank.depositAll();
        			
        		}
        		if (bankbooth != null){
        			if(bankbooth.isVisible()){
        				bankbooth.interact("Bank");
        				sleep(random(700,800));
        			}
        			
        		}
       		
        	} else {
        		getWalking().webWalk(BANK_AREA);
        	}
        }

        return random(200, 300);
    }

    @[member=Override]
    //Code used at End
    public void onExit(){
        log("Thanks for using my woodcutter!");
    }

    @[member=Override]
    public void onPaint(Graphics2D g) {

    }

}

Code is really messy and I'm still confused... but hopefully some guidance will help.

Posted

Isn't there an area#contains(Entity entity)?

 

If (Tree_area.contains(tree)) {

}

 

or smth

 

Thank you!

 

Gave this a try, and works beautifully.

 

Still a little confused on where I should put it, but I guess that just comes with more java knowledge lol.

 

I put it right before tree.isVisible..

 

  @[member=Override]
        public int onLoop() throws InterruptedException {


        if(!inventory.isFull()){
            //Chop
         
         if(Tree_Area.contains(myPlayer())){
            Entity tree = objects.closest(tree_name);
            if (tree != null) {
             if (Tree_Area.contains(tree))
                if (tree.isVisible()) {
                 if(!myPlayer().isAnimating()){
                 if(!myPlayer().isMoving()){
                    tree.interact("Chop down");
                    sleep(random(700,800));
                 }
                } 
            } else {
                    camera.toEntity(tree);
                }
            }

RS2Object tree = getObjects().closest(AREA_HERE, TREE_NAME HERE);

 

check out the api here for more options:

 

http://osbot.org/api/org/osbot/rs07/api/EntityAPI.html

 

shit, explains why it stops chopping after 1 tree. lmao

 

Still a little confused on how to use that line of code but I'll keep reading. Thank you!

Posted (edited)

Thank you!

 

Gave this a try, and works beautifully.

 

Still a little confused on where I should put it, but I guess that just comes with more java knowledge lol.

 

I put it right before tree.isVisible..

 

  @[member='Override']
        public int onLoop() throws InterruptedException {


        if(!inventory.isFull()){
            //Chop
         
         if(Tree_Area.contains(myPlayer())){
            Entity tree = objects.closest(tree_name);
            if (tree != null) {
             if (Tree_Area.contains(tree))
                if (tree.isVisible()) {
                 if(!myPlayer().isAnimating()){
                 if(!myPlayer().isMoving()){
                    tree.interact("Chop down");
                    sleep(random(700,800));
                 }
                } 
            } else {
                    camera.toEntity(tree);
                }
            }

 

shit, explains why it stops chopping after 1 tree. lmao

 

Still a little confused on how to use that line of code but I'll keep reading. Thank you!

 

here is what it could look like:

 

if(!getInventory().isFull()) {
		            //Chop
			        if(!myPlayer().isAnimating() && !myPlayer().isMoving()) {
			        	 if(TREE_AREA.contains(myPlayer())) {
			        		 Entity tree = getObjects().closest(AREA_HERE, TREE_NAME);
			        		 if (tree != null) {
			        			 if(tree.interact("CHOP??"))
			        				 add sleep here
			        		 }
			        	 }
			        }
		        }
Edited by Precise
  • Like 2
Posted

 

here is what it could look like:

 

if(!getInventory().isFull()) {
		            //Chop
			        if(!myPlayer().isAnimating() && !myPlayer().isMoving()) {
			        	 if(TREE_AREA.contains(myPlayer())) {
			        		 Entity tree = getObjects().closest(AREA_HERE, TREE_NAME);
			        		 if (tree != null) {
			        			 if(tree.interact("CHOP??"))
			        				 add sleep here
			        		 }
			        	 }
			        }
		        }

 

 

Thank you! I appreciate the help. It works beautifully now.

 

Going to do more studying lmao. thanks again

  • Like 2
Posted
if (BANK_AREA.contains(myPlayer())){
        		Entity bankbooth = objects.closest(BANK_BOOTH_ID);
        		
        		if(bank.isOpen()){
        			bank.depositAll();
        			
        		}
        		if (bankbooth != null){
        			if(bankbooth.isVisible()){
        				bankbooth.interact("Bank");
        				sleep(random(700,800));
        			}
        			
        		}

Now there is no need for

Entity bankbooth = objects.closest(BANK_BOOTH_ID);

Instead you can simply use the Bank(Api) to open by using:

getBank().open();

And the second thing is that the logic is wrong instead you can do:

if (BANK_AREA.contains(myPlayer())){
        		
        		if(bank.isOpen()){ // If bank is opened deposit all
        			bank.depositAll();
        			
        		} else { // If bank is not opened open it
        			getBank().open();
                                new ConditionalSleep(5000) { // Conditional Sleep 5000ms untill bank is open.
					@[member=Override]
					public boolean condition() throws InterruptedException {
						return getBank().isOpen();
						}
					}.sleep();
        		}
Posted
if (BANK_AREA.contains(myPlayer())){
        		Entity bankbooth = objects.closest(BANK_BOOTH_ID);
        		
        		if(bank.isOpen()){
        			bank.depositAll();
        			
        		}
        		if (bankbooth != null){
        			if(bankbooth.isVisible()){
        				bankbooth.interact("Bank");
        				sleep(random(700,800));
        			}
        			
        		}

Now there is no need for

Entity bankbooth = objects.closest(BANK_BOOTH_ID);

Instead you can simply use the Bank(Api) to open by using:

getBank().open();

And the second thing is that the logic is wrong instead you can do:

if (BANK_AREA.contains(myPlayer())){
        		
        		if(bank.isOpen()){ // If bank is opened deposit all
        			bank.depositAll();
        			
        		} else { // If bank is not opened open it
        			getBank().open();
                                new ConditionalSleep(5000) { // Conditional Sleep 5000ms untill bank is open.
					@[member='Override']
					public boolean condition() throws InterruptedException {
						return getBank().isOpen();
						}
					}.sleep();
        		}

 

Wow. Beautiful. Thank you for the help. 

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