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.

Need help animating stopping while smelting

Featured Replies

Hi i'm new to scripting at osbot.org. Trying to learn the basic stuff. Created a willow cutter and banker at draynor. Now moved onto a steel smelter at edgeville (just to get more knowledge and the basics)

 

I just have a problem with smelting since your animations stop for a second when smelting bars. How can i prevent this?

 

Here's an example of my code:

 

if (!player.isAnimating()) {
                            if (!player.isMoving()) {
 
// && System.currentTimeMillis() > (player.getAnimation() + 3000)
                                if (options == null) {
                                    furnace.interact("Smelt");
                                    sleep(3000);
                                }
 
                                if (options != null) {
                                    sleep(3000);
                                    options.interact("Smelt X Steel");
                                    sleep(random(2000, 2000));
                                    keyboard.typeString("" + random(29, 99), true);
                                    sleep(3000);
 
                                }
 
                                //sleep(random(1000, 1000));
                            }
                        }
 
 
 
 
It just hits smelt at furnace again when it has smelted 1 bar.
Thanks in advance

tbh i didnt like any of those answers. Maybe except for the condition sleep. Personally i would just use a timer. And a simple boolean check to weather it should interaction or keep waiting.

private long waitTimer = System.currentTimeMillis();

if (player animtaing) {
  restart timer
}
else if (System.currentTimeMillis() - this.waitTimer > 3000){
  start interaction
}

edit: if you dont understand how to make the timer concept. Here a simple timer class. Its been passed around for ages

public class Timer {

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

	public long getElapsed()	{
		return System.currentTimeMillis() - this.start;
	}
	
	public long getRemaining()	{
		return this.period - this.getElapsed();
	}
	
	public boolean isRunning()	{
		return this.getElapsed() <= this.period;
	}
	
	public void setPeriod(long period)	{
		this.period = period;
	}
	
	public void reset()	{
		this.start = System.currentTimeMillis();
	}
	
	public static String format(long milliSeconds)	{
		long secs = milliSeconds / 1000L;
		return String.format("%02d:%02d:%02d", new Object[]	{
				Long.valueOf(secs / 3600L), Long.valueOf(secs % 3600L/ 60L), Long.valueOf(secs % 60L)
		});
	}
}

Edited by Joseph

  • Author
Still doesn't work. What am i doing wrong here?

 

if (!player.isAnimating()) {

                            if (!player.isMoving()) {

 

                                if(System.currentTimeMillis() - this.waitTimer > 3000){

                                    if (options == null) {

                                    furnace.interact("Smelt");

                                    sleep(3000);

                                }

 

                                if (options != null) {

                                    sleep(3000);

                                    options.interact("Smelt X Steel");

                                    sleep(random(2000, 2000));

                                    keyboard.typeString("" + random(29, 99), true);

                                    sleep(3000);

 

                                }

                                }

                                else{

                                    waitTimer = System.currentTimeMillis(); 

                                }

                                    

                            }

                        }

My if else order:

if(myPlayer().isAnimating()) {

// Reset timer

}

else if (waitTimer.getElapsed() > 3000) {

// Smithing code here

}
  sleep(1000);
}

Edited by herojord

  • 2 weeks later...
  • Author

Fixed it my own way without timer or conditionsleep :D

You could have something like this:

import org.osbot.rs07.script.MethodProvider;

public class ConditionalTimer {

	private int time, step, elapsed;
	private TimerCondition condition;
	
	public ConditionalTimer(int t, TimerCondition cond, int s) {
		time = t;
		condition = cond;
		step = s;
	}
	
	public boolean run() throws InterruptedException {
		elapsed = 0;
		while (time <= elapsed) {
			if (condition.condition()) return true;
			MethodProvider.sleep(step);
		}
		return false;
	}
	
	public int getElapsed() {
		return elapsed;
	}
}

interface TimerCondition {
	public boolean condition();
}

Example:

if (new ConditionalTimer(3000, () -> (myPlayer().isAnimating()), 50).run()) {
    //we're animating
}
else {
    //we're not animating (we haven't been animating for 3000 ms)
}

Edited by Bobrocket

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.