Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

getHealthPercent()

Featured Replies

Hello, during deathwalking I am trying to enable eating in my script, the code is as follows...

while(myPlayer().isMoving()) {
	if(myPlayer().getHealthPercent() < 60) {
		if(getFood() != null)
			inventory.getItem(new String(getFood())).interact("Eat");
	}
                                          
	sleep(random(100, 200));
}

 

This seems like it should work, but the problem is that it is never eating. I tried some basic debugging of the script and decided to log the output from the getHealthPercent function and it is always returning 100. When my hitpoints are 8/38 it says that my health percent is 100 and therefore does not eat. 

  • Author

I can try that, but I'm not sure why it would work if it does. 

log(myPlayer().getHealthPercent()) gives me an output of 100, so we would be sending into the if statement (false && true && true)

You can't eat in the middle of webwalking. 
Webwalker must finish before moving to the next line of code.


You need to use setBreakCondition to interrupt webwalker.


Goodluck

  • Author

Seems that I've found a current fix using deprecated methods, thanks for your help :)

private double getHealthPercentB() {
	return (double)myPlayer().getCurrentHealth() / (double)myPlayer().getMaximumHealth();
}
while(myPlayer().isMoving()) {
	if(getHealthPercentB() <= 0.6) {
		if(gui.getFood() != null)
			inventory.getItem(new String(gui.getFood())).interact("Eat");
		}
                                 
	sleep(random(100, 200));
}

 

  • Author
Just now, Juggles said:

You can't eat in the middle of webwalking. 
Webwalker must finish before moving to the next line of code.


You need to use setBreakCondition to interrupt webwalker.


Goodluck

 

You're right. My fix helped fix the issue of when I was idle, my script would tell me that I was 100% hp, when I was not. 

Edited by Kawaii_s
grammar

Eating is fine for me in my script. I'm not sure if health percent runs off of the hp bar though?

  • Author

Got everything working, not sure what the problem with the method to get percent hitpoints, but found that using the depricated methods works for my case. Are the depricated methods considered unsafe for bot detection or just aren't really used anymore? Nevertheless, the code I used is as follows..

while(!(starting_area.contains(myPlayer()))) {
	walkToStart();
	if(gui.getFood() != null)
		inventory.getItem(new String(gui.getFood())).interact("Eat");
}
private void walkToStart() throws InterruptedException {
	WebWalkEvent to_start = new WebWalkEvent(starting_area);
	to_start.setBreakCondition(new Condition() {

		@Override
		public boolean evaluate() {
			return (getHealthPercentB() <= 0.60);
		}
	});
		
	getWalking().execute(to_start);
}

 

2 hours ago, Kawaii_s said:

Got everything working, not sure what the problem with the method to get percent hitpoints, but found that using the depricated methods works for my case. Are the depricated methods considered unsafe for bot detection or just aren't really used anymore? Nevertheless, the code I used is as follows..


while(!(starting_area.contains(myPlayer()))) {
	walkToStart();
	if(gui.getFood() != null)
		inventory.getItem(new String(gui.getFood())).interact("Eat");
}

private void walkToStart() throws InterruptedException {
	WebWalkEvent to_start = new WebWalkEvent(starting_area);
	to_start.setBreakCondition(new Condition() {

		@Override
		public boolean evaluate() {
			return (getHealthPercentB() <= 0.60);
		}
	});
		
	getWalking().execute(to_start);
}

 

To get your player's health you should use getSkills().getDynamic(Skill.HITPOINTS)

That returns the current hitpoint value.

You can also get the players max hitpoints using getSkills().getStatic(Skill.HITPOINTS)

You can then calculate health percent using them:

getSkills().getDynamic(Skill.HITPOINTS) * 100 / getSkills().getStatic(Skill.HITPOINTS);

Edited by Explv

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.