Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Need changes but some methods for those who can understand it


    Sin

    Recommended Posts

    import java.util.Optional;
    import java.util.function.Predicate;
    
    public class Target<T> {
        private T target;
        private Searcher<T> searcher;
        private Predicate<T> validity;
    
        public Target(Predicate<T> validity, Searcher<T> searcher) {
            this.validity = validity;
            this.searcher = searcher;
        }
    
        public T get() {
            return this.target;
        }
    
        public void set(T target) {
            this.target = target;
        }
    
        public boolean valid() {
            return this.valid(this.validity);
        }
    
        public boolean valid(Predicate validity) {
            if(validity.test(this.target)) {
                return true;
            } else {
                this.target = null;
                return false;
            }
        }
    
        public boolean find() {
            Optional optional = this.searcher.search();
            if(optional.isPresent()) {
                this.target = (T)optional.get();
                return true;
            } else {
                return false;
            }
        }
    }
    
    import java.util.Comparator;
    import java.util.Optional;
    import java.util.function.Predicate;
    /** you will need to import the DreamBot API for the following and change thier respected variables (this is from another script client i used)
    import Entity;
    import Item;
    import NPC;
    import Player;
    **/
    
    
    public interface Searcher<T> { //some different API but will need changing
        Optional<T> search();
    
        static Searcher<NPC> closestNPC(BasicScript bs, EntityDefinition definition) {
            return () -> {
                return bs.getNPCStream().filter(definition).min(new Comparator<NPC>() {
                    public int compare(NPC a, NPC  {
                        return bs.getMap().distance(a.getPosition()) - bs.getMap().distance(b.getPosition());
                    }
                });
            };
        }
    
        static Searcher closestObject(BasicScript bs, EntityDefinition definition) {
            return () -> {
                return bs.getObjectStream().filter(definition).min(new Comparator<Entity>() {
                    public int compare(Entity a, Entity  {
                        return bs.getMap().distance(a.getPosition()) - bs.getMap().distance(b.getPosition());
                    }
                });
            };
        }
    
        static Searcher closestGroundItem(BasicScript bs, EntityDefinition definition) {
            return () -> {
                return bs.getGroundItemStream().filter(definition).min(new Comparator<Entity>() {
                    public int compare(Entity a, Entity  {
                        return bs.getMap().distance(a.getPosition()) - bs.getMap().distance(b.getPosition());
                    }
                });
            };
        }
    
        static Searcher<Player> anyPlayer(BasicScript bs, Predicate<Player> predicate) {
            return () -> {
                return bs.getPlayerStream().filter(predicate).findAny();
            };
        }
    
        static Searcher<Item> anyInventoryItem(BasicScript bs, Predicate<Item> predicate) {
            return () -> {
                return bs.getInventoryStream().filter(predicate).findAny();
            };
        }
    }
    

    I have more stuff to add but I have to go

     

     

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.