liverare Posted May 15, 2014 Posted May 15, 2014 (edited) public static boolean drinkPotion(Client client, Skill skill) throws InterruptedException { boolean success = false; int boostedLevel = client.getSkills().getCurrentLevel(skill); int baseLevel = client.getSkills().getLevel(skill); if (boostedLevel <= baseLevel) { /* * e.g., * ATTACK -> * -> (A) (ttack) -> * -> Attack */ String potionName = skill.name().charAt(0) + skill.name().substring(1).toLowerCase(); Item potion = client.getInventory().getItemForNameThatContains(potionName); if (potion != null && client.getInventory().interactWithId(potion.getId(), "Drink")) { success = true; } } return success; } Be liek public void someMethod() { // Drink attack potion if (drinkPotion(client, Skill.ATTACK)) { log("Successfully drank a sip of attack potion."); } // Drink strength potion if (drinkPotion(client, Skill.STRENGTH)) { log("Successfully drank a sip of strength potion."); } // Drink agility potion if (drinkPotion(client, Skill.AGILITY)) { log("Successfully drank a sip of agility potion."); } } Oh, forgot to mention: Untested. :\ ...Lol, just realised; don't be havin' no strength amulet on yo' purson! Mmmeh, just so long as getItemForNameThatContains is case sensitive, you should be fine because... Strength potion Amulet of strength Edited May 15, 2014 by liverare 1
Nezz Posted May 15, 2014 Author Posted May 15, 2014 public static boolean drinkPotion(Client client, Skill skill) throws InterruptedException { boolean success = false; int boostedLevel = client.getSkills().getCurrentLevel(skill); int baseLevel = client.getSkills().getLevel(skill); if (boostedLevel <= baseLevel) { /* * e.g., * ATTACK -> * -> (A) (ttack) -> * -> Attack */ String potionName = skill.name().charAt(0) + skill.name().substring(1).toLowerCase(); Item potion = client.getInventory().getItemForNameThatContains(potionName); if (potion != null && client.getInventory().interactWithId(potion.getId(), "Drink")) { success = true; } } return success; } Be liek public void someMethod() { // Drink attack potion if (drinkPotion(client, Skill.ATTACK)) { log("Successfully drank a sip of attack potion."); } // Drink strength potion if (drinkPotion(client, Skill.STRENGTH)) { log("Successfully drank a sip of strength potion."); } // Drink agility potion if (drinkPotion(client, Skill.AGILITY)) { log("Successfully drank a sip of agility potion."); } } Oh, forgot to mention: Untested. :\ ...Lol, just realised; don't be havin' no strength amulet on yo' purson! Mmmeh, just so long as getItemForNameThatContains is case sensitive, you should be fine because... Strength potion Amulet of strength None of those would handle Super potions. I should probably go through and rewrite my snippet. :P