July 19, 20196 yr I can't get the script to eat food. Any help? 😛 public int onLoop() throws InterruptedException { if (myPlayer().getHealthPercent() < 35) { eatFood(); sleep(random(500, 1000)); } return 0; } public void eatFood() throws InterruptedException { if (getInventory().contains("Shrimps")) { getInventory().getItem("Shrimps").interact("Eat"); } else { goBank(); sleep(random(1000, 2000)); goMonsterLoc(); } }
July 20, 20196 yr Make sure the names of the item, "shrimp" and the interaction, "eat" is exactly how it's written in the game. If that's fine, then just remove everything and put the "eat" code in the on loop and see if that works. If it does, then it should indicate that something else is the issue.
July 29, 20196 yr On 7/19/2019 at 9:54 AM, jajaXd said: I can't get the script to eat food. Any help? 😛 public int onLoop() throws InterruptedException { if (myPlayer().getHealthPercent() < 35) { eatFood(); sleep(random(500, 1000)); } return 0; } public void eatFood() throws InterruptedException { if (getInventory().contains("Shrimps")) { getInventory().getItem("Shrimps").interact("Eat"); } else { goBank(); sleep(random(1000, 2000)); goMonsterLoc(); } } your timer seems a bit silly because eating takes 3 ticks. you're more than welcome to do random (1800, 2400), but random doesn't really matter much anyways here's two ways you can go about it, but it's virtually the exact same code just done differently. untested, but it should work you're also better off checking if your player is in an Area instead of checking if the bank booth is null. or you can use map.distance and a null check as for everyone else, it is infact "Shrimps" in-game. it doesn't take much effort to check it out on the wikia for the correct name, instead of telling op he got it wrong Position VarrockWestBank = new Position(3184, 3436, 0); int health; boolean invHas(String item) { return inventory.contains(item); } boolean eat(String name) { return inventory.interact("Eat", name); } boolean objExists(String obj) { return objects.closest(obj) != null; } String booth = "Bank booth", food = "Shrimps"; public int onLoop() throws InterruptedException { health = myPlayer().getHealthPercent(); if (health <= 35 && invHas(food)) { eat(food); sleep(1800); } else if (health <= 50 && !invHas(food) && !objExists(booth)) { walking.webWalk(VarrockWestBank); } return 200; } Position VarrockWestBank = new Position(3184, 3436, 0); public int onLoop() throws InterruptedException { if (myPlayer().getHealthPercent() <= 35 && inventory.contains("Shrimps")) { inventory.interact("Eat", "Shrimps"); sleep(1800); } else if (myPlayer().getHealthPercent() <= 50 && !inventory.contains("Shrimps") && objects.closest("Bank booth") == null) { walking.webWalk(VarrockWestBank); } return 200; } edit: you can also choose to not declare certain positions like I did, and you can simple do - walking.webWalk(Banks.VARROCK_WEST); Edited July 29, 20196 yr by qmqz
Create an account or sign in to comment