July 7, 20178 yr 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.
July 7, 20178 yr try something like if (myPlayer().getHealthPercent() < 60 && myPlayer().isAnimating() && getInventory().contains(item -> item.hasAction("Eat"))) { //eat any food getInventory().getItem(item -> item.hasAction("Eat")).interact("Eat"); sleep(random(600, 1000)); } return 100; }
July 7, 20178 yr 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)
July 7, 20178 yr 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
July 7, 20178 yr 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)); }
July 7, 20178 yr 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 July 7, 20178 yr by Kawaii_s grammar
July 7, 20178 yr Eating is fine for me in my script. I'm not sure if health percent runs off of the hp bar though?
July 7, 20178 yr 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); }
July 7, 20178 yr 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 July 7, 20178 yr by Explv