Jump to content

Detecting level up


Recommended Posts

Posted

When you level up you stop skilling, how can I detect this and restart?

Right now I'm using message detection using onMessage but It doesn't seem to work.

boolean doBreak = false;

@Override
public void onMessage(Message m){
	if(m.getType() == MessageType.GAME && m.getMessage().contains("You are now level") && !doBreak){
		doBreak = true;
	}
}

@Override
public int onLoop() throws InterruptedException {
	// code to start making pizza
	while(getInventory().contains("Anchovies") && getInventory().contains("Plain pizza")){
		sleep(random(250, 500));
		if(doBreak){
			doBreak = false;
			sleep(random(100, 200));
			break;
		}
	}
}

Full code: https://hastebin.com/defifurane.java

Posted

You will need a more advanced solution for this rather than just checking for the level up message, to account for other interruptions and to more reliably accommodate for level ups.

I'm not sure how you're tracking when you finish the inventory (hopefully not a massive 40 second long sleep!), but I would suggest moving over to a timer-based system (I have this implemented in my AIO Cooker). The idea is that a timer is running in the background and is reset when you're animating (or some other check to determine whether you're cooking). If this timer exceeds a threshold, then you're probably no longer cooking and the interaction code kicks in.

For this timer to work however, you will need some kind of async thread to work in. You could use the onPaint, however onPaint should really not be used for anything more than paint stuff! You will most likely have to create your own concurrent utility class which does this for you. Since it is easy to get something wrong when doing concurrent stuff, be careful and make sure you do sufficient research otherwise you might see some behaviour you did not expect. I would suggest the best way to achieve this is to extend Thread and work from there, implementing the void run method.

Good luck! (:

Apa

Posted (edited)

you might want to change that while to a conditional sleep after you move mouse off screen, that would sleep until out of pizzas or level up message is seen
 

					new ConditionalSleep(30000) {
						@Override
						public boolean condition() {
							return !inventory.contains("Plain pizza") || widgets.isVisible(233);
						}
					}.sleep();

the 233 widget is the level up message

Edited by GPSwap

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