Jump to content

Need help creating a new dropping method


Tom

Recommended Posts

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.

Link to comment
Share on other sites


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
Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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