Jump to content

Methods to use potions


Nezz

Recommended Posts

  • 2 months later...

:/

	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! smile.png

Mmmeh, just so long as getItemForNameThatContains is case sensitive, you should be fine because...

Strength potion

Amulet of strength

Edited by liverare
  • Like 1
Link to comment
Share on other sites

:/

	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! smile.png

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

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...