Jump to content

how to place a sleep when smelting?


Recommended Posts

Posted (edited)

i'm trying to smelt gold amulets for free crafting exp but the script will not sleep when smelting

here is the portion so far

i know 10 seconds isn't enough to craft 27 amulets but it's relooping after like 2 amulets which is like 4 seconds

case MAKEAMULETS:
			getWalking().webWalk(new Position[] {furnaceposition});
			if(getWidgets().isVisible(446, 32))
			{
				getWidgets().interact(446,32,"Make-X");
				sleep(random(300,500));
				if(getWidgets().isVisible(162, 33))
				{
					getKeyboard().typeString("27", true);
				}
				new ConditionalSleep(10000)
	            {					
					@Override
					public boolean condition() throws InterruptedException 
					{
						return !myPlayer().isAnimating();
					}
				}.sleep();
			}
			else
			{
				Entity furnace = objects.closest("Furnace");
				getInventory().interact("Use", "Gold bar");
				sleep(random(200,300));
				furnace.interact("Use");
			}
			break;
Edited by justanotherkid
Posted (edited)
while(myPlayer().isAnimating())
{
     sleep(500);
}

should work, idk if its clean though

 

with ur conditional sleep it will wait for the remaining of the 10seconds if you're done smelting

 

no, that didn't work either but there is a workaround i used to

 

return !getInventory().contains("gold bars") || getDialogue().inDialogue(); // the dialogue part is for when it levels up crafting

Edited by justanotherkid
Posted

no, that didn't work either but there is a workaround i used to

 

return !getInventory().contains("gold bars") || getDialogue().inDialogue(); // the dialogue part is for when it levels up crafting

when im cooking fish, i use the while loop to check if i still have raw fish.  when it levels up  i check on the level-up widget, not indialoge, but i guess it both works

Posted (edited)

EDIT: The following eliminates the issue of sleeping while proceeding with an action, as well as eliminating the issue of animations occurring only for a short period of time.

 

When crafting you expect an experience gain every few seconds, let's use this to build a predetermined time in the future which we can check our previous crafting experience with our current crafting experience.

 

We simply cache our crafting experience every 'check' before we are going to gain any new experience, every check, we get the current system time and add 4 - 6 seconds (the timeout essentially) to get our time for the next 'check'.

 

In pseudo code the following would be it's own method:


IF bar count = 0 THEN
RETURN false
END IF

IF CurrentTime > LastCheckedTime + timeout THEN
   IF CurrentCraftingXP > PreviousCraftingXP THEN
    PreviousCraftingXP = CurrentCraftingXP 
    LastCheckedTime = CurrentTime
   
    RETURN TRUE
    
    ELSE
    
    RETURN FALSE
    END IF
ELSE
RETURN TRUE
END IF
Edited by Final
  • Like 1
Posted
while(getInventory().contains("Gold bar")
{
    sleep(500);
}

 

I wouldn't use this. Just because the user has a gold bar doesn't mean that he's smelting, something such as a level up or unwanted interaction could disrupt this, furthermore it's a while loop and there's clear reasons of why not to use a while loop within a script (a while loop).

Posted

I wouldn't use this. Just because the user has a gold bar doesn't mean that he's smelting, something such as a level up or unwanted interaction could disrupt this, furthermore it's a while loop and there's clear reasons of why not to use a while loop within a script (a while loop).

Why r u stalking me?

Posted (edited)

 

i'm trying to smelt gold amulets for free crafting exp but the script will not sleep when smelting

here is the portion so far

i know 10 seconds isn't enough to craft 27 amulets but it's relooping after like 2 amulets which is like 4 seconds

case MAKEAMULETS:
			getWalking().webWalk(new Position[] {furnaceposition});
			if(getWidgets().isVisible(446, 32))
			{
				getWidgets().interact(446,32,"Make-X");
				sleep(random(300,500));
				if(getWidgets().isVisible(162, 33))
				{
					getKeyboard().typeString("27", true);
				}
				new ConditionalSleep(10000)
	            {					
					@Override
					public boolean condition() throws InterruptedException 
					{
						return !myPlayer().isAnimating();
					}
				}.sleep();
			}
			else
			{
				Entity furnace = objects.closest("Furnace");
				getInventory().interact("Use", "Gold bar");
				sleep(random(200,300));
				furnace.interact("Use");
			}
			break;

 

 

Easiest way imo is just to do a long sleep, and check if you still have gold bars / have leveled up:

if(getKeyboard().typeString("27")){
    new ConditionalSleep(100_000){					
        @Override
        public boolean condition() throws InterruptedException {
            return !getInventory().contains("Gold bar") || getDialouges().isPendingContinuation();
        }
    }.sleep();
}
Edited by Explv
  • Like 1

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...