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.

stuck on getInventory.....

Featured Replies

First thing we need is an instance that supplies the methods we need (from MethodProvider). We can do this by extending upon the API type:
final class DefaultAPI extends API {

}

You will be forced to declare an initializeModule method. Don't worry about it, just the devs not following interface segregation wink.png Leave it blank. You could fill it in, but you would be required to call it after instantiating API. 

 

Once you have your API type, create an instance of it in onStart in your Script subclass:

final class MyScript extends Script {
    private API api;

    public void onStart() {
        api = new DefaultAPI();

    }
}

Finally, we need to pass the context of our script to our api instance. We do this by calling exchangeContext on our api instance, passing in the script's bot:

final class MyScript extends Script {
    private API api;

    public void onStart() {
        api = new DefaultAPI();
        api.exchangeContext(getBot());

    }
}

I quoted fixthissite's post. Read it through thoroughly and if you pay attention, you'll make it.

 

Edit: If you did all of this above, here is an example:

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.API;


public class Inventory {

    // ADDED THIS HERE @@@
    private API api;

    public Inventory(API api) {
        this.api = api;
    }
    // @@@@@@@
	
    // WARNING: Untested code
    
    /** Holds the amount of willows we have cut */
    private int willowsCut = 0;
    /** Holds the last inventory that was compared */
    private Item[] lastInv;
    
    /**
     * Simple getter
     * @return the number of willows cut
     */
    public int getWillowsCut() {
        return willowsCut;
    }
    
    /**
     * Compares your last inventory with the current inventory.
     */
    public void compareItems() {
        if (lastInv == null) {
            lastInv = api.getInventory().getItems();
            return; // It will be the same, no need to check
        }
        
        String item = "Willow logs";
        Item[] currInv = getInventory().getItems();
        for (int i = 0; i < 28; i++) {
            // Check for the same thing
            if ((currInv[i] == null && lastInv == null)
                    || currInv[i].getName().equals(lastInv[i].getName()))
                continue; // Its the same, continue
            
            if (currInv[i] != null) {
                // We have an item when we didn't
                if (currInv[i].getName().equals(item))
                    willowsCut++; // It was a willow log, ++
            } else {
                // We don't have an item when we did
                if (lastInv[i].getName().equals(item))
                    willowsCut--; // It was a willow log, --
            }
        }
        lastInv = currInv; // Update the inv
    }
    
    /**
     * Run this when the lastInv needs refreshing, aka after banking
     */
    public void resetItems() {
        lastInv = api.getInventory().getItems();
    }
}

If you want to get inventory in your Inventory class, simply do "api.getInventory()".

Edited by Woody

  • Author

 

First thing we need is an instance that supplies the methods we need (from MethodProvider). We can do this by extending upon the API type:
final class DefaultAPI extends API {

}

You will be forced to declare an initializeModule method. Don't worry about it, just the devs not following interface segregation wink.png Leave it blank. You could fill it in, but you would be required to call it after instantiating API. 

 

Once you have your API type, create an instance of it in onStart in your Script subclass:

final class MyScript extends Script {
    private API api;

    public void onStart() {
        api = new DefaultAPI();

    }
}

Finally, we need to pass the context of our script to our api instance. We do this by calling exchangeContext on our api instance, passing in the script's bot:

final class MyScript extends Script {
    private API api;

    public void onStart() {
        api = new DefaultAPI();
        api.exchangeContext(getBot());

    }
}

I quoted fixthissite's post. Read it through thoroughly and if you pay attention, you'll make it.

 

Edit: If you did all of this above, here is an example:

import org.osbot.rs07.api.model.Item;
import org.osbot.rs07.script.API;


public class Inventory {

    // ADDED THIS HERE @@@
    private API api;

    public Inventory(API api) {
        this.api = api;
    }
    // @@@@@@@
	
    // WARNING: Untested code
    
    /** Holds the amount of willows we have cut */
    private int willowsCut = 0;
    /** Holds the last inventory that was compared */
    private Item[] lastInv;
    
    /**
     * Simple getter
     * @return the number of willows cut
     */
    public int getWillowsCut() {
        return willowsCut;
    }
    
    /**
     * Compares your last inventory with the current inventory.
     */
    public void compareItems() {
        if (lastInv == null) {
            lastInv = api.getInventory().getItems();
            return; // It will be the same, no need to check
        }
        
        String item = "Willow logs";
        Item[] currInv = getInventory().getItems();
        for (int i = 0; i < 28; i++) {
            // Check for the same thing
            if ((currInv[i] == null && lastInv == null)
                    || currInv[i].getName().equals(lastInv[i].getName()))
                continue; // Its the same, continue
            
            if (currInv[i] != null) {
                // We have an item when we didn't
                if (currInv[i].getName().equals(item))
                    willowsCut++; // It was a willow log, ++
            } else {
                // We don't have an item when we did
                if (lastInv[i].getName().equals(item))
                    willowsCut--; // It was a willow log, --
            }
        }
        lastInv = currInv; // Update the inv
    }
    
    /**
     * Run this when the lastInv needs refreshing, aka after banking
     */
    public void resetItems() {
        lastInv = api.getInventory().getItems();
    }
}

If you want to get inventory in your Inventory class, simply do "api.getInventory()".

 

how do i call it from the main class it wont let me do it... getting NUlled or error

 

i did 

Inventory inventory = new Inventory();
or
Inventory inventory = new Inventory(null);

I will not spoonfeed you anymore. Learn some java instead of depending on the forum.

Edited by Woody

Keep in mind that for a simple script you don't have to and probably shouldn't create additional classes, it will only complicate things.

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.