Jump to content

How to constantly check if under attacked?


Recommended Posts

Posted
On 24-11-2017 at 12:14 PM, The Legman said:

onLoop.PNG.2e966a32ebee923378562df4e2e9c591.PNG This currently how I build my scripts. The issue is when it runs through a task, such as normalRocks ( a completely different script btw), it will never interrupt that task while it's mid way done - which is what I want it to do. Thus I will end up trying to put that code in the onLoop. Thanks!

Stopscript == true?

 

Posted

If you're using conditional sleeps, your bot will be unresponsive to attacking players. Add a condition in your conditional sleep to check if you're under attack to break out of the sleep, and have your "under attack" case be first in your code so it takes priority.

new ConditionalSleep(45000){
	public boolean condition() throws InterruptedException {
		return myPlayer().isUnderAttack() || (other conditions);
	}
}.sleep();

 

Posted

Just to expand on what HeyImJamie said. Only teleporting after you're under attack might be too late and hopping afterwards is impossible. You can iterate through the players that are loaded and check if their combat level can attack you(Example: Your combat level is 30, they're 45 and you're in 10 wilderness it won't hop or teleport. If they're 37, you would hop.). If you don't want to do that, an easier way to do it would be to check the size of local players and if it's greater than 2 it will hop(It counts your player). This will hop no matter what though, whether they can attack you or not. Then check for active tasks. 

 

P.S I would also recommend checking for teleblock with onMessage so that you don't have the bot spamming the teleport. And isUnderAttack so it's not trying to hop worlds.

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