Jump to content

Need help animating stopping while smelting


Recommended Posts

Posted

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
Posted (edited)

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
Posted
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(); 

                                }

                                    

                            }

                        }

  • 2 weeks later...
Posted (edited)

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

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...