Jump to content

Detecting level up


ThatGamerBlue

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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