Jump to content

dreameo

Scripter II
  • Posts

    410
  • Joined

  • Last visited

  • Days Won

    2
  • Feedback

    100%

Posts posted by dreameo

  1. Here's a guide on how to make an inventory listener. I don't think the bot offers it in the API, but you will see how simple it can be. The architecture of the following classes can be made better but this is how I've done it on my first try.

    (There wont be much explanation)

    Main Class:

    -Implements Observer -> Interface we made

    -Exchanges context since we extend MethodProvider

    -Sets the observer as the Main class

    Spoiler
    
    import org.osbot.rs07.api.model.Item;
    import org.osbot.rs07.script.Script;
    import org.osbot.rs07.script.ScriptManifest;
    
    @ScriptManifest(version = 1, logo = "", author = "Dream", info = "", name = "Listener")
    public class Main extends Script implements Observer {
    
        private InventoryListener inventoryListener = InventoryListener.getInstance();
    
        @Override
        public void onStart() throws InterruptedException {
            inventoryListener.exchangeContext(getBot());
            inventoryListener.setObserver(this);
            new Thread(inventoryListener).start();
        }
    
        @Override
        public int onLoop() throws InterruptedException {
            return 256;
        }
    
        @Override
        public void inventoryListener(Item item, boolean gained) {
            log("Item: " + item.getName() + " Gained or Lost: " + gained);
        }
    
        @Override
        public void onExit() throws InterruptedException {
            inventoryListener.setRun(false);
        }
    }

     

     

    InventoryListener Class

    Note: I think the code would break if you try running it while logged off. An easy fix would be to set the run state once we are logged in.

    -Implements runnable, this is a seperate thread that runs to check the status of our inventory

    -Really simple strategy, we check our current items with a cached set of items. If there are any differences, we know that we either gained/lost an item. Whenever those cases occur, we notify our observer.

    -The thread runs ever 50 ms = checks for new items 20 times per second.

    Spoiler
    
    import org.osbot.rs07.api.model.Item;
    import org.osbot.rs07.script.MethodProvider;
    
    public class InventoryListener extends MethodProvider implements Runnable {
    
        private Observer observer;
        private volatile boolean run;
        private boolean initiated;
        private Item[] items;
        private static InventoryListener inventoryListener = new InventoryListener();
    
        private InventoryListener(){
            run = true;
            initiated = false;
        }
    
        public static InventoryListener getInstance(){
            return inventoryListener;
        }
    
        public void setObserver(Observer observer){
            this.observer = observer;
        }
    
        public void setRun(boolean run){
            this.run = run;
        }
    
        @Override
        public void run() {
            while (run){
                if(!initiated){
                    items = getInventory().getItems();
                    initiated = true;
                } else {
                    Item[] newItems = getInventory().getItems();
                    Item newItem, oldItem;
    
                    for(int i = 0; i < 27; i++) {
                        oldItem = items[i];
                        newItem = newItems[i];
    
                        if(newItem == null && oldItem != null){
                            observer.inventoryListener(oldItem, false);
                        } else if(oldItem == null &&  newItem != null){
                            observer.inventoryListener(newItem, true);
                        }
                    }
                    items = newItems;
                }
    
                try {
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }

     

     

    Observer - Interface

    Spoiler
    
    import org.osbot.rs07.api.model.Item;
    
    public interface Observer {
        void inventoryListener(Item item, boolean gained);
    }

     

     

     

    • Like 4
  2. 2 minutes ago, IDontEB said:

    The examples not wrong. 

    boolean expressions are expressed as 0s or 1s and in the example they had 
     

    
    int x =55;
    if (x<50 & x>0)

    so it'd be if (0 & 1) which (0 & 1) evaluate to 0 which is false.

    you're right about it not being appropriate though.

    zz read it as the author saying the first expression is false and second is true.

  3. 1 minute ago, jca said:

    That’s still defining an area... it’s not an issue. Just if there was an option with regions it feels better to use. But maybe it’s not possible. 

    You made it sound like it's an issue when you said the area is large. Which I said, you don't need to actually define an area.. you just need 2 coordinates.

    You're doing the same with with a region that you would with an area. Idk why you're hard stuck on regions.

  4. 5 minutes ago, jca said:

    Yeah... well that’s one option. 

    The area I need to check is huge (the size of the region, basically 104x104). My logic is if it’s already defined as a region and I could check that then it makes more sense then defining a massive area. 

    But if there’s not really a better way then areas will have to do. 

    You don't need to define the area. Since it's big just get the bottom left and top right coordinates and that's all you need to check and see if you're within an area.

  5. 5 minutes ago, HexMurder said:

    I appreciate all the comments, and thanks for the information about anti-ban. But, I'm still looking for a well written source to study here ?

    tldr, there really isn't any.

  6. The general consensus here is that anti-ban is dumb and it shoudn't be implemented.

    Conventional thinking should always be challenged though. I don't really agree with the consensus but the majority do have a point in the sense that anti-ban has not been effective. It's very possible to create something to counteract the bans. It just not has been done right so far.

    When it comes down to it, all bot interacts generalize to a certain behavior. Regardless of what strategy you may do to make the bot perform like a human, it still does human things in a bot like way.  GL coming up with some idea.

    • Like 1
  7. 16 hours ago, FrostBug said:

    Use == for primitives and constants
    Use .equals() for everything else

    GrandExchange.Status is an enum, and enum values are always constant (even if they for some reason are mutable), so here you should use '=='

    Those strings are literals actually; which are constant. '==' is valid :xboge:

    I think the main reason why what Alek wrote is valid is because both those string objects point to the same object. Compiler is smart enough to see that "abc" is being used twice and instead of making 2 separate objects, it makes both variables point to one "abc" object.

    (90%)

  8. 28 minutes ago, sorag13 said:

    Cmon! Finish and release it :D

    Anyways this works great. Good xp rates, I dont know how safe to use it is, but I think people use it for 50 Firemaking.

    Yeah lol... I never play but whenever I do and i'm at GE, I see someone using the bot. Obvious to me, idk if obvious to others.

  9. 5 minutes ago, Glaciation96 said:

    I'm not intentionally looking for old posts, just digging through all the resources that I can find, then commenting to test my own understanding of java/botting lol. Also does my code not make sense or not work? So long as it's not the latter I'm happy ?

     

    He also asked for "any items" which I guess could translate to all or just some of the items, to me anyway. Nice Explv's Map btw, been using that loads. 

    no it doesn't make any sense lol.

×
×
  • Create New...