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

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


public class Inventory {
	
    // 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 = 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 = getInventory().getItems();
    }
}

cant find the getInventory() try to import nothing works.. suggestion of eclipse nothing...

getInventory is a method defined in MethodProvider. The Script class inherits from MethodProvider, and that's why you can use it from classes that extend Script.

This class does not have any definition of that method, so you cannot use it here.

 

To use it, you should have a reference to the Script instance.

  • Author

getInventory is a method defined in MethodProvider. The Script class inherits from MethodProvider, and that's why you can use it from classes that extend Script.

This class does not have any definition of that method, so you cannot use it here.

 

To use it, you should have a reference to the Script instance.

is it possible to use it with myPlayer method?

is it possible to use it with myPlayer method?

 

myPlayer() is also defined in MethodProvider.

Since your Inventory class here does not extend anything, there are no methods beyond the ones you've defined in the class yourself.

 

You have to either pass a reference to your Script instance, and call the MethodProvider methods thru that; or create a new instance of whatever API classes you need, and exchange contexts with them.

 

  • Author

myPlayer() is also defined in MethodProvider.

Since your Inventory class here does not extend anything, there are no methods beyond the ones you've defined in the class yourself.

 

You have to either pass a reference to your Script instance, and call the MethodProvider methods thru that; or create a new instance of whatever API classes you need, and exchange contexts with them.

 

awsome thanks works now :)

public class Inventory extends MethodProvider{

 

awsome thanks works now smile.png

public class Inventory extends MethodProvider{

 

That's going to give you a NullPointerException, though. You have to do an exchangeContext first (MethodProvider#exchangeContext).

 

  • Author

That's going to give you a NullPointerException, though. You have to do an exchangeContext first (MethodProvider#exchangeContext).

 

where do i put it inside my class or main?

where do i put it inside my class or main?

 

Either. As long as you're calling exchangeContext on your Inventory instance

 

  • Author

Either. As long as you're calling exchangeContext on your Inventory instance

 

i have no clue how this works.... 

	  	Inv invent = new Inv();
	  	Inv.this.exchangeContext(bot);
	  	invent.compareItems();
	  	banked = invent.getWillowsCut();
    private MethodProvider api;

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

    }

did it in my class still null class called Inv en main class called main

Edited by Mocro

Because its is a new class and it extends method provider I say you create a constructor and exchange context with it in there. And also have either the bot or script as an argument of the constructor.

In your inv class in the constructor just do

ExchangeContext (script.getBot ())

ExchangeContext (bot instance)

In your main class that extends scriot, you must initialize your inv class and pass the argument to it.

Edited by Joseph

 

i have no clue how this works.... 

	  	Inv invent = new Inv();
	  	Inv.this.exchangeContext(bot);
	  	invent.compareItems();
	  	banked = invent.getWillowsCut();
    private MethodProvider api;

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

    }

did it in my class still null class called Inv en main class called main

 

Read the guide and do it step by step.

  • Author

man im really stuck here im trying my best to understand it just wont work just getting nulled... and im trying to code in objectoriented and in classes ... 

 

if i put everything in main class it works fine.... but then its not objectoriented...

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


public class Inventory {
	
    // 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 = 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 = getInventory().getItems();
    }
}

cant find the getInventory() try to import nothing works.. suggestion of eclipse nothing...

 

 

try

inside your Inventory class

private Script scriptInstance;
    public Inventory(Script scriptInstance){
        this.scriptInstance = scriptInstance;
    }
  • Author

 

try

inside your Inventory class

private Script scriptInstance;
    public Inventory(Script scriptInstance){
        this.scriptInstance = scriptInstance;
    }

Thank you il try that its so weird you cant like call methode from that class objects are working for me now but i want to make classes im using public voids now in main class....

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.