March 30, 20196 yr public void eat() throws InterruptedException { log("Checking Health"); if (myPlayer().getHealthPercent() < 99){ log("Health is not 100%"); if (getInventory().contains("Shark")){ log("Eating Shark"); getInventory().interact("Eat", "Shark"); new ConditionalSleep(1000, 100) { @Override public boolean condition() throws InterruptedException { return (myPlayer().getHealthPercent() == 100); } }.sleep(); } else { if (getInventory().contains("Varrock teleport")){ log("Teleporting to Varrock"); getInventory().interact("Break", "Varrock teleport"); new ConditionalSleep(1000, 100) { @Override public boolean condition() throws InterruptedException { return (!getCombat().isFighting()); } }.sleep(); } } } } Edited March 30, 20196 yr by investmentideas
March 30, 20196 yr Author this is the log [INFO][Bot #2][03/30 06:00:50 PM]: Checking Health [INFO][Bot #2][03/30 06:00:50 PM]: Checking Health [INFO][Bot #2][03/30 06:00:51 PM]: Checking Health [INFO][Bot #2][03/30 06:00:51 PM]: Checking Health my health was 45% when the script was running, so it is not recognising my health is < 99
March 30, 20196 yr It only works in combat, the value is cached. If no value has been cached yet, it should return 100. Use skills#getDynamic & skills#getStatic to compute your own health percent.
March 30, 20196 yr Author 8 minutes ago, Token said: It only works in combat, the value is cached. If no value has been cached yet, it should return 100. Use skills#getDynamic & skills#getStatic to compute your own health percent. didnt know, thanks for that! I changed to use static and dynamic, works like a treat, might not be the cleanest but works: private int getHpPercent() { int staticHp = getSkills().getStatic(Skill.HITPOINTS); int dynamicHp = getSkills().getDynamic(Skill.HITPOINTS); int hpPercent = 100 * (dynamicHp / staticHp); return hpPercent; } public void eat() throws InterruptedException { int hpThreshold = 100; log("Checking Health"); if (getHpPercent() < hpThreshold){ log("Health is not 100%"); if (getInventory().contains("Shark")){ log("Eating Shark"); getInventory().interact("Eat", "Shark"); new ConditionalSleep(1000, 100) { @Override public boolean condition() throws InterruptedException { return (myPlayer().getHealthPercent() == 100); } }.sleep(); } else { if (getInventory().contains("Varrock teleport")){ log("Teleporting to Varrock"); getInventory().interact("Break", "Varrock teleport"); new ConditionalSleep(1000, 100) { @Override public boolean condition() throws InterruptedException { return (!getCombat().isFighting()); } }.sleep(); } } } }
March 30, 20196 yr 12 minutes ago, investmentideas said: didnt know, thanks for that! I changed to use static and dynamic, works like a treat, might not be the cleanest but works: private int getHpPercent() { int staticHp = getSkills().getStatic(Skill.HITPOINTS); int dynamicHp = getSkills().getDynamic(Skill.HITPOINTS); int hpPercent = 100 * (dynamicHp / staticHp); return hpPercent; } public void eat() throws InterruptedException { int hpThreshold = 100; log("Checking Health"); if (getHpPercent() < hpThreshold){ log("Health is not 100%"); if (getInventory().contains("Shark")){ log("Eating Shark"); getInventory().interact("Eat", "Shark"); new ConditionalSleep(1000, 100) { @Override public boolean condition() throws InterruptedException { return (myPlayer().getHealthPercent() == 100); } }.sleep(); } else { if (getInventory().contains("Varrock teleport")){ log("Teleporting to Varrock"); getInventory().interact("Break", "Varrock teleport"); new ConditionalSleep(1000, 100) { @Override public boolean condition() throws InterruptedException { return (!getCombat().isFighting()); } }.sleep(); } } } } Make sure you cast to float/double when doing the division, your method should return only 0 or 100 if I'm not wrong
March 30, 20196 yr Couldn't you just say if (myPlayer().getHealthPercent() < 50 && getInventory().contains("Shark")) { Health % below 50 & Inventory contains sharks log("I got an owie, let's eat!"); getInventory().interact("Eat", "Shark"); Eats a shark } }
Create an account or sign in to comment