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
  • Help with state script


    Pengu

    Recommended Posts

    First try on making a script with states

    Its a progressive wc up to willows.
    i tested on a acc with lvl 20 wc, so it should use the oak area.
    It walks to the correct area but dosent do anything when its there
    I tried to fill the inventory with logs and oak logs to check if it dropped them correctly, wich it did.

     

    Here is the code:

    public class Main extends AbstractScript{
        Area treeArea = new Area(3158, 3418, 3172, 3399);
        Area oakArea = new Area(3271, 3438, 3287, 3411);
        Area willowArea = new Area(2970, 3192, 2972, 3190);
    
        public void onStart(){
            log("Starting script");
        }
        private enum State {
            TREE, OAK, WILLOW, DROP, WAIT
        }
    
        private State getState(){
            if (getInventory().isFull())
                return State.DROP;
            if (getSkills().getRealLevel(Skill.WOODCUTTING) < 15)
                return State.TREE;
            if (getSkills().getRealLevel(Skill.WOODCUTTING) < 30)
                return State.OAK;
            if (getSkills().getRealLevel(Skill.WOODCUTTING) < 60)
                return State.WILLOW;
            return State.WAIT;
        }
        @Override
        public int onLoop() {
            switch (getState()){
                case WAIT:
                    if (getLocalPlayer().isAnimating()){
                        int random = Calculations.random(1, 5);
                        if (random == 1){
                            if (getMouse().isMouseInScreen()){
                                getMouse().moveMouseOutsideScreen();
                            }
                        }
                    }
                    break;
                case DROP:
                    log("Dropping all logs");
                    if (getInventory().isFull()){
                        getInventory().dropAll("Logs", "Oak logs", "Willow logs");
                    }
                    sleep(100, 500);
                    break;
                case TREE:
                    if (!treeArea.contains(getLocalPlayer())){
                        getWalking().walk(treeArea.getCenter().getRandomizedTile());
                    }else {
                        if (!getLocalPlayer().isAnimating()){
                            GameObject tree = getGameObjects().closest("Tree");
                            if (tree != null){
                                tree.interact("Chop down");
                            }
                        }
                    }
                    break;
                case OAK:
                    if (!oakArea.contains(getLocalPlayer())){
                        getWalking().walk(oakArea.getCenter().getRandomizedTile());
                    }else {
                        if (!getLocalPlayer().isAnimating()){
                            GameObject oak = getGameObjects().closest("Oak tree");
                            if (oak != null){
                                oak.interact("Chop down");
                            }
                        }
                    }
                    break;
                case WILLOW:
                    if (!willowArea.contains(getLocalPlayer())){
                        getWalking().walk(willowArea.getCenter().getRandomizedTile());
                    }else {
                        if (!getLocalPlayer().isAnimating()){
                            GameObject willow = getGameObjects().closest("Willow tree");
                            if (willow != null){
                                willow.interact("Chop down");
                            }
                        }
                    }
                    break;
            }
            return 1000;
        }
    }
    
    
    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.