Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Proper way to handle tasks where there is a -1 animation between each activity e.g stringing bows crafting hide bodies etc.

Featured Replies

Hi as title says I know that it is discouraged to use "while" in the loop, but for the activities mentioned you cant use !myPlayer().isAnimating() due to the character hitting -1 animation during the creation of items. For example, when stringing magic longbows every 5 or so I get a -1 animation and so the bot tries to string again. I currently am getting around this using a while loop with a counter which basically will break the loop when it hits a number which means something isnt working properly for whatver reason but I know this isnt a good way to handle it. I am struggling to see anything in the api to help (although i am not the best at reading apis). I was wondering what the consensus is on how to work around this issue?

  • Author
33 minutes ago, Khaleesi said:

Ya do not use a while loop.

You can use a Timer and set it to 2-3 seconds and reset it every time u animating
and only start interacting or crafting when the timer is not running :)

Hey thanks for the reply is there any chance you can give an example? :)

8 minutes ago, chardragon said:

Hey thanks for the reply is there any chance you can give an example? :)

public class AnimationCheck extends Script {
    
    private final Timer animationTimer = new Timer(3_000);

    @Override
    public void onStart() {
        
    }

    @Override
    public int onLoop() {
        
        if(myPlayer().isAnimating()){
            animationTimer.reset();
        }
        
        if(animationTimer.isRunning()){
            log("Animating");
        }else{
            //Start doing whatever you wanted to do
        }
        
        return 50;
    }
}


Basic Timer class

public class Timer {

     private long period;
     private long startTime;

     public Timer(long period) {
          this.period = period;
          startTime = System.currentTimeMillis();
     }

     public boolean isRunning() {
          return getElapsed() < period;
     }

      public long getElapsed() {
           return System.currentTimeMillis() - startTime;
     }

     public long getRemaining() {
           return period - getElapsed();
     }

     public void reset() {
          startTime = System.currentTimeMillis();
     }

     public void stop() {
           period = 0;
     }

    public static String formatTime(long ms) {
        long sec = ms / 1000L;
        return String.format("%02d:%02d:%02d", Long.valueOf(sec / 3600L), Long.valueOf((sec % 3600L) / 60L), Long.valueOf(sec % 60L));
    }
}

 

Edited by Khaleesi

9 hours ago, chardragon said:

Hi as title says I know that it is discouraged to use "while" in the loop, but for the activities mentioned you cant use !myPlayer().isAnimating() due to the character hitting -1 animation during the creation of items. For example, when stringing magic longbows every 5 or so I get a -1 animation and so the bot tries to string again. I currently am getting around this using a while loop with a counter which basically will break the loop when it hits a number which means something isnt working properly for whatver reason but I know this isnt a good way to handle it. I am struggling to see anything in the api to help (although i am not the best at reading apis). I was wondering what the consensus is on how to work around this issue?

Look at the ConditionalSleep class, it uses a loop but allows interruption

You basically want a nested condition, sleep until you haven't animated for x seconds (sleep until the nested sleep fails)

import org.osbot.rs07.utility.ConditionalSleep;

import java.util.function.BooleanSupplier;

public class Sleep extends ConditionalSleep {
    private final BooleanSupplier condition;

    public Sleep(final BooleanSupplier condition, final int timeout) {
        super(timeout);
        this.condition = condition;
    }

    public static boolean sleepUntil(final BooleanSupplier condition, final int timeout) {
        return new Sleep(condition, timeout).sleep();
    }

    @Override
    public final boolean condition() {
        return condition.getAsBoolean();
    }
}

Usage

Sleep.sleepUntil(() -> !Sleep.sleepUntil(api.myPlayer()::isAnimating, random(4000, 8000)), random(20000, 40000))

Sleep until haven't animated for 4-8 seconds, returns boolean whether condition was met or timed out

  • 3 weeks later...

You could do a conditional sleep when you push through the craft and have the break condition be when your inventory no longer contains the required crafting items. Then after that have a simple sleep with a randomizer after that.

Create an account or sign in to comment

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.