Tom Posted March 6, 2015 Share Posted March 6, 2015 Due to the current inbuilt methods being a bit too "botlike", i decided to have a crack and tried to code my own, but introducing common human errors. Here is what I have: package com.ggplugins.osFisher; import java.util.ArrayList; import org.osbot.rs07.api.model.Item; import org.osbot.rs07.script.MethodProvider; import org.osbot.rs07.script.Script; public class Powerfish{ private Script instance; public Powerfish(Script instance){ this.instance = instance; } public void clearInventory(ArrayList<Item> safelist) throws InterruptedException{ for(Item i : instance.inventory.getItems()){ if(!safelist.contains(i)){ switch(MethodProvider.random(0, 200)){ case 25: instance.inventory.interact("Examine", i.getName()); MethodProvider.sleep(MethodProvider.random(300,600)); instance.inventory.drop(i.getName()); break; case 50: instance.inventory.interact("Use", i.getName()); MethodProvider.sleep(MethodProvider.random(300,600)); //Deselect item instance.inventory.drop(i.getName()); break; default: instance.inventory.drop(i.getName()); break; } MethodProvider.sleep(MethodProvider.random(350,750)); } } } } So what happens is, occasionally it will skip items, then it will jump back to them a few drops later, and once it gets down to the last 8 items in the inventory it decides to throw a null pointer on instance.inventory.drop(i.getName()); In the default case. So instead of staring at it for another 2 hours, I decided another pair of eyes might just be what I need so I've posted it here. Any help is appreciated, thanks. Quote Link to comment Share on other sites More sharing options...
Novak Posted March 6, 2015 Share Posted March 6, 2015 (edited) private void dropAllExcept(String... names) throws InterruptedException { for (int i = 0; i < 28; i++) { Item item = sI.inventory.getItemInSlot(i); if (item != null) { boolean drop = true; for (String name : names) { if (item.getName().equals(name)) { drop = false; break; } } if (drop) { if(sI.getInventory().interact(i, "Drop")) { MethodProvider.sleep(MethodProvider.gRandom(50, 25)); } else continue; } } } } Edited March 6, 2015 by Novak Quote Link to comment Share on other sites More sharing options...
Tom Posted March 6, 2015 Author Share Posted March 6, 2015 private void dropAllExcept(String... names) throws InterruptedException { for (int i = 0; i < 28; i++) { Item item = sI.inventory.getItemInSlot(i); if (item != null) { boolean drop = true; for (String name : names) { if (item.getName().equals(name)) { drop = false; break; } } if (drop) { if(sI.getInventory().interact(i, "Drop")) { MethodProvider.sleep(MethodProvider.gRandom(50, 25)); } else continue; } } } } This isn't quite the solution I'm looking for, but I will try the use of using inventory slot numbers rather than looping through the items in the inventory. That should help isolate my problem with items being dropped twice. Thanks! Quote Link to comment Share on other sites More sharing options...
Novak Posted March 6, 2015 Share Posted March 6, 2015 This isn't quite the solution I'm looking for, but I will try the use of using inventory slot numbers rather than looping through the items in the inventory. That should help isolate my problem with items being dropped twice. Thanks! all you have to do is c+p your switch statement for dropping under the if(drop) Quote Link to comment Share on other sites More sharing options...
Tom Posted March 6, 2015 Author Share Posted March 6, 2015 (edited) all you have to do is c+p your switch statement for dropping under the if(drop) Yeah i've pretty much adjusted it now to work with my switch. Testing it now, will post back. @Novak works like a charm mate, thanks Now ive only gotta fix deselecting, which seems to be bugged Edited March 6, 2015 by Mykindos Quote Link to comment Share on other sites More sharing options...