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
  • How do I approach multi-stage scripting?


    DullAchingLeg

    Recommended Posts

    I've made two scripts, one cooks and one combines two items. They're both basic and have a simple anti-ban pattern, but I feel like I need to have some framework because I imagine a bunch of if statements can get messy.  

    Currently, I have my script using a getState() method.

    private enum State {
            WITHDRAW, COMBINE, WAIT, DEPOSIT
        }
        private State getState() {
            if (Inventory.isEmpty())
                return State.WITHDRAW;
            if (Inventory.contains(firstItem) && Inventory.contains(secondItem))
                return State.COMBINE;
            if (!Inventory.contains(firstItem) && !Inventory.isFull())
                return State.DEPOSIT;
            return State.WAIT;
        }

    Currently, I have my script using a getState() method. Eventually, I'd like to combine my cooking script with my combine script. When I have multi-part scripts, how does one approach a larger, more complex script? Perhaps something like buying ingredients -> Combine ingredients -> Cook ingredients -> Bank. I can see this getting huge from something simple.

    Link to comment
    Share on other sites

    Quite simple really, just break it down into more scripts xD

    For instance, have a script that handles:
    - G.E (buying / selling) Static methods
    - Banking (depositing, withdrawing, equipping) Static methods
    - Cooking (will walk to closest range/fire or pre selected one, then withdraw best raw food in bank based on level) Initialized from GameManager and told to run the Task method in this script if the state is set to cooking.

    If the combining of ingredients is an aspect of cooking, then keep in in the Cooking class

    Most classes you'll want to just have static methods in it so it can be accessed easily from anywhere (Walking, AntiBan, Banking, NPC interactions (quest system stuff), G.E, etc)
    However, with multilayer systems I highly recommend having a single class that runs the entire bot, I call it the 'GameManager'.

    Your GameManager is a singleton that can be called from anywhere, and it also is when invokes the constructors for all other non static classes.
    It is very important to have a single class in charge of running everything, that way the logic and processes never get out of order in the thread.

    I personally use a second TimerTask thread to handle mouse/camera movements to emulate a real player being able to do more than 1 thing at a time, but be careful with multithreading as you can have some undesired results like the two threads fighting to do the same thing but with different values.

    You're going to want to change those states to be stronger ones: WITHDRAW, COMBINE, WAIT, DEPOSIT shouldn't be states.

    Your states should be stuff like: quest, cooking, mining, etc
    The WITHDRAW/DEPOSIT should be a static method within your Banking class, that returns a boolean, not a state, the COMBINE can be a method within the Cooking class that too returns boolean when done, the WAIT should be a static method within your AntiBan class.
    Also implementing sideStates are very useful for doing things like: makeFood, tutorialIsland (things that take priority over States, but won't change or stop it)

    I'd also advise having mini management classes, ex: QuestSystem
    That way you can simply set your State to quest and tell it to call QuestSystem.quest();

    Within there, the QuestSystem will determine which quest it needs/wants to do, and set its own state to that quest.

    You should be able to run a 1-50k line bot (mega complex ones) with a 500line GameManager if you do it right. I can testify this being true for both Unity Game Development and DreamBot as I do both and is a good habit to get into.
    Also to avoid too many lines / redundant coding, if there is ever a method more than 1 class uses, make a static version of it in a class that makes sense and then just call upon it.
    methods within classes are only if just that class uses it, or it needs to set private/local variables within that class it self, otherwise make it static and put it elsewhere for efficiency and cleanness. 

    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.