July 21, 201510 yr Some code I toyed around with yesterday to test out a few things: Core: import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.api.model.RS2Object; import org.osbot.rs07.script.Script; import org.osbot.rs07.script.ScriptManifest; import java.util.Comparator; import java.util.function.Predicate; import java.util.stream.Stream; @ScriptManifest(author = "Botre", info = "", logo = "", name = "Experiment", version = 0.0) public class ExperimentalScript extends Script { private ScriptClock clock = new ScriptClock(1.6); private String name = "Man"; private String action = "Pickpocket"; private Predicate<NPC> validityPredicate = o -> o != null && o.exists() && o.getName().equals(name) && o.hasAction(action) && getMap().canReach(o.getPosition()); private Comparator<Entity> distanceComparator = EntityComparator.create(this, EntityComparator.Type.DISTANCE_FROM_PLAYER); private Target<NPC> target = new Target<>(validityPredicate, () -> getNpcStream().filter(validityPredicate).min(distanceComparator)); @Override public int onLoop() throws InterruptedException { if (target.valid() || target.find()) { target.get().interact(action); } return clock.tick(); } private Stream<RS2Object> getObjectStream() { return getObjects().getAll().stream(); } private Stream<NPC> getNpcStream() { return getNpcs().getAll().stream(); } } Target: import java.util.Optional; import java.util.function.Predicate; /** * Created by Bjorn on 19/07/2015. */ public class Target<T> { private T target; private TargetSearcher<T> searcher; private Predicate<T> validity; public Target(Predicate<T> validity, TargetSearcher<T> searcher) { this.validity = validity; this.searcher = searcher; } /** * @return The current target. */ public T get() { return target; } /** * @return Whether the current target is valid. */ public boolean valid() { if (validity.test(target)) { return true; } else { target = null; return false; } } /** * Searches for and assigns a new target by making a call to the search() method. * * @return Whether a new target was find. */ public boolean find() { Optional<T> optional = searcher.search(); if (optional.isPresent()) { target = optional.get(); return true; } else { return false; } } } Target searcher: import java.util.Optional; /** * Created by Bjorn on 21/07/2015. */ public interface TargetSearcher<T> { /** * Searches for a new target. * * @return The new target. */ Optional<T> search(); } Script clock: /** * Created by Bjorn on 19/07/2015. */ public class ScriptClock { private double loopsPerSecond ; private int millisecondsPerLoop; private long systemMilliseconds; private long deltaMilliseconds; private int sleepMilliseconds; public ScriptClock(double loopsPerSecond) { this.loopsPerSecond = loopsPerSecond; millisecondsPerLoop = (int) ((1 / loopsPerSecond) * 1000); systemMilliseconds = System.currentTimeMillis(); } public int tick() { deltaMilliseconds = System.currentTimeMillis() - systemMilliseconds; systemMilliseconds = System.currentTimeMillis(); sleepMilliseconds = (int) (millisecondsPerLoop - deltaMilliseconds); return sleepMilliseconds > 0 ? sleepMilliseconds : 0; } } Entity comparator: import org.osbot.rs07.api.model.Entity; import org.osbot.rs07.api.model.NPC; import org.osbot.rs07.script.MethodProvider; import java.util.Comparator; /** * Created by Bjorn on 20/07/2015. */ public final class EntityComparator { public enum Type { DISTANCE_FROM_PLAYER, } public static Comparator<Entity> create(MethodProvider mp, Type type) { switch(type) { case DISTANCE_FROM_PLAYER: return (a, b) -> mp.getMap().distance(a.getPosition()) - mp.getMap().distance(b.getPosition()); } return null; } }
July 21, 201510 yr this gets you 1-50 thieving in 1 night if its fast enough. use this for your DT lads
July 21, 201510 yr this gets you 1-50 thieving in 1 night if its fast enough. use this for your DT lads sounds good
July 21, 201510 yr You could have uploaded this to github so people can download a zip instead of copy and pasting every file. Just a suggestion. :p
July 21, 201510 yr You could have uploaded this to github so people can download a zip instead of copy and pasting every file. Just a suggestion. They getting a free script source they can spend the effort copying it
July 21, 201510 yr Author You could have uploaded this to github so people can download a zip instead of copy and pasting every file. Just a suggestion. Meh I might when my noob-friendly framework is ready :x
July 21, 201510 yr You're running me out of business here :'( Looks good though! Remember that map.distance() is deprecated though
July 21, 201510 yr Author You're running me out of business here :'( Looks good though! Remember that map.distance() is deprecated though Sowyyy, tbh I don't think many people even know how to compile this so dw :p I think it was just getMap().distance(Entity) that was deprecated, getMap().distance(Entity.getPosition()); hasn't been touched (yn).
July 22, 201510 yr Sowyyy, tbh I don't think many people even know how to compile this so dw I think it was just getMap().distance(Entity) that was deprecated, getMap().distance(Entity.getPosition()); hasn't been touched (yn). I have no idea lol, I've never touched those functions :p better be safe than sorry!
Create an account or sign in to comment