Jump to content

[Help] Conditional Sleep


Recommended Posts

Posted

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


 

Posted (edited)

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

 

 

Posted

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
Posted
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 (:

 

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