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.

getInventory().isFull ALWAYS returns TRUE!

Featured Replies

First of all, first ever script I'm writing so don't judge me (yet).

So the problem here is everytime the bot hops to a random F2P world, and the onLoop method runs, it returns the currentState.INVENTORY_FULL --- EVEN WHEN THE INVENTORY IS NOT FULL!

I've tried numerous things, conditional loop till player exists, player is visible, player is not null, player is on screen but it always returns true when checking if the inventory is full.

 

Here is my source code:

import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.map.constants.Banks;
import org.osbot.rs07.api.model.NPC;
import org.osbot.rs07.api.model.RS2Object;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.utility.ConditionalSleep;
import org.osbot.rs07.script.ScriptManifest;

@ScriptManifest(author = "Stufid N00b", info = "Zaff's Staff Hoarder", name = "ZaffBot BETA", version = 0, logo = "")

public class Main extends Script {

    public NPC zaffNPC;
    public Position zaffShopPos;
    public boolean coinsAreAvailable = false;
    public boolean reachedZaffShopPos = false;
    public boolean zaffDoorOpen = false;
    public boolean playerAtZaff = false;

    public enum currentState {
        NULL, COINS_AVAILABLE, REACHED_ZAFF_SHOP, ZAFF_DOOR_OPEN, INVENTORY_FULL
    }

    public currentState getState() {
        if (!coinsAreAvailable) {
            if (getInventory().contains("Coins")) {
                coinsAreAvailable = true;
                log("Coins are available.");
                return currentState.COINS_AVAILABLE;
            } else {
                log("Coins are not available, stopping script.");
                stop(false);
            }
        }

        if (reachedZaffShopPos) {
            return currentState.REACHED_ZAFF_SHOP;
        }

        if (zaffDoorOpen) {
            RS2Object zaffDoor = getObjects().closest("Door");
            if (zaffDoor != null && zaffDoor.hasAction("Close")) {
                zaffDoorOpen = false;
                return currentState.ZAFF_DOOR_OPEN;
            } else {
                zaffDoorOpen = false;
                reachedZaffShopPos = true;
            }
        }

        if (playerAtZaff) {
            playerAtZaff = false;
           return currentState.ZAFF_DOOR_OPEN;
        }

        if (getInventory().isFull()) {
            log("Inventory is full.");
            return currentState.INVENTORY_FULL;
        }
        return currentState.NULL;
    }

    @Override
    public int onLoop() throws InterruptedException {
        switch (getState()) {
            case COINS_AVAILABLE:
                zaffShopPos = new Position(3205,3432,0);
                log("Attempting to walk to zaffShopPos.");
                if (getWalking().webWalk(zaffShopPos)) {
                    reachedZaffShopPos = true;
                } else {
                    coinsAreAvailable = false; //Restart script
                }

            case REACHED_ZAFF_SHOP:
                RS2Object zaffDoor = getObjects().closest("Door");
                if (zaffDoor != null && zaffDoor.hasAction("Open")) {
                    if (zaffDoor.interact("Open")) {
                        reachedZaffShopPos = false;
                        zaffDoorOpen = true;
                        log("Zaff's door is now open.");
                    }
                } else if (zaffDoor != null && zaffDoor.hasAction("Close")) {
                    reachedZaffShopPos = false;
                    zaffDoorOpen = true;
                    log("Zaff's door is open.");
                }

            case ZAFF_DOOR_OPEN:
                new ConditionalSleep(10000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        zaffNPC = getNpcs().closest("Zaff");
                        return (zaffNPC != null && zaffNPC.isVisible());
                    }
                }.sleep();
                zaffNPC = getNpcs().closest("Zaff");
                    if (zaffNPC != null && zaffNPC.isVisible()) {
                        camera.toEntity(zaffNPC);
                        if (zaffNPC.interact("Trade")) {
                            int rndSleepTime1 = random(3000,5000);
                            Thread.sleep(rndSleepTime1);
                            if (getStore() != null && getStore().isOpen()) {
                                if (getStore().getAmount("Staff") > 0) {
                                    if (getStore().buy("Staff", 5)) {
                                        int rndSleepTime2 = random(1000,5000);
                                        Thread.sleep(rndSleepTime2);
                                        getStore().close();
                                        if (getWorlds().hopToF2PWorld()) {
                                            new ConditionalSleep(10000) {
                                                @Override
                                                public boolean condition() throws InterruptedException {
                                                    zaffNPC = getNpcs().closest("Zaff");
                                                    return (zaffNPC != null && zaffNPC.isVisible());
                                                }
                                            }.sleep();
                                            playerAtZaff = true;
                                        }
                                    }
                                }
                            } else {
                                reachedZaffShopPos = true;
                            }
                    }
                }

            case INVENTORY_FULL:
                if (!(Banks.VARROCK_WEST.contains(myPlayer().getPosition()))) {
                    log("Inventory is full..?!");
                    getWalking().webWalk(Banks.VARROCK_WEST);
                } else {
                    if (!(getBank().isOpen())) {
                        getBank().open();
                            new ConditionalSleep(10000) {
                                @Override
                                public boolean condition() throws InterruptedException {
                                    return getBank().isOpen();
                                }
                            }.sleep();
                        log("Attempting to deposit items...");
                        if (getBank().depositAllExcept("Coins")) {
                            new ConditionalSleep(10000) {
                                @Override
                                public boolean condition() throws InterruptedException {
                                    return !getInventory().isFull();
                                }
                            }.sleep();
                            coinsAreAvailable = false;
                        }
                    }
                }
        }
        return random(500,1000);
    }
}

 

I'd like some help.

  • Author
1 hour ago, Muffins said:

just a protip, webwalker will automatically handle obstacles (i.e. doors)

Lol, you kidding me? Was a pain in the ass to write the door method, but thanks!

 

You think you can help me out with the hopping? Should I just declare an int variable and increase it every hop, if it reaches x then go bank?

After loading into a world you can't read whats in your inventory unless you open it once. It's just like logging into the game because you are doing the same thing just on a different server.

  • Author
10 minutes ago, TheWind said:

After loading into a world you can't read whats in your inventory unless you open it once. It's just like logging into the game because you are doing the same thing just on a different server.

So what you're saying is the code needs to perform a click on the inventory (open the inventory) before it can determine which items are in the inventory?

Just now, MadMork said:

So what you're saying is the code needs to perform a click on the inventory (open the inventory) before it can determine which items are in the inventory?

Yep basically this. I've noticed that inventory methods sometimes don't work properly when inventory is not open. Best to check if inventory is open, if no then open it and then check whatever you need in it

  • Author
4 minutes ago, nosepicker said:

Yep basically this. I've noticed that inventory methods sometimes don't work properly when inventory is not open. Best to check if inventory is open, if no then open it and then check whatever you need in it

Awesome, thanks.

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.