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
  • Looking for help with my smithing script


    Xtra

    Recommended Posts

    Hey guys, 

    I'm having an issue with my script, and I'm looking for a point in the right direction.

    The problem is that it will click too many times, and this is something correct logic or a sleepUntil will usually fix.

    But I believe that the problem lies with the widget ID, as I have been messing around with a ton of different ways to code this and it will still click twice before making the cannonballs.

     

    So what I want to happen:

    Clicks the furnace

    Waits for the "Make all" cannonballs widget, then clicks it

    Waits for the bars to be used up

    Get more bars and repeat.


    What actually happens:
    Clicks the furnace, waits until the sleep that I put in there is over

    Clicks the furnace again 1ms before clicking the widget

    Runs as normal.

     

    The log shows that it reaches "if (makeAll != null){"  but then starts the script over, and by the time it reaches that if statement, it will work and actually click it.

     

    Here's the code:

    package nodes;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.script.TaskNode;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.widgets.WidgetChild;
    
    public class SmithNode extends TaskNode {
    
       private Area furnaceArea = new Area(3109, 3498, 3109, 3499);
       private GameObject furnace;
       private WidgetChild makeAll;
    
        @Override
        public boolean accept() {
            return getInventory().contains("Steel bar")
                    && getInventory().contains("Ammo mould");
        }
    
        @Override
        public int execute() {
            furnace = getGameObjects().closest("Furnace");
            makeAll = getWidgets().getWidgetChild(270, 14);
    
            // Logs to help debugging
            log("CB_1");
    
            // If the player is in the furnace area
            if(furnaceArea.contains(getLocalPlayer())){
    
                log("CB_2");
    
                // If the furnace is not null, interact with it
                if (furnace != null){
    
                    log("CB_3");
                    furnace.interact();
    
                    // If a sleep is not present, it will spam click for a second or two
                    sleep(Calculations.random(2000, 3000));
    
                    /* Here is I believe the problem lies.
                    *  because it seems to see the widget as null when it isn't.
                    *  I used the debug and widget tool to find the ID. I have also tried other IDs.
                    *  Perhaps this is a part of the redesign's functionality, to help prevent bots?
                    */
                    if (makeAll != null){
    
                        log("CB_4");
    
                        // Interact with the widgetChild
                        makeAll.interact();
    
                        // This makes the bot wait until a level-up dialogue appears
                        // and waits for it to finish smelting
                        sleepUntil(() -> getDialogues().continueDialogue()
                                || !getInventory().contains("Steel bar"), 180000);
                    }
                }
    
                // If not at the furnace area, walk there
            } else if (getWalking().shouldWalk(Calculations.random(2, 5))){
    
                log("CB_6");
                getWalking().walk(furnaceArea.getCenter());
    
            } return 300;
        }
    }

     

    Link to comment
    Share on other sites

    3 minutes ago, wettofu said:

    if (makeAll.interact()){

     sleep

    Thanks for the suggestion

    It will still click the furnace a few times before clicking the makeAll widget

    Link to comment
    Share on other sites

    11 minutes ago, wettofu said:

    i dont really understand but couldnt you just make it 

    if make all !=null 

    else  interact furnace

    My saviour <3  that worked

    I need to get used to this type of logic, sometimes it's too easy to fall to overly linear logic.

    Have my upvote

     

    Edit: I spoke too soon, it does the same thing in a different order, but with the same outcome
    https://gyazo.com/a73a251d96dc5edc8fbe1254aaa7aa21

    Clicks, then clicks again just before "making all" cannonballs

    Link to comment
    Share on other sites

    1 minute ago, Pandemic said:

    You should get the widget right before you need it, not before a few seconds of sleeping. A null widget will not turn into a non-null one by itself :)

    Very true, however I did this because it would spamclick 4-5 times, and with the sleep it clicks only once. Neither are favourable though

    Link to comment
    Share on other sites

    4 minutes ago, Xtra said:

    Very true, however I did this because it would spamclick 4-5 times, and with the sleep it clicks only once. Neither are favourable though

    What I mean is, you should call:

    makeAll = getWidgets().getWidgetChild(270, 14);

    right before you check if it's null, after the sleep :)

    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.