Dick Posted June 9, 2014 Posted June 9, 2014 Hey guys, I was hoping that somebody is able to provide me/us of a snippet that codes for a fast dropping method. Quicker that the regular one. Im sorry, im a hopeless coder and want to setup a script that works properly without breaking..
Botre Posted June 9, 2014 Posted June 9, 2014 public void dropAll(Script script, ArrayList<String> exceptionList) throws InterruptedException { Item[] i = script.inventory.getItems(); for (Item inventoryItem : i) { if ((exceptionList == null || !exceptionList.contains(inventoryItem.getName())) && Arrays.asList(inventoryItem.getDefinition().getActions()).contains("Drop")) { int s = script.inventory.getSlot(inventoryItem); Timer failsafe = new Timer(); while (script.inventory.getSlot(inventoryItem) == s && failsafe.getElapsed() < 5000L) { inventoryItem.interact("Drop"); Script.sleep(Script.random(600, 1200)); } } if (script.inventory.isItemSelected()) { script.inventory.deselectItem(); } } } Not sure if it's faster considering it relies on the API's interaction method.
Dick Posted June 9, 2014 Author Posted June 9, 2014 public void dropAll(Script script, ArrayList<String> exceptionList) throws InterruptedException { Item[] i = script.inventory.getItems(); for (Item inventoryItem : i) { if ((exceptionList == null || !exceptionList.contains(inventoryItem.getName())) && Arrays.asList(inventoryItem.getDefinition().getActions()).contains("Drop")) { int s = script.inventory.getSlot(inventoryItem); Timer failsafe = new Timer(); while (script.inventory.getSlot(inventoryItem) == s && failsafe.getElapsed() < 5000L) { inventoryItem.interact("Drop"); Script.sleep(Script.random(600, 1200)); } } if (script.inventory.isItemSelected()) { script.inventory.deselectItem(); } } } Not sure if it's faster considering it relies on the API's interaction method. Good looking man, Thanks
Botre Posted June 9, 2014 Posted June 9, 2014 Just revisited the class in question: public static void wholeInventory(Script script, ArrayList<String> exceptionList, boolean dropCondition) throws InterruptedException { if (dropCondition) { Item[] i = script.inventory.getItems(); for (Item inventoryItem : i) { if (!dropCondition) { break; } if ((exceptionList == null || !exceptionList.contains(inventoryItem.getName())) && Arrays.asList(inventoryItem.getDefinition().getActions()).contains("Drop")) { int s = script.inventory.getSlot(inventoryItem); Timer failsafe = new Timer(); while (script.inventory.getSlot(inventoryItem) == s && failsafe.getElapsed() < 5000L) { inventoryItem.interact("Drop"); Script.sleep(Script.random(600, 1200)); } } if (script.inventory.isItemSelected()) { script.inventory.deselectItem(); } } } } public static void inventoryItems(Script script, ArrayList<String> itemList, boolean dropCondition) throws InterruptedException { if (dropCondition) { Item[] i = script.inventory.getItems(); for (Item inventoryItem : i) { if (!dropCondition) { break; } if (itemList != null) { if (itemList.contains(inventoryItem.getName()) && Arrays.asList(inventoryItem.getDefinition().getActions()).contains("Drop")) { int s = script.inventory.getSlot(inventoryItem); Timer failsafe = new Timer(); while (script.inventory.getSlot(inventoryItem) == s && failsafe.getElapsed() < 5000L) { inventoryItem.interact("Drop"); Script.sleep(Script.random(600, 1200)); } } } if (script.inventory.isItemSelected()) { script.inventory.deselectItem(); } } } }
Nitrousek Posted June 9, 2014 Posted June 9, 2014 (edited) You can also change the itemName to drop, to exception if you'd prefer that. Should be fairly easy to change. public void dropAll(String itemName) throws InterruptedException { Inventory inv = client.getInventory(); if (inv.contains(itemName)) { for (Item item : inv.getItems()) { if (item.getName().equalsIgnoreCase(itemName)) { MouseDestination slotDestination = new RectangleDestination( inv.getDestinationForSlot(inv .getSlotForName(itemName))); if (client .moveMouseTo(slotDestination, false, false, false)) { client.clickMouse(true); int i = findOption("Drop"); if (i > 0) { if (client.moveMouseTo(new RectangleDestination( client.getMenuX(), client.getMenuY() + 5 + (i * 15), client.getMenuWidth() - 3, 6), false, true, false)) { sleep(random(150, 300)); } } } } } } } public int findOption(String option) { int i = 0; Iterator<Option> it1 = client.getMenu().iterator(); while (it1.hasNext()) { ++i; Option temp = it1.next(); if (temp.action.equalsIgnoreCase(option)) { return i; } } return 0; } Edited June 9, 2014 by Nitrousek
Pseudo Posted June 10, 2014 Posted June 10, 2014 (edited) private void dropAll() throws InterruptedException { for (int slot = 0; slot < 28; slot++) { Item item = client.getInventory().getItems()[slot]; if (item == null) continue; client.getInventory().interactWithSlot(slot, "Drop"); } } Edited June 10, 2014 by Pseudo
Nitrousek Posted June 10, 2014 Posted June 10, 2014 How would this code differ from osbot 2 Don't ask. Try.