Jump to content

Keeps lighting logs while im already lighting


08egans

Recommended Posts

hi ive been trying to work on my first script, which just checks for logs on the ground and lights them. however the problem is that when the script starts to light a fire and the animation comes on, the loop keeps repeating itself over and over without stopping so it keeps lighting the same log over and over before it has time to even light. i know there is something to do with player animations but im new to java so im a bit stuck. (dont mind the sleep times)

source - 

package org.Hello.Sebby;

import org.osbot.rs07.api.model.GroundItem;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;




import java.awt.*;

@ScriptManifest(name = "Skeleton", logo ="", info ="Script Info", version = 0.1, author ="08egans")
public class skeleton extends Script{

    public void onStart(){
        log("Our Script has started");

    }

    public int onLoop() throws InterruptedException {

        GroundItem item =   getGroundItems().closest("Logs");
        if(!myPlayer().isAnimating()) {
            item.interact("Light");
            sleep(random(2000, 3000));

        }

        return random(2000, 1800);
    }
    public void onExit(){
        log("Script has stopped");
    }
    public void onPaint(Graphics g){

    }
    public void onMessage(String s){
        log("on Message: " + s);
    }
}
  • Like 1
Link to comment
Share on other sites

the firemaking animation is weird,it stops animating regularly (when you stand up it actually stops the animation before starting again meaning !myPlayer().isAnimating() will think its not animating, unlike during fishing/wc where it doesn't stop the animation), its not the best way to check, honestly I would try something simpler as your first script

Link to comment
Share on other sites

First off I would really recommend looking up a tutorial and trying to work on it using state based logic.

 

But anyways, given your current code with the intention of trying to do what you want to do,

 

I would just keep track of your xp gains. If you haven't gained exp since the last time you tried to light a log, then presumably you're not done burning that log yet, so don't try to light another one.

Link to comment
Share on other sites

if (myPlayer().isAnimating()) { //if we are animating
                *LONG VARIABLE TO STORE THE TIME* = System.currentTimeMillis(); //Grabs the time

} else if (System.currentTimeMillis() > (*THE VARIABLE U CREATED* + 5000)) { //If we are not animating, and 5 seconds has passed without us animating, then do stuff.

//Do your stuff here such as lighting the log

};

 

Reference -> 

 

Edited by Viston
  • Like 1
Link to comment
Share on other sites

4 hours ago, Viston said:

if (myPlayer().isAnimating()) { //if we are animating
                *LONG VARIABLE TO STORE THE TIME* = System.currentTimeMillis(); //Grabs the time

} else if (System.currentTimeMillis() > (*THE VARIABLE U CREATED* + 5000)) { //If we are not animating, and 5 seconds has passed without us animating, then do stuff.

//Do your stuff here such as lighting the log

};

 

Reference -> 

Thank you for the help! :)

 

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