LoudPacks Posted August 12, 2015 Share Posted August 12, 2015 (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 August 12, 2015 by Chris1665 Quote Link to comment Share on other sites More sharing options...
Bobrocket Posted August 12, 2015 Share Posted August 12, 2015 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 Quote Link to comment Share on other sites More sharing options...
Apaec Posted August 12, 2015 Share Posted August 12, 2015 or a rather crude way of doing it but a method that works just fine: Area area = new Area(0,0,0,0); //area around stall, defined and initi at top RS2Object stall = objects.closest(area,"Stall name"); if (stall != null && stall.exists()) { stall.interact("Steal-from"); //blah } Quote Link to comment Share on other sites More sharing options...
Botre Posted August 12, 2015 Share Posted August 12, 2015 (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 August 12, 2015 by Botre Quote Link to comment Share on other sites More sharing options...