Jump to content

stuck on getInventory.....


Mocro

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

 

  • Like 1
Link to comment
Share on other sites

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{
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

 

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.

Link to comment
Share on other sites

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;
    }
Link to comment
Share on other sites

 

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...