Jump to content

Thieving Help (1st Script)


Recommended Posts

Posted (edited)

Ok so I'm new to scripting, I have some understanding of Java and have been able to at least start a working script. I've been reading through the API but I can't figure out how to do this. There are several silk stalls. I want to theive from the same one, rather than running to the next closest stall when the first one is all out. 

 

I am using: Entity stall = objects.closest(11729);

 

How can I make it so it will only do one stall specifically, rather than running across to the second stall? I tried using the stall ID but I realized all stalls have the same ID so I was still running everywhere. I was thinking using some sort of filter with the coords but idk how

 

 

Also, I'm trying to use combat().getFighting() to register when a guard attacks because I have a kill state where I want to kill the guard, register he's dead, and then move onto the steal state etc. Any tips?

Edited by Chris1665
Posted
Entity stall = getObjects().closest("Silk stall");
Position p = stall.getPosition();
//thieve Stall
//on other loops, do this
Entity stall = (Entity) getObjects().closest(new Filter<RS2Object>() {
    @Override
    public boolean match(RS2Object rs) {
        return (rs.getPosition().equals(p) && rs.getName().contains("stall"));
    }
});

if (stall != null && !stall.getName().equals("Market stall")) {
    //thieve stall
}

The idea is that you do not want to thieve "Market stall" but rather the silk stall/tea stall/whatever stall, so you save the position when you first locate it to search in that position again :)

Posted (edited)

(Not written in an IDE, whatever)

/*
Global variables.
*/

private Optional<Entity> stall = Optional.empty();

private Position position = new Position(0, 0, 0); // Set this to the position of your stall.

private Predicate<Entity> predicate = p -> p != null && p.exists() && p.getName().equals("Silk stall") && p.getPosition().equals(position); 

private Comparator<Entity> comparator = new Comparator<Entity>() {
            @Override
            public int compare(Entity a, Entity b) {
                return bs.getMap().distance(a.getPosition()) - bs.getMap().distance(b.getPosition());
            }
        }

/*
Loop.
*/

@Override
public int onLoop() {
if(!stall.isPresent() || !predicate.test(stall.get()) {
stall = getObjects().getAll().stream().filter(predicate).min(comparator);
}
else {
stall.get().interact("Steal-from");
}
return 1337;
}
Edited by Botre

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...