Jump to content

Player Health Listener


Recommended Posts

Posted (edited)

Synopsis: I want to cut willows at Draynor, but that damn wizard keeps kicking my ass. 

How would I write a listener that keeps track of health and the minute the wizard starts attacking me, I can tell my player to move to a safespot.

 

EDIT: I just got an idea. Would it be wise to put it at the top of the states so it's the first thing that gets checked?

i.e.

 

public states getStates() {

if my player is being harassed by the dark mage { return run }

if blah blah blah { return chop }

if blah blue { return bank }

Edited by Noidlox
Posted
14 minutes ago, Noidlox said:

Synopsis: I want to cut willows at Draynor, but that damn wizard keeps kicking my ass. 

How would I write a listener that keeps track of health and the minute the wizard starts attacking me, I can tell my player to move to a safespot.

You could create a concurrent thread to track this kind of thing, but since your onLoop should be continuously looping anyway, and you don't need such a big degree of accuracy (oh, and it can be easy to implement new threads incorrectly), why not just put the check in your onLoop (or create a new state if you're using some kind of structure):

if (getSkills().getDynamic(Skill.HITPOINTS) < getSkills().getStatic(Skill.HITPOINTS)) {
  //We've lost some health - run!
}
Posted (edited)
34 minutes ago, Apaec said:

You could create a concurrent thread to track this kind of thing, but since your onLoop should be continuously looping anyway, and you don't need such a big degree of accuracy (oh, and it can be easy to implement new threads incorrectly), why not just put the check in your onLoop (or create a new state if you're using some kind of structure):


if (getSkills().getDynamic(Skill.HITPOINTS) < getSkills().getStatic(Skill.HITPOINTS)) {
  //We've lost some health - run!
}

I totally forgot about the on-loop part lol. Thanks for that!

[I wish I could like your comment, but I've reached my threshold]

25 minutes ago, d0zza said:

You could use what Apaec wrote or you could even check if your player is in combat or under attack.


if (myPlayer().isUnderAttack() || getCombat().isFighting()) {
	//We are in combat, run
}

 

Gonna use isUnderAttack instead of HitVarVisible from now on. Ty for this!

[I wish I could like your comment, but I've reached my threshold]

Edited by Noidlox

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