Jump to content

trying to create a woodcutting script


Recommended Posts

Posted

Do you have the required axe in your bank at all? Aftering checking if the bank is open, nest another if statement (or use a logical operator on the same line) that checks whether the axe is in your bank at all. If (bank.contains(Axetouse) && bank.withdraw(Axetouse, 1)) new ConditionalSleep(3000, 25). Return on that sleep whether your inventory contains the axe.

  • Like 1
Posted

Axe was in the bank and i had already added the if statement to look if the axe was
in the bank but thanks anyway Now I´m trying to create the script that if the axe isn´t in the bank he will sell the logs you harvested and buy the axe but I can't figure out how to open the offer slot in the ge (note i'm already in the ge ).

 RS2Widget Openbuymenu = getWidgets().get(465, 7, 26);
                                if(Openbuymenu != null) {
                                    Openbuymenu.interact("Buy");
                                    new ConditionalSleep(5000) {
                                        public boolean condition() throws InterruptedException {
                                            return grandExchange.isOfferScreenOpen();
                                        }
                                    }.sleep();
                                }
                                keyboard.typeString(AxeToUse());
                                int Offerprice = grandExchange.getOfferPrice();
                                grandExchange.setOfferPrice( 2 * Offerprice );

 

Posted
9 minutes ago, heervangrijsburg said:

It would be possible with widgets if I am not mistaken.

It would be. I commend you for creating your own methods for the GE.

Are you certain that "Buy" is the right interact string? When hovering I see "Create Buy offer". Alternatively, you can ask for the x, y coordinate of that widget and create a rectangle based on the x, y, width and height. Then you can click on that with the mouse class.

  • Like 1
Posted (edited)

hello,

thanks @Steel Poster but I now use "grandExchange.buyItem".

Now I´m getting this error and i don´t know how to fix it :

222336162_Screenshot(325).thumb.png.4d3808f8c8cf7f166c4687494c007c4c.png

this is the part of the code I think the problem is in but like I said I don´t know how to fig it

Main class

Spoiler

package script;

import items.Axe;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import tasks.*;

@ScriptManifest(author = "Heervangrijsburg", logo = "", info ="Cuts trees" , version = 1.2 , name = "Tree chopper")
public final class Main extends Script {
    private final GoChopTree goChopTree = new GoChopTree();
    private final GoBank goBank = new GoBank();
    private final Axe axe = new Axe();
    private final GoGetAxe gogetaxe = new GoGetAxe();



    @SuppressWarnings("deprecation")
    @Override
    public void onStart() {
        goChopTree.exchangeContext(getBot());
        goBank.exchangeContext(getBot());
        axe.exchangeContext(getBot());
        gogetaxe.exchangeContext(getBot());
    }

    @Override
    public void onExit() {

    }

    @Override
    public int onLoop() throws InterruptedException {
        log("start oke");
        if (inventory.isEmptyExcept(1511, 1353,1361,1355,1357,1359,1351)) {
            log ("section 2");
            if (!inventory.isFull()) {
                log ("section 3");
                if (inventory.contains(axe.AxeToUseName())) {
                    log ("section 4");
                    goChopTree.choptree();
                } else {
                    gogetaxe.getsrightaxe();
                }
            } else {
                log ("section 2,1");
                goBank.bankafterchopptingtrees();
            }
        } else {
            log ("section 1,1");
            goBank.bankinventoryjunk();
        }
        return 1000;
    }
}

 

 

GoGetAxe class :

Spoiler

package tasks;

import org.osbot.rs07.api.map.Area;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.utility.ConditionalSleep;
import items.Axe;
import pricege.*;

public final class GoGetAxe extends MethodProvider {
    private Axe axe = new Axe();
    private Area bank_area = new Area(
            new int[][]{
                    { 3092, 3246 },
                    { 3092, 3240 },
                    { 3097, 3240 },
                    { 3097, 3246 }
            }
    );
    private Area grandexchange_Area = new Area(
            new int[][]{
                    {3162, 3486},
                    {3168, 3486},
                    {3168, 3493},
                    {3161, 3492}
            }
    );

    public void getsrightaxe() throws InterruptedException {
        if (bank_area.contains(myPlayer())) {
            if (bank.isOpen()){
                if (bank.contains(axe.AxeToUseName())){
                    bank.withdraw(axe.AxeToUseName(), 1);
                } else {
                    buyrightaxe();
                }
                bank.close();
                new ConditionalSleep(5000){
                    public boolean condition() throws InterruptedException {
                        return !bank.isOpen();
                    }
                }.sleep();
            } else {
                bank.open();
                new ConditionalSleep(5000){
                    public boolean condition() throws InterruptedException {
                        return bank.isOpen();
                    }
                }.sleep();
            }
        } else {
            getWalking().webWalk(bank_area);
            new ConditionalSleep(5000) {
                public boolean condition() throws InterruptedException {
                    return bank_area.contains(myPlayer());
                }
            }.sleep();
        }
    }

 

Axe class

Spoiler

package items;

import org.osbot.rs07.api.ui.Skill;
import org.osbot.rs07.script.MethodProvider;

public class Axe extends MethodProvider {
    public String AxeToUseName() {
        if (skills.getDynamic(Skill.WOODCUTTING) <= 10) {
            return "Steel axe";
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 20) {
            return "Black axe";
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 30) {
            return "Mithril axe";
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 40) {
            return "Adamant axe";
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 99) {
            return "Rune axe";
        } else {
            return "bronze axe";
        }
    }
    public int AxeToUseID() {
        if (skills.getDynamic(Skill.WOODCUTTING) <= 10) {
            return 1353;
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 20) {
            return 1361;
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 30) {
            return 1355;
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 40) {
            return 1357;
        } else if (skills.getDynamic(Skill.WOODCUTTING) <= 99) {
            return 1359;
        } else {
            return 1351;
        }
    }
}

 

 

Edited by heervangrijsburg
adding Axe class
Posted (edited)

If I were you, I'd take a look into what classes/methods are just in general in Java.

It seems like you have classes for simple tasks where methods would be sufficient. Having a class for just a small task is not advised and very bad coding habits.

Look into object-oriented programming as that's what Java was developed for :)

Edited by Rays

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