Jump to content

Thieving Help (1st Script)


LoudPacks

Recommended Posts

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

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 :)

Link to comment
Share on other sites

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