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
  • Try asking for help in the chatbox
  • [Scripting support] How do I make my program utilise multiple Java Classes, and how will an if(x.interact"y") help prevent missclicks?


    Before
     Share

    Recommended Posts

    That title though.

     

    I'm planning on making a little bit bigger of a script, that will use some of my other scripts inside. I could merge it all into once source code, but isn't there a way to have a script use multiple classes? Like there is a way, I know that but.. oh well you get what I'm saying.

     

    Also, I've had some help with people and they recommend when I'm using the "interact" method I put an if-statement around it, because it will return false if it missclicks; how does that help me make the bot more reliable with the interact method? (Right now sometimes for whatever reason, it clicks the entity on the minimap instead of clicking it on the screen)

    Link to comment
    Share on other sites

    I'm no java expert, but I'm pretty sure you use setters and getters or w/e. From what I can remember when I was scripting years back for a different bot, I was told you use setters and getters and you can use it across multiple classes. 

     

    http://www.dreamincode.net/forums/topic/86439-getters-and-setters-and-using-multiple-classes/

     

    That title though.

     

    I'm planning on making a little bit bigger of a script, that will use some of my other scripts inside. I could merge it all into once source code, but isn't there a way to have a script use multiple classes? Like there is a way, I know that but.. oh well you get what I'm saying.

     

    Also, I've had some help with people and they recommend when I'm using the "interact" method I put an if-statement around it, because it will return false if it missclicks; how does that help me make the bot more reliable with the interact method? (Right now sometimes for whatever reason, it clicks the entity on the minimap instead of clicking it on the screen)

     

    #pleasedon'tkillmeifIgotthiswrong.

    Edited by Ayaka
    Link to comment
    Share on other sites

    put this in your Main class

    private ClasName classname;
    
    
    public void onStart() {
    
    
    classname = new ClasName(this);
    
    
    }

    Then to make a new class

     

    public class ClasName {
    AbstractScript s;
    
    
    public ClasName (AbstractScript ctx) {
    this.s = ctx;
     }
    }
    Link to comment
    Share on other sites

    public class chop {
        
        private AbstractScript ctx;
        private GameObject tree;
    
        public chop(AbstractScript ctx) {
            this.ctx = ctx;
        }
     
        public boolean choppingIsFun() {
            tree = ctx.getGameObjects().closest(f -> f != null && f.getName().contains("tree"));
            if (tree != null && tree.interact("Chop down")) {
                ctx.sleep(randNum(300, 400));
                ctx.sleepUntil(() -> !tree.exists(), randNum(12000, 8000));
                return true;
            } else {
                return false;
            }
        }
    }
     
    public class Scripto extends AbstractScript {
        private chop chopper;
     
        @Override
        public void onStart() {
            chopper = new chop(this);
        }
     
     
        @Override
        public int onLoop() {
            if (chopper.choppingIsFun()) {
                log("ok we did some choppin");
            }
        }
     
    }
     
    
     

     

    Hope that helps ;o

     

    edit: Edited to display what Hope is referring to

    Link to comment
    Share on other sites

    public class chop {
        
        private AbstractScript ctx;
        private GameObject tree;
    
        public chop(AbstractScript ctx) {
            this.ctx = ctx;
        }
     
        public boolean choppingIsFun() {
            tree = ctx.getGameObjects().closest(f -> f != null && f.getName().contains("tree"));
            if (tree != null && tree.interact("Chop down")) {
                ctx.sleep(randNum(300, 400));
                ctx.sleepUntil(() -> !tree.exists(), randNum(12000, 8000));
                return true;
            } else {
                return false;
            }
        }
    }
     
    public class Scripto extends AbstractScript {
        private chop chopper;
     
        @Override
        public void onStart() {
            chopper = new chop(this);
        }
     
     
        @Override
        public int onLoop() {
            if (chopper.choppingIsFun()) {
                log("ok we did some choppin");
            }
        }
     
    }
     
    
     

     

    Hope that helps ;o

     

    edit: Edited to display what Hope is referring to

     

     

    I used

    classA = new ClassA();
    

    Where classA is in my main package, outside the main class.

     

    This will work too right?

    Link to comment
    Share on other sites

    Are you trying to have multiple scripts in the same project? Or just split your script up into nodes?

    Link to comment
    Share on other sites

    Putting an if around an x.interact("y") doesn't prevent misclicks, rather it tells you whether your first click was successful or not. The interact method returns a boolean depending on whether your client successfully completed the interaction. If you put x.interact("y") inside an if statement, you would be able to act differently depending on whether the interaction succeeded or failed. As hope mentioned earlier, it's convenient inside a sleepUntil condition.

    Link to comment
    Share on other sites

    The reason you use an if around interact is you don't want to test if you are doing something in a conditional sleep at f you never actually did it.

    Oh.. Hmm. 

     

    Yeah as I said one of my scripts had been acting weird (for some accounts only too, checked all the settings and shit). Dunno.

     

    (code)
     

     

    Hope that helps ;o

     

    edit: Edited to display what Hope is referring to

     

    So do I just have two Classes inside the same source file (like a superfunction) or are these separate in my package?

     

     

    put this in your Main class

    private ClasName classname;
    
    
    public void onStart() {
    
    
    classname = new ClasName(this);
    
    
    }

    Then to make a new class

     

    public class ClasName {
    AbstractScript s;
    
    
    public ClasName (AbstractScript ctx) {
    this.s = ctx;
     }
    }

     

    Okayy, I think I get this. I'll use it as reference <3

     

    Are you trying to have multiple scripts in the same project? Or just split your script up into nodes?

    Multiple scripts in the same project; like I already have a fishing script and a cooking one, so if I combine them into one script, can I just copy the class files or do I have to copy and paste the source as a function

     

    Putting an if around an x.interact("y") doesn't prevent misclicks, rather it tells you whether your first click was successful or not. The interact method returns a boolean depending on whether your client successfully completed the interaction. If you put x.interact("y") inside an if statement, you would be able to act differently depending on whether the interaction succeeded or failed. As hope mentioned earlier, it's convenient inside a sleepUntil condition.

    Ohh, that will help for a few things. Awesoem!

    Link to comment
    Share on other sites

    A script is just a class file w/ the manifest at the top, that is ALL the bot looks for.

     

    So you can have as many classes as you want w/ those manifest at the top, and those would be separate scripts inside the bot client.

     

    Now of course with these classes, you can create instances of other classes inside of them, like shown above, the client doesn't look for those, it only needs the main class with the manifest to run the script.

    Link to comment
    Share on other sites

     Share

    ×
    ×
    • 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.