Woody Posted October 4, 2015 Share Posted October 4, 2015 (edited) 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 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 October 4, 2015 by Woody Quote Link to comment Share on other sites More sharing options...
Mocro Posted October 6, 2015 Author Share Posted October 6, 2015 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 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); Quote Link to comment Share on other sites More sharing options...
Woody Posted October 6, 2015 Share Posted October 6, 2015 (edited) I will not spoonfeed you anymore. Learn some java instead of depending on the forum. Edited October 6, 2015 by Woody Quote Link to comment Share on other sites More sharing options...
Flamezzz Posted October 6, 2015 Share Posted October 6, 2015 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. Quote Link to comment Share on other sites More sharing options...