Jump to content

Need help animating stopping while smelting


ridooz

Recommended Posts

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

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

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

                                }

                                    

                            }

                        }

Link to comment
Share on other sites

  • 2 weeks later...

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