Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Trying to learn how to work with GE

Featured Replies

Spoiler

private void withdrawCoinsAndLogs() throws InterruptedException {
        while (!inventory.contains(995) || !inventory.contains(1511)) {
            if (bank.isOpen()) {
                bank.withdrawAll("Logs");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return inventory.contains("Logs");
                    }
                }.sleep();
                bank.withdrawAll(995);
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return inventory.contains(995);
                    }
                }.sleep();
            } else {
                bank.open();
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return bank.isOpen();
                    }
                }.sleep();
            }
        }
    }

    public void sellLogs() throws InterruptedException {
        while (inventory.contains(1511)) {
            if (grandExchange.isOpen()) {
                grandExchange.sellItem(1511, 1, Math.toIntExact(inventory.getAmount(1511)));
                while (grandExchange.getAmountRemaining(GrandExchange.Box.BOX_1) != 0) {
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() {
                            return grandExchange.getAmountRemaining(GrandExchange.Box.BOX_1) == 0;
                        }
                    }.sleep();
                }
                grandExchange.collect();
            } else {
                NPC grandExchangClerk = npcs.closest(2148);
                grandExchangClerk.interact("Exchange");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return grandExchange.isOpen();
                    }
                }.sleep();
            }
        }
    }

    public void buyaxe() throws InterruptedException {
        while (!inventory.contains(axe.axeToUseID())) {
            if (grandExchange.isOpen()) {
                grandExchange.buyItem(axe.axeToUseID(), axe.axeToUseName(), Math.toIntExact(inventory.getAmount(995)), 1);
                while (grandExchange.getAmountRemaining(GrandExchange.Box.BOX_1) != 0) {
                    new ConditionalSleep(5000) {
                        @Override
                        public boolean condition() {
                            return grandExchange.getAmountRemaining(GrandExchange.Box.BOX_1) == 0;
                        }
                    }.sleep();
                }
                grandExchange.collect();
            } else {
                NPC grandExchangClerk = npcs.closest(2148);
                grandExchangClerk.interact("Exchange");
                new ConditionalSleep(5000) {
                    @Override
                    public boolean condition() {
                        return grandExchange.isOpen();
                    }
                }.sleep();
            }
        }
    }

    @Override
    public int onLoop() throws InterruptedException {
        if (grandexchange_Area.contains(myPlayer())) {
            withdrawCoinsAndLogs();
            if (Math.toIntExact(inventory.getAmount(995)) >= 850) {
                buyaxe();
            } else {
                sellLogs();
            }
        } else {
            getWalking().webWalk(grandexchange_Area);
            new ConditionalSleep(5000) {
                @Override
                public boolean condition() {
                    return grandexchange_Area.contains(myPlayer());
                }
            }.sleep();
        }
        return 600;
    }
}

 

As the title says, I try to learn how to work with the GE. What I'm trying to do with this bot is that it gets coins and logs from the bank sells the logs at the GE (currently the logs can be sold at 1 gp later I will try to get the right prices from osbuddy).

 

then the bot would have to buy a steel axe at the GE (currently all coins in the inventory can be used for this later I will also try to get the right prices from osbuddy).

Unfortunately, the bot clicks randomly succeeds to get the coins and logs from the bank than he opens the GE to start clicking all over the place. Would anyone be able to look at my code and maybe give me a quick tutorial on how to work with the GE (preferably with a few examples)

thank you in advance
heervangrijsburg

 

 

12 hours ago, heervangrijsburg said:

As the title says, I try to learn how to work with the GE. What I'm trying to do with this bot is that it gets coins and logs from the bank sells the logs at the GE (currently the logs can be sold at 1 gp later I will try to get the right prices from osbuddy).

then the bot would have to buy a steel axe at the GE (currently all coins in the inventory can be used for this later I will also try to get the right prices from osbuddy).

Unfortunately, the bot clicks randomly succeeds to get the coins and logs from the bank than he opens the GE to start clicking all over the place. Would anyone be able to look at my code and maybe give me a quick tutorial on how to work with the GE (preferably with a few examples)

thank you in advance

heervangrijsburg

There's a few things to address here... 

1. Try not to use static IDs, as these could change and it could break the script. Instead use a string literal to retrieve items 

if ( getInventory().contains("Logs") ) {}

2. Null check NPCs to avoid NullPointerExceptions, and move interactions to a conditional statement. This is so you can better deal with the success and failure events (true / false). 

NPC exchangeClerk = getNpcs().closest("Grand Exchange Clerk");

if ( exchangeClerk != null && exchangeClerk.interact("Exchange") ) {

	new ConditionalSleep(MethodProvider.random(2000, 2500)) {
		@Override
		public boolean condition() throws InterruptedException {
			return getGrandExchange().isOpen();
		}
	}.sleep();

}

3. Avoid while() statements, they are blocking the script onLoop(). The game environment is changing constantly and if the conditional for the while statement is unreachable your script will be unable to proceed. Instead write better conditionals. 

---

Spoiler Alert - if you want to use an event to handle this, here is my snippet. As you can see I need to remove the static IDs for Addy and Mith axe, I can do this using an API for the items and dynamically fill item IDs. 

Spoiler

package events;

import org.osbot.rs07.api.Bank;
import org.osbot.rs07.api.GrandExchange;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.event.Event;
import org.osbot.rs07.script.MethodProvider;
import org.osbot.rs07.utility.ConditionalSleep;

import java.util.Arrays;
import java.util.List;

public class BuyAxesEvent extends Event {

    @Override
    public int execute() {
        if ( getInventory().contains("Adamant axe") && getInventory().contains("Mithril axe") ) {
            setFinished();
        } else if (!Banks.GRAND_EXCHANGE.contains(myPosition())) {
            getWalking().webWalk(Banks.GRAND_EXCHANGE);
        } else {

            Item logs = getInventory().getItem("Logs");

            if ( logs != null && !logs.isNote() ) {

                withdrawNotes(logs);

                return 1000;

            }

            sellLogs();


        }

        return 200;

    }

    private void withdrawNotes(Item item) {

        if ( getBank().isOpen() ) {

            if (getBank().getWithdrawMode() != Bank.BankMode.WITHDRAW_NOTE)
                getBank().enableMode(Bank.BankMode.WITHDRAW_NOTE);

            if (getBank().depositAll(item.getName())) {

                new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return !getInventory().contains(item.getName());
                    }
                }.sleep();

            getBank().withdrawAll(item.getName());

            }

        } else {

            NPC banker = getNpcs().closest("Banker");

            if ( banker != null && banker.interact("Bank") ) {

                new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getBank().isOpen();
                    }
                }.sleep();

            }

        }

    }

    private void sellLogs(){

        if ( getBank().isOpen() )
            getBank().close();

        if ( ! getGrandExchange().isOpen() ) {

            NPC exchangeClerk = getNpcs().closest("Grand Exchange Clerk");

            if ( exchangeClerk != null && exchangeClerk.interact("Exchange") ) {

                new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getGrandExchange().isOpen();
                    }
                }.sleep();

            }

        } else {

            if ( getInventory().contains("Logs") ) {

                Item logs = getInventory().getItem("Logs");

                if ( getGrandExchange().sellItem(logs.getId(), 1, logs.getAmount()) ) {

                    new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                        @Override
                        public boolean condition() throws InterruptedException {
                            return getGrandExchange().getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.PENDING_SALE;
                        }
                    }.sleep();

                }

            } else if ( getGrandExchange().getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.FINISHED_SALE && getGrandExchange().collect() ) {

                new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getInventory().contains("Coins");
                    }
                }.sleep();

            } else if ( getInventory().contains("Coins") ) {

                if ( getGrandExchange().getStatus(GrandExchange.Box.BOX_1).equals(GrandExchange.Status.EMPTY) && !getInventory().contains("Mithril axe")) {

                    if ( getGrandExchange().buyItem(1355, "Mithril axe", 1000, 1) ) {

                        new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return getGrandExchange().getStatus(GrandExchange.Box.BOX_1) == GrandExchange.Status.PENDING_BUY;
                            }
                        }.sleep();

                    }

                }

                if ( getGrandExchange().getStatus(GrandExchange.Box.BOX_2).equals(GrandExchange.Status.EMPTY) && !getInventory().contains("Adamant axe")) {

                    if ( getGrandExchange().buyItem(1357, "Adamant axe", 1000, 1) ) {

                        new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return getGrandExchange().getStatus(GrandExchange.Box.BOX_2) == GrandExchange.Status.PENDING_BUY;
                            }
                        }.sleep();

                    }

                }

                if ( getGrandExchange().getStatus(GrandExchange.Box.BOX_1).equals(GrandExchange.Status.FINISHED_BUY)|| getGrandExchange().getStatus(GrandExchange.Box.BOX_2).equals(GrandExchange.Status.FINISHED_BUY) ) {

                    if ( getGrandExchange().collect() ) {

                        new ConditionalSleep(MethodProvider.random(2000, 2500)) {
                            @Override
                            public boolean condition() throws InterruptedException {
                                return !getGrandExchange().isBuyOfferOpen();
                            }
                        }.sleep();

                    }

                }

            }

        }

    }

}

Run with 


import events.BuyAxesEvent;

private final BuyAxesEvent buyAxes = new BuyAxesEvent();

if (!getInventory().contains("Adamant axe")) {

	execute(buyAxes);

}

 

 

  • Author

Thank you very much for the tips. I will have a bit of work to understand everything and be able to write it all myself, but with this I can work further.

Thanks again.


 

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.