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 to determine whether a player is smithing/smelting?


    LoremIpsum213

    Recommended Posts

    At the moment i use this function to determine whether the player is smelting bars:

        private boolean isSmelting()
        {
            return Players.getLocal().isAnimating() || (Players.getLocal().getAnimation() == Players.getLocal().getStandAnimation() && canSmelt());
        }

    where canSmelt() determines whether there is enough ores in the inventory.


    However, this is not fool proof as sometimes, the player model just stands still for a brief moment before adding more ore in the furnace.

    In the execute function i have an if statement that uses the isSmelting() function to determine whether we should interact with the furnace, \

    if we are already smelting i don't want it to click on the furnace again.

    I have got everything else working for my smithing script, except for this annoying issue. If someone knows a better way, let me know.

     

     

    Edited by LoremIpsum213
    Link to comment
    Share on other sites

    I had this happen when I was doing a cooking script, essentially you make sure that you started animating, and then you sleep until there's no more raw resources in your inventory (ores in this case), or until you're in dialogue.

    Link to comment
    Share on other sites

    39 minutes ago, una_maquina said:

    I had this happen when I was doing a cooking script, essentially you make sure that you started animating, and then you sleep until there's no more raw resources in your inventory (ores in this case), or until you're in dialogue.

    Thats what i do, although iam not sure if iam using the sleepWhile() function correctly:

     

            // check whether we are in area
            if(Area.getArea().contains(Players.getLocal().getTile()))
            {
                GameObject furnace = Area.GetInteractionObject();
                // if player is on tile in front of furnace and we can smelt, and interact
                if(furnace.interact())
                {
                    sleep(500, 3000);
                    
                    WidgetChild selectionbox = Widgets.getWidgetChild(270, widgetMap.get(Bar.getID()));
                    if (selectionbox != null && selectionbox.isVisible()) { //widget exists
                        selectionbox.interact();
                    }
                    sleepWhile(() -> canSmelt(), 30000, 5000);
                }
            }

     

    Link to comment
    Share on other sites

    1 hour ago, LoremIpsum213 said:

    Thats what i do, although iam not sure if iam using the sleepWhile() function correctly:

     

            // check whether we are in area
            if(Area.getArea().contains(Players.getLocal().getTile()))
            {
                GameObject furnace = Area.GetInteractionObject();
                // if player is on tile in front of furnace and we can smelt, and interact
                if(furnace.interact())
                {
                    sleep(500, 3000);
                    
                    WidgetChild selectionbox = Widgets.getWidgetChild(270, widgetMap.get(Bar.getID()));
                    if (selectionbox != null && selectionbox.isVisible()) { //widget exists
                        selectionbox.interact();
                    }
                    sleepWhile(() -> canSmelt(), 30000, 5000);
                }
            }

     

    Oh, you're passing 3 arguments to sleepWhile, you can only pass two, wrap the "30000, 5000" into Calculations.random(30000,50000), otherwise check out your canSmelt logic, it might be the problem.

    sleepWhile(() -> canSmelt(), Calculations.random(30000, 50000));
    Link to comment
    Share on other sites

    Oh, maybe you can pass 3 arguments to sleepWhile and it automatically randomizes the sleep times (didn't know that), but the fact that you've put 30000 and 5000 as the other number, might be the problem, because it's 30 secs and 5 secs.

    Link to comment
    Share on other sites

    1 hour ago, una_maquina said:

    Oh, maybe you can pass 3 arguments to sleepWhile and it automatically randomizes the sleep times (didn't know that), but the fact that you've put 30000 and 5000 as the other number, might be the problem, because it's 30 secs and 5 secs.

    30000, 5000 just means that he'll have a timeout for 30 seconds and it will poll every 5 seconds if i understood the documentation correctly

    Link to comment
    Share on other sites

    1 minute ago, mrchrismas said:

    30000, 5000 just means that he'll have a timeout for 30 seconds and it will poll every 5 seconds if i understood the documentation correctly

    I see, that makes sense, still though fixed sleeping times like that is unadvisable, better to always have random sleep times with Calculation.random().

    As for why he's having that bug is probably due to something being wrong in the canSmelt() method.

    Link to comment
    Share on other sites

    In the end i solved it as following:

     

    	//get furnace object in Area (= special class that uses Dreambot Area API)
            GameObject furnace = Area.GetInteractionObject();
            // check if we are within reach, otherwise, keep walking to destination
            if(furnace != null && furnace.distance() < 10)
            {
                // if furnace was clicked
                if(furnace.interact())
                {
                  	// succesfully clicked on furnace, now wait until widget menu is opened
                    sleepUntil(() -> Widgets.isOpen(), 10000, 500);
                    WidgetChild selectionbox = Widgets.getWidgetChild(270, widgetMap.get(Bar.getID()));
                    if (selectionbox != null && selectionbox.isVisible() && selectionbox.interact()) {
                        //wait until done smelting or when a lvl-up dialogue pops up
                        sleepUntil(() -> !canSmelt() || Dialogues.canContinue(), 60000, 5000);
                    }
                }
            }

     

    I guess this code can be repeated for many different activities within the game. Let me know if i did something else kinda weird.

     

    Edited by LoremIpsum213
    Link to comment
    Share on other sites

    3 hours ago, una_maquina said:

    I see, that makes sense, still though fixed sleeping times like that is unadvisable, better to always have random sleep times with Calculation.random().

    As for why he's having that bug is probably due to something being wrong in the canSmelt() method.

    the fixed sleeping time, is just the timeout, so that means it will always exit after 60 seconds in my latest code change. But 99.9% of time, everything has been smelted by then and the canSmelt function will return false (which is checked every 5 seconds). Perhaps I should randomize that a little bit. so i don't always walk away exactly at the same time.

    Link to comment
    Share on other sites

    Look into using the `reset` condition of the sleepUntil method. This way you can sleepUntil your inventory contains no more resources (raw fish, ores etc) with a low timeout (5 seconds for example), but reset the timeout if you are ever animating.

     

    Something like this could work:

    static int SMELTING_ANIMATION_ID = 899
      
      
    
    Player me = Players.getLocal();
    Sleep.sleepUntil(me::isStandingStill, () -> me.getAnimation() == SMELTING_ANIMATION_ID, 10000, 150, 3);

     

    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.