Jump to content

Problem with pray pot drinking script.


why paranoid

Recommended Posts

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
Link to comment
Share on other sites

3 minutes ago, Spider said:

make onloop return 300, so that it repeats itself every 300 milliseconds or so

also in osbot API slots are numbered from 0-27 so make the loop <28 instead of <=

also check the logger it usually can give you hints about what is going wrong

 

He edited it an hour ago

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

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