Jump to content

Need help creating a new dropping method


Recommended Posts

Posted

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.

Posted (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 by Novak
Posted
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!

Posted

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)

Posted (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 by Mykindos

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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