October 19, 20196 yr Two drop methods but, both of them are able to be reversed. You can also add item name(s) that you don't want to be dropped. Example: Spoiler private String[] items = new String[]{"Small fishing net", "Raw shrimps"}; private Drop drop = new Drop(); @Override public void onStart() throws InterruptedException { drop.exchangeContext(bot); } @Override public int onLoop() throws InterruptedException { // Boolean will reverse the order in which things are dropped // You can use an Array of strings, individual strings, or no strings if (drop.shiftClickDropAllExcept(false, items)) { log("Drop Completed!"); } if (drop.shiftClickDropAllDownToUpExcept(true, "Small fishing net", "Raw shrimps")) { log("Drop Completed!"); } if (drop.shiftClickDropAllDownToUpExcept(false)) { log("Drop Completed!"); } if (drop.shiftClickDropAllExcept(true)) { log("Drop Completed!"); } return random(800, 3000); } Code: Spoiler import org.osbot.rs07.api.ui.RS2Widget; import org.osbot.rs07.script.MethodProvider; import org.osbot.rs07.utility.ConditionalSleep; import java.awt.*; import java.util.ArrayList; public class Drop extends MethodProvider { public boolean shiftClickDropAllExcept(boolean reverse, String... itemNames) { if (!isShiftClickActivated()) { log("Shift Dropping Not Enabled!"); return false; } if (!isInventoryOpen()) { if (!openInventory()) { log("Unable To Open Inventory!"); return false; } } int[] itemSlots = (reverse) ? reverseArray(getOccupiedItemSlotsStandardDrop(itemNames)) : getOccupiedItemSlotsStandardDrop(itemNames); if (itemSlots.length > 0) { getKeyboard().pressKey(16); for (int i = 0, j; i < itemSlots.length; i++) { j = itemSlots[i]; drop(j); } getKeyboard().releaseKey(16); } return getInventory().isEmptyExcept(itemNames); } public boolean shiftClickDropAllDownToUpExcept(boolean reverse, String... itemNames) { if (!isShiftClickActivated()) { log("Shift Dropping Not Enabled!"); return false; } if (!isInventoryOpen()) { if (!openInventory()) { log("Unable To Open Inventory!"); return false; } } int[] itemSlots = (reverse) ? reverseArray(getOccupiedItemSlotsDownToUp(itemNames)) : getOccupiedItemSlotsDownToUp(itemNames); if (itemSlots.length > 0) { getKeyboard().pressKey(16); for (int i = 0, j; i < itemSlots.length; i++) { j = itemSlots[i]; drop(j); } getKeyboard().releaseKey(16); } return getInventory().isEmptyExcept(itemNames); } private int[] reverseArray(int[] arrayToReverse) { int[] tempArray = new int[arrayToReverse.length]; for (int i = tempArray.length - 1, j = 0; i >= 0; i--, j++) { tempArray[j] = arrayToReverse[i]; } return tempArray; } private int[] convertToPrimitiveArrayFromList(ArrayList<Integer> integers) { int[] itemSlotIds = new int[integers.size()]; for (int i = 0; i < itemSlotIds.length; i++) { itemSlotIds[i] = integers.get(i); } return itemSlotIds; } private int[] getOccupiedItemSlotsDownToUp(String... itemNames) { ArrayList<Integer> tempItemSlotIds = new ArrayList<>(); for (int i = 0, j = 1; i < 28; ) { if (j == 1) { if (inventorySlotHasUnWantedItem(i, itemNames)) { tempItemSlotIds.add(i); } if (i != 24) { i += 4; } else { j++; i = 25; } } else if (j == 2) { if (inventorySlotHasUnWantedItem(i, itemNames)) { tempItemSlotIds.add(i); } if (i != 1) { i -= 4; } else { j++; i = 2; } } else if (j == 3) { if (inventorySlotHasUnWantedItem(i, itemNames)) { tempItemSlotIds.add(i); } if (i != 26) { i += 4; } else { j++; i = 27; } } else if (j == 4) { if (inventorySlotHasUnWantedItem(i, itemNames)) { tempItemSlotIds.add(i); } if (i != 3) { i -= 4; } else { j++; i = 28; } } } return convertToPrimitiveArrayFromList(tempItemSlotIds); } private int[] getOccupiedItemSlotsStandardDrop(String... itemNames) { ArrayList<Integer> tempItemSlotIds = new ArrayList<>(); for (int i = 0; i < 28; i++) { if (inventorySlotHasUnWantedItem(i, itemNames)) { tempItemSlotIds.add(i); } } return convertToPrimitiveArrayFromList(tempItemSlotIds); } private void drop(int slotId) { Rectangle boundingBox = getInventory().getSlotBoundingBox(slotId); int x = boundingBox.x + random(1, 25); int y = boundingBox.y + random(1, 25); getMouse().move(x, y); getMouse().click(false); } private boolean isShiftClickActivated() { return getSettings().isShiftDropActive(); } private boolean inventorySlotHasUnWantedItem(int slotId, String... itemNames) { return getInventory().getItemInSlot(slotId) != null && !getInventory().getItemInSlot(slotId).nameContains(itemNames); } private boolean isInventoryOpen() { return getWidgets().get(548, 51).getSpriteIndex1() != -1; } private boolean openInventory() { RS2Widget inventoryButton = getWidgets().get(548, 51); if (inventoryButton != null && inventoryButton.interact("Inventory")) { new ConditionalSleep(3000, 100) { @Override public boolean condition() throws InterruptedException { return isInventoryOpen(); } }.sleep(); } return isInventoryOpen(); } } Edited October 19, 20196 yr by BravoTaco
October 19, 20196 yr Some thoughts if your interested: Should extend MethodProvider and exchange context Reverse should not actually reverse the item positioning, you should just be starting at the end (i = 27 for ex) "script.getKeyboard().releaseKey(16)" shouldn't be exposed in the wild. Why can't it be a member of drop()?
October 19, 20196 yr Author 3 hours ago, dreameo said: Some thoughts if your interested: Should extend MethodProvider and exchange context Reverse should not actually reverse the item positioning, you should just be starting at the end (i = 27 for ex) "script.getKeyboard().releaseKey(16)" shouldn't be exposed in the wild. Why can't it be a member of drop()? I thought the exchangeContext method was deprecated. Was this changed recently? Updated the code with this. I thought about that when i was writing this, but that would require two different for loops in each drop method, one that adds to i and another that subtracts from it. Or set i depending on the boolean value to 0 or the length of the array and than update it inside the for loop. I felt that it was easier to read if i just reversed the array. If i added the release key into drop() than it would release the key before the dropping is done. Edited October 19, 20196 yr by BravoTaco
October 19, 20196 yr 2 hours ago, BravoTaco said: I thought the exchangeContext method was deprecated. Was this changed recently? Updated the code with this. I thought about that when i was writing this, but that would require two different for loops in each drop method, one that adds to i and another that subtracts from it. Or set i depending on the boolean value to 0 or the length of the array and than update it inside the for loop. I felt that it was easier to read if i just reversed the array. If i added the release key into drop() than it would release the key before the dropping is done. it has always been deprecated but meant to be used. Minor either way - but you do 2 loops anyhow + extra work of having to reverse. Just noticed that whole method is shift dropping.
Create an account or sign in to comment