Jump to content

Problem with pray pot drinking script.


Recommended Posts

Posted (edited)

Hello,

I'm new to osrs scripting and having trouble getting a simple pray pot drinker to work. Here is a snippet:

public final int onLoop() throws InterruptedException {
    // drinks potion when prayer falls under 10.
    if (getSkills().getDynamic(Skill.PRAYER) < 10){
        drinkPotion();
    }
    return 0;

}


public void drinkPotion(){
    // if slot contains prayer pot, it is drank and loop is exited.
    for (int i = 0; i <= 28; i++) {
        if (getInventory().getItemInSlot(i).nameContains("Prayer potion(4)", "Prayer potion(3)", "Prayer potion(2)", "Prayer potion(1)")) {
            getInventory().interact(i, "Drink");
            break;
        }
    }
}

Program works perfectly without the conditional that prayer be under 10. With it, once the conditional is met, the client (not the game) freezes. Any help would be appreciated, thanks.

EDIT: was a simple counting from zero error. (should be <=27)

Edited by why paranoid
Posted
11 hours ago, why paranoid said:

Hello,

I'm new to osrs scripting and having trouble getting a simple pray pot drinker to work. Here is a snippet:


public final int onLoop() throws InterruptedException {
    // drinks potion when prayer falls under 10.
    if (getSkills().getDynamic(Skill.PRAYER) < 10){
        drinkPotion();
    }
    return 0;

}


public void drinkPotion(){
    // if slot contains prayer pot, it is drank and loop is exited.
    for (int i = 0; i <= 28; i++) {
        if (getInventory().getItemInSlot(i).nameContains("Prayer potion(4)", "Prayer potion(3)", "Prayer potion(2)", "Prayer potion(1)")) {
            getInventory().interact(i, "Drink");
            break;
        }
    }
}

Program works perfectly without the conditional that prayer be under 10. With it, once the conditional is met, the client (not the game) freezes. Any help would be appreciated, thanks.

EDIT: was a simple counting from zero error. (should be <=27)

The for loop is redundant, the script is already looping, so you can just call interact(filter) and it will progress through the inventory.

As everyone else suggested, you should add a sleep after the interact to wait for the potion to actually be consumed before trying to drink the next one.

Posted (edited)
public void timer(boolean why) {
	new ConditionalSleep(10000) {
		@Override
		public boolean condition() throws InterruptedException {
			return why;
		}
	}.sleep();
}

if (skills.getDynamic(Skill.PRAYER) <= randomPrayerNum && inventory.contains(new ContainsNameFilter<>("Prayer"))) {
	inventory.getItem(new ContainsNameFilter<>("Prayer")).interact();
	timer(skills.getDynamic(Skill.PRAYER) > randomPrayerNum);
	randomPrayerNum = random(10,  35);
}

First part is it's own method, second part can be either added to your loop, or it's own method.

Also, if you're doing nameContains, you don't need to specify the entire name. Just "Prayer pot" would work.

Edited by qmqz

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

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