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
  • Basic Construction


    Aeglen

    Recommended Posts

    The main logic of the script is below:

    package nodes;
    
    import base.Main;
    import base.Utils;
    import org.dreambot.api.methods.container.impl.Inventory;
    import org.dreambot.api.methods.dialogues.Dialogues;
    import org.dreambot.api.methods.interactive.GameObjects;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.methods.skills.Skills;
    import org.dreambot.api.methods.widget.Widgets;
    import org.dreambot.api.script.ScriptManager;
    import org.dreambot.api.script.TaskNode;
    import org.dreambot.api.wrappers.interactive.GameObject;
    
    public class Construction extends TaskNode {
    
        private enum Plank {
            NORMAL_NOTED(961), OAK_NOTED(8779), NORMAL_ITEM(960), OAK_ITEM(8778);
            private final int id;
            Plank(final int x) {
                id = x;
            }
        }
    
        private enum Furniture {
            OAK_LARDER("Oak larder",33,15403,"Kitchen",8,"Larder"),
            CARVED_OAK_TABLE("Carved oak table",31,15298,"Dining room",6,"Oak table"),
            OAK_DINING_TABLE("Oak dining table",22,15298,"Dining room",4,"Oak table"),
            WOODEN_LARDER("Wooden larder",9,15403,"Kitchen",8,"Larder"),
            WOODEN_BOOKCASE("Wooden bookcase",4,4521,"Parlour",4,"Bookcase"),
            CRUDE_WOODEN_CHAIR("Crude wooden chair",1,4515,"Parlour",2,"Chair");
            private final String name;
            private final int level;
            private final int spot_id;
            private final String room;
            private final int planks;
            private final String built_name;
            Furniture(String name, int level, int spot_id, String room, int planks, String built_name) {
                this.name = name;
                this.level = level;
                this.spot_id = spot_id;
                this.room = room;
                this.planks = planks;
                this.built_name = built_name;
            }
        }
    
        @Override
        public int priority() { //higher = more important
            return 0;
        }
    
        @Override
        public boolean accept() { //when to do it
            return Main.task.equals("Construction");
        }
    
        @Override
        public int execute() {
            //decide what to build
            int level = Skills.getRealLevel(Skill.CONSTRUCTION);
            int best_level = -1;
            Furniture thing_to_build = Furniture.CRUDE_WOODEN_CHAIR;
            for (Furniture f: Furniture.values()) {
                if (f.level > best_level) {
                    best_level = level;
                    thing_to_build = f;
                }
            }
            log("Want to build " + thing_to_build.name);
            //decide what planks it needs
            int plank_id;
            if (thing_to_build.level < 15) {
                plank_id = Plank.NORMAL_NOTED.id;
            } else {
                plank_id = Plank.OAK_NOTED.id;
                if (Inventory.contains(Plank.NORMAL_ITEM.id) && getLocalPlayer().getX() < 3000) {
                    log("Dropping old planks"); //can't do this in the house, hence < 3000
                    Inventory.dropAll(Plank.NORMAL_ITEM.id);
                    sleep(Utils.delay(Main.standard_delay));
                }
            }
            //check for out of resources
            if (Inventory.count(plank_id) < 28 && !Inventory.isFull()) {
                log("Low on planks!");
                return -1;
            }
            if (getLocalPlayer().getX() < 3000 && Inventory.contains(plank_id) && !Inventory.isFull()) {
                log("Un-noting planks");
                //check if upstairs by mistake
                if (getLocalPlayer().getZ() == 1) {
                    Utils.moveFloor(0);
                }
                Utils.walkTo(new Tile(2949, 3213));
                int plank_count = Inventory.count(plank_id);
                Utils.useOnNPC(plank_id, "Phials");
                sleepUntil(()-> Dialogues.inDialogue(), Utils.delay(3000));
                Utils.solveDialogue(3);
                int temp = plank_id;
                sleepUntil(()-> Inventory.count(temp) < plank_count, Utils.delay(2000));
                return Utils.delay(Main.standard_delay);
            }
            //go to house
            if (getLocalPlayer().getX() < 3000) {
                log("Entering house");
                //check if house advertisement opened by mistake
                if (Utils.getCloseButton() != null) {
                    Utils.getCloseButton().interact();
                }
                Utils.interactOBJ("Portal","Build mode",null);
                sleep(Utils.delay(1000));
                sleepUntil(() -> getLocalPlayer().getX() > 3000,20000);
                Utils.waitUntilNotLoading();
                sleepUntil(() -> !Utils.checkForCutscene(),20000);
                return Utils.delay(Main.standard_delay);
            }
            //check for building spot
            if (getLocalPlayer().getX() > 3000) {
                log("Looking for building spot");
                int spot_id = thing_to_build.spot_id;
                GameObject building_spot_temp = GameObjects.closest(spot_id);
                if (building_spot_temp == null) {
                    //build the room
                    String desired_room = thing_to_build.room;
                    log("Building new " + desired_room);
                    Tile portal = GameObjects.closest("Portal").getTile();
                    Tile target_tile = new Tile(portal.getX(),portal.getY()+4); //the door to the north
                    Utils.walkTo(target_tile,true); //it's important to be in the portal room for this
                    GameObject hotspot = GameObjects.closest("Door hotspot");
                    hotspot.interact("Build");
                    sleepUntil(()-> Utils.getWidgetWithAction(desired_room)!=null || Dialogues.inDialogue(), Utils.delay(10000));
                    if (Dialogues.inDialogue()) {
                        Utils.solveDialogue(1); //remove existing room
                        sleep(Utils.delay(1000));
                        Utils.waitUntilNotLoading();
                        sleepUntil(() -> !Utils.checkForCutscene(),20000);
                    }
                    sleep(Utils.delay(Main.standard_delay));
                    if (Utils.getWidgetWithAction(desired_room) != null) {
                        Utils.getWidgetWithAction(desired_room).interact();
                        sleepUntil(() -> Dialogues.inDialogue(), Utils.delay(10000));
                        Utils.solveDialogue(3);
                        sleep(Utils.delay(1000));
                        Utils.waitUntilNotLoading();
                        sleepUntil(() -> !Utils.checkForCutscene(),20000);
                    }
                    return Utils.delay(Main.standard_delay);
                } else {
                    if (thing_to_build.name.equals("Wooden bookcase")) {
                        Utils.walkTo(new Tile(building_spot_temp.getTile().getX() - 1, building_spot_temp.getTile().getY())); //db collision seems buggy in POH
                    } else {
                        Utils.walkTo(new Tile(building_spot_temp.getTile().getX(), building_spot_temp.getTile().getY() - 1)); //db collision seems buggy in POH
                    }
                    int plank_id_2;
                    if (thing_to_build.level < 15) {
                        plank_id_2 = Plank.NORMAL_ITEM.id;
                    } else {
                        plank_id_2 = Plank.OAK_ITEM.id;
                    }
                    while(Inventory.count(plank_id_2) >= thing_to_build.planks) { //has resources
                        if (!ScriptManager.getScriptManager().isRunning()) {
                            return -1;
                        }
                        log("Building " + thing_to_build.name);
                        final GameObject building_spot = GameObjects.closest(spot_id);
                        if (building_spot != null) {
                            building_spot.interact();
                            final String temp = thing_to_build.name;
                            sleepUntil(() -> Widgets.getWidgetChildrenContainingText(temp).size() > 0, Utils.delay(10000));
                            sleep(Utils.delay(Main.standard_delay));
                            Widgets.getWidgetChildrenContainingText(temp).get(0).interact();
                            sleepUntil(() -> !building_spot.exists(), Utils.delay(10000));
                            sleepUntil(() -> !getLocalPlayer().isAnimating(), Utils.delay(6000));
                        }
                        if (building_spot == null || !building_spot.exists()) {
                            log("Removing " + thing_to_build.built_name);
                            GameObject thing = GameObjects.closest(thing_to_build.built_name);
                            if (thing == null) {
                                return Utils.delay(Main.standard_delay);
                            } else {
                                thing.interact("Remove");
                                sleepUntil(()-> Dialogues.inDialogue(), Utils.delay(10000));
                                Utils.solveDialogue(1);
                                sleepUntil(() -> getLocalPlayer().isAnimating(), Utils.delay(2000));
                                sleepUntil(() -> !getLocalPlayer().isAnimating(), Utils.delay(6000));
                                sleep(Main.standard_delay);
                            }
                        }
                    }
                    //leave house
                    log("Leaving house");
                    GameObject portal = GameObjects.closest("Portal");
                    Utils.walkTo(portal.getTile());
                    portal.interact();
                    sleep(Utils.delay(1000));
                    sleepUntil(() -> getLocalPlayer().getX() < 3000,20000);
                    Utils.waitUntilNotLoading();
                    sleepUntil(() -> !Utils.checkForCutscene(),20000);
                    return Utils.delay(Main.standard_delay);
                }
            }
            return Utils.delay(Main.standard_delay);
        }
    }

     

    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.