Jump to content

getInventory().isFull ALWAYS returns TRUE!


Recommended Posts

Posted

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.

Posted
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?

Posted
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?

Posted
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

  • Like 1

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