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
  • Simple Raw chicken cooker at Varrock east bank


    Deep Slayer

    Recommended Posts

    Here's a pretty simple cooking bot I made.

    Maybe it can help someone just starting out to see how script runs

    Don't use it extensively, I'm 99% sure you'll get banned if you use this in game as there's no antiban or randomness added to it via the script itself.

    Link to comment
    Share on other sites

    Posted (edited)
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.container.impl.bank.Bank;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.methods.interactive.Players;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.walking.impl.Walking;
    import org.dreambot.api.methods.widget.Widgets;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.utilities.Sleep;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.interactive.Player;
    
    
    @ScriptManifest(author = "Anyone",
            name = "Simple Raw chicken cooker",
            version = 1.0, description = "cooks raw chicken",
            category = Category.COOKING
    )
    
    
    
    public class CookingBot extends AbstractScript {
        public final String rawFood = "Raw chicken";
        Player myPlayer = Players.getLocal();
        Area cookingArea = new Area(3236, 3411, 3240, 3409);
    
        private State currentState;
    
        private enum State {
            COOK, WALK_TO_COOKING_RANGE, BANK_FOOD, DROP_BURNT, WITHDRAW_FOOD
        }
    
    
        @Override
        public void onStart() {
    
            currentState = State.WITHDRAW_FOOD;
        }
    
        @Override
        public int onLoop() {
            
    
            switch (currentState) {
                case WITHDRAW_FOOD:
                    log("WITHDRAW_FOOD:");
                    withdrawShrimp();
                    if(Inventory.contains(rawFood)){
                        currentState = State.WALK_TO_COOKING_RANGE;
                    }
                    break;
                case WALK_TO_COOKING_RANGE:
                    log("WALK_TO_COOKING_RANGE:");
                    walkToCookingRange();
                    if(cookingArea.contains(myPlayer)){
                        currentState = State.COOK;
                    }
                    break;
                case COOK:
                    log("COOK:");
                    cook();
                    if(!Inventory.contains(rawFood)){
                        currentState = State.DROP_BURNT;
                    }
                    break;
                case DROP_BURNT:
                    log("DROP_BURNT:");
                    dropBurnt();
                    if(!Inventory.contains("burnt ")){
                        currentState = State.BANK_FOOD;
                    }
                    break;
                case BANK_FOOD:
                    log("BANK_FOOD:");
                    bankFood();
                    if(Inventory.isEmpty()){
                        currentState = State.WITHDRAW_FOOD;
                    }
                    break;
    
            }
    
            return 600;
        }
    
        private void bankFood() {
            if (!Bank.isOpen()) {
                Bank.open();
            }
            if (Bank.isOpen()) {
                Bank.depositAllItems();
                Bank.close();
            }
        }
    
        private void dropBurnt() {
            if(Inventory.contains("Burnt chicken")){
                log("Inventory contains burnt...");
                Inventory.dropAll("Burnt chicken");
            }
    
        }
    
    
        private void cook() {
            if (Inventory.contains("Raw chicken")) {
                GameObject range = GameObjects.closest(gameObject -> gameObject != null && gameObject.getName().equals("Range"));
                if (range != null && range.interact("Cook")) {
                    Sleep.sleepUntil(() -> myPlayer.isAnimating(), Calculations.random(2000, 3000));
                   if(Inventory.contains("Cooked chicken")){
                    if (Widgets.getWidgetChild(270, 15) != null) { //if you have cooked chicken in inventory and go to cook, widget changes
                        Widgets.getWidgetChild(270, 15).interact();
                    }
                   }
                    else{
                        if (Widgets.getWidgetChild(270, 14) != null) { //widget without cooked chicken in inventory
                            Widgets.getWidgetChild(270, 14).interact();
                        }
    
                    }
                        sleep(2000,3000);
                        Sleep.sleepUntil(()->!myPlayer.isAnimating(), Calculations.random(60000, 70000));
    
                }
            }
        }
        
    
        private void walkToCookingRange () {
                if (!cookingArea.contains(myPlayer)) {
                    Walking.walk(cookingArea);
                    sleep(500,5000);
                }
            }
    
            private void withdrawShrimp () {
                if (!Bank.isOpen()) {
                    Bank.open();
                }
                if (Bank.isOpen()) {
                    if(!Inventory.isEmpty()){
                        Bank.depositAllItems();
                        sleep(500,1000);
                    }
                    Bank.withdrawAll(rawFood);
                    Bank.close();
                }
            }
    
            @Override
            public void onExit () {
    
            }
        }
    
    
    Edited by Deep Slayer
    Link to comment
    Share on other sites

    I think your code would be more readable if you used return conditions in your methods. For example, instead of,

    6 hours ago, Deep Slayer said:
    private void cook() {
            if (Inventory.contains("Raw chicken")) {
                GameObject range = GameObjects.closest(gameObject -> gameObject != null && gameObject.getName().equals("Range"));
    

    you could have,

    private void cook() {
            if (!Inventory.contains("Raw chicken")) { return; }
            GameObject range = GameObjects.closest(gameObject -> gameObject != null && gameObject.getName().equals("Range"));

    which would reduce the levels of indentation in your methods and make them easier to follow.

    Link to comment
    Share on other sites

    40 minutes ago, apnasus said:

    I think your code would be more readable if you used return conditions in your methods. For example, instead of,

    you could have,

    private void cook() {
            if (!Inventory.contains("Raw chicken")) { return; }
            GameObject range = GameObjects.closest(gameObject -> gameObject != null && gameObject.getName().equals("Range"));

    which would reduce the levels of indentation in your methods and make them easier to follow.

    (+ 1) I agree
    Not changing it to this would get flagged at code review stage in an enterprise environment.

    Furthermore you can increase the code quality by removing the magic numbers such as:
    getWidgetChild(270, 15) and sleep(500,1000)

    Imagine how hard it would be to maintain a large script if those widget numbers changed. At a minimum you could wrap the getWdigetChild in a method which describes the widget you are getting and reuse that. For the sleep put the 500,1000 into variables such as minSleep and maxSleep.

    Examples:
     

    int maxSleep = 1000;
    int minSleep = 500;
    
    private WidgetChild getCookWidget() {
      Widgets.getWidgetChild(270, 15);
    }
    
    private void exampleMethodWithSleep() {
      //code
      Sleep(minSleep, maxSleep);
      //code
    }

    Also if you find the need to add comments, generally in 90% of cases, your code isn't readable and therefore can be improved so you don't need comments.

    Link to comment
    Share on other sites

    thanks for the feedback, will consider the early return approach next time for readability. and use of naming variables instead of directly throwing numbers in there. hope u enjoyed the script

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • 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.