January 17, 20197 yr 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 January 17, 20197 yr by why paranoid
January 17, 20197 yr 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 Edited January 17, 20197 yr by Spider
January 17, 20197 yr 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
January 17, 20197 yr 35 minutes ago, FuryShark said: He edited it an hour ago ohhh nvm didn't see the edit just focused on the code
January 18, 20197 yr 2 hours ago, FuryShark said: He edited it an hour ago I'd still add a sleep. It's iterating far too fast for what it should, surprised it's even running tbh.
January 18, 20197 yr 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.
January 19, 20197 yr 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 January 19, 20197 yr by qmqz
Create an account or sign in to comment