Jump to content

[Help] Conditional Sleep


whipz

Recommended Posts

Hey guys, my conditional sleeps usually work however for ground items I seem to be having a little bit of problems;

this is my code for that part 

 

	GroundItem item = getGroundItems().closest("item");
		if (item == null) {
			log("item is null");
			if (!magic.isSpellSelected()) {
				log("Spell is not active, activating spell");
				magic.castSpell(Spells.NormalSpells.TELEKINETIC_GRAB);
			} else {
				log("item is null, spell is active moving mouse to predicted spot");
				hoverTile.hover(bot);
				sleep(random(500, 1500));
				new ConditionalSleep(5000) {

					@Override
					public boolean condition() throws InterruptedException {
						return item.exists();
					}
				}.sleep();

			}
		}

no matter what I do it always seems to return true even if its not there 

I have tried:

item != null; (this one waits until it times out then continues)

item.isVisiable();

item.isOnScreen();

pretty much everything I can think of and nothing works right


 

Link to comment
Share on other sites

Zammy wine grabber

 

Anyway, you sure its returning true and its not just waiting the 5 seconds defined by the line 

new ConditionalSleep(5000) {

// This means a max sleep of 5 seconds which is shorter than the item respawn time.
// Try new ConditionalSleep(90000) { for 1.5 minutes sleep

Also I would use item != null (Although there are other of doing it, suggest you test each one you can come up with for the fastest time).

 

Also instead of a conditional sleep, you could just change it to this which is probably better practice

else {
	if(!pos.getPolygon(bot).contains(getMouse().getPosition())){ //mouse is not hovering on tile
		//blah blah blah hover mouse
	}
}

 

 

Edited by k9thebeast
Link to comment
Share on other sites

9 minutes ago, k9thebeast said:

Zammy wine grabber

 

Anyway, you sure its returning true and its not just waiting the 5 seconds defined by the line 


new ConditionalSleep(5000) {

// This means a max sleep of 5 seconds which is shorter than the item respawn time.
// Try new ConditionalSleep(90000) { for 1.5 minutes sleep

Also I would use item != null (Although there are other of doing it, suggest you test each one you can come up with for the fastest time).

 

Also instead of a conditional sleep, you could just change it to this which is probably better practice


else {
	if(!pos.getPolygon(bot).contains(getMouse().getPosition())){ //mouse is not hovering on tile
		//blah blah blah hover mouse
	}
}

 

 

i did have it set for after re spawn rate i was just using it so that it would work; but it always fucks up;

ill give it a shot and report back

 

 

Link to comment
Share on other sites

From what I understand you're simply trying to make the script wait until the wine is back on the table?  

This isn't perfect, but you could definitely build on it

In your onLoop you shouldn't make the script DyanmicSleep while waiting, just don't make it do anything.

onLoop(){

GroundItem item = groundItems.closest("item");

if(item != null || item.exists()){

   //grab that shit
}

if(item == null || !item.exists()){


 if(!magic.isSpellSelected()){
	//check if can cast, then cast spell
}
if(magic.isSpellSelected()){
	if(!magic.getSelectedSpellName().equalsIgnoreCase(NormalSpells.TELEKINETIC_GRAB.name())){
		//deselect spell only
	}

  if(!hoverTile.getPolygon(bot).contains(mouse.getPosition()){
    // hover the tile
//return 600 or whatever here. Just make the script return inside onLoop() when waiting
  }
}

}


}

 

  • Like 1
Link to comment
Share on other sites

21 minutes ago, Polymorphism said:

From what I understand you're simply trying to make the script wait until the wine is back on the table?  

This isn't perfect, but you could definitely build on it


In your onLoop you shouldn't make the script DyanmicSleep while waiting, just don't make it do anything.

onLoop(){

GroundItem item = groundItems.closest("item");

if(item != null || item.exists()){

   //grab that shit
}

if(item == null || !item.exists()){


 if(!magic.isSpellSelected()){
	//check if can cast, then cast spell
}
if(magic.isSpellSelected()){
	if(!magic.getSelectedSpellName().equalsIgnoreCase(NormalSpells.TELEKINETIC_GRAB.name())){
		//deselect spell only
	}

  if(!hoverTile.getPolygon(bot).contains(mouse.getPosition()){
    // hover the tile
//return 600 or whatever here. Just make the script return inside onLoop() when waiting
  }
}

}


}

 

thanks mate; k9's worked perfect (:

 

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