Jump to content

Custom Inventory dropping method :/


Recommended Posts

Posted

For OSB2

public class DropItems {

	private final Script script;
	@SuppressWarnings("unused")
	private final Bot b;

	public DropItems(final Script script, final Bot b) {
		this.script = script;
		this.b = b;
	}

	public void dropAllExcept(ArrayList<String> blacklist)
			throws InterruptedException {
		Item[] i = script.inventory.getItems();
		for (Item inventoryItem : i) {
			if (!blacklist.contains(inventoryItem.getName())
					&& Arrays
							.asList(inventoryItem.getDefinition().getActions())
							.contains("Drop")) {
				int s = script.inventory.getSlot(inventoryItem);
				Timer failsafe = new Timer(0L);
				while (script.inventory.getSlot(inventoryItem) == s
						&& failsafe.getElapsed() < 5000L) {
					inventoryItem.interact("Drop");
					Script.sleep(750);
				}
			}
			if (script.inventory.isItemSelected()) {
				script.inventory.deselectItem();
			}
		}
	}

}
Posted (edited)

 

For OSB2

public class DropItems {

	private final Script script;
	@SuppressWarnings("unused")
	private final Bot b;

	public DropItems(final Script script, final Bot b) {
		this.script = script;
		this.b = b;
	}

	public void dropAllExcept(ArrayList<String> blacklist)
			throws InterruptedException {
		Item[] i = script.inventory.getItems();
		for (Item inventoryItem : i) {
			if (!blacklist.contains(inventoryItem.getName())
					&& Arrays
							.asList(inventoryItem.getDefinition().getActions())
							.contains("Drop")) {
				int s = script.inventory.getSlot(inventoryItem);
				Timer failsafe = new Timer(0L);
				while (script.inventory.getSlot(inventoryItem) == s
						&& failsafe.getElapsed() < 5000L) {
					inventoryItem.interact("Drop");
					Script.sleep(750);
				}
			}
			if (script.inventory.isItemSelected()) {
				script.inventory.deselectItem();
			}
		}
	}

}

 

Why did you use an Array List in the parameter, it will be easier and look better with an array of strings "String...blacklist". 

 

example:

	public void dropAllExcept(String...blacklist) throws InterruptedException {
		List<String> list = new ArrayList<String>();
		
		for (String s: blacklist)	{
			if (s!=null)
				list.add(s);
		}
		
		//then you could do the rest in here using the arrayList
	}

initialize it as a List then convert it into an array list

List<String> list = new ArrayList<String>();

Edited by josedpay
Posted

 

Why did you use an Array List in the parameter, it will be easier and look better with an array of strings "String...blacklist". 

 

example:

	public void dropAllExcept(String...blacklist) throws InterruptedException {
		List<String> list = new ArrayList<String>();
		
		for (String s: blacklist)	{
			if (s!=null)
				list.add(s);
		}
		
		//then you could do the rest in here using the arrayList
	}

initialize it as a List then convert it into an array list

List<String> list = new ArrayList<String>();

 

The fixed length of simple arrays is the reason why I don't use them much anymore except for constants (my blacklists are usually dynamic, this allows me to have one smart flexible blacklist instead of multiple constant ones). I prefer the collection interface because it offers much more flexibility imo.

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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