Jump to content

how to place a sleep when smelting?


justanotherkid

Recommended Posts

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
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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).

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

Nope.

 

If you really want to use a while loop, always have a backup so it doesn't get stuck in the loop.

obviously, but OP already has that as far as i know, he already has the logic for leveling up

 

 

 

@op this is how i have it

0ac9787689.png

Edited by The Hero of Time
Link to comment
Share on other sites

 

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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