Jump to content
Guest

Player Health Listener

Recommended Posts

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
Link to comment
Share on other sites

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!
}
Link to comment
Share on other sites

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

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