Jump to content

[Beginner] Trying to run simple miner, it wont even start?


t0r3

Recommended Posts

Hey :D It's me again :)

Have a problem with my miner, - tried writing it different from what I'm used to; Tried using private voids and then putting them into onLoop. What can I improve and what is making my script not runnable? :o  

public class LSCopperMiner extends Script {

    private Area miningArea = new Area( 3228, 3145, 3229, 3145);

    private void walking(){

        if (getInventory().isEmptyExcept("Bronze pickaxe","Iron pickaxe","Steel pickaxe",
                "Mithril pickaxe","Adamant pickaxe","Rune pickaxe" )
                && !miningArea.contains(myPosition())){

            log("Inventory is empty and miningArea does not contain my position, walking to mining area");
            getWalking().webWalk(miningArea);

        } else if(getInventory().isFull() && !Banks.LUMBRIDGE_UPPER.contains(myPosition())) {

            log("Inventory is full, walking to LBank");
            getWalking().webWalk(Banks.LUMBRIDGE_UPPER);
        }
    }

    private RS2Object copperRocks = getObjects().closest(7484,7453);

    private void levelUpWhile() {

        while (getDialogues().isPendingContinuation()){

            if(getDialogues().clickContinue()){

                log("Interacting with copperRocks again");
                copperRocks.interact("Mine");
            }
        }
    }

    private void mining() throws InterruptedException {

        if(copperRocks != null && !myPlayer().isAnimating() && !myPlayer().isMoving()){

            log("Interacting with copperRocks");
            copperRocks.interact("Mine");

            log("Sleeping a bit before 'going afk'");
            sleep(random(1000,1400));

            log("Moving mouse outside of screen,'going afk'");
            getMouse().moveOutsideScreen();
        }
    }

    private void banking() throws  InterruptedException {

        RS2Object bankBooth = getObjects().closest("Bank booth");

        if(!getBank().isOpen() && bankBooth != null && Banks.LUMBRIDGE_UPPER.contains(myPosition())) {

            log("In LBank and Bank is not open, interacting with Bank");
            bankBooth.interact("Bank");

            log("Sleeping for 1.5-2.5 sec to avoid interacting with bank again");
            sleep(random(1500, 2500));
        }

        if(getBank().isOpen()) {

            log("Bank is open, depositing everything except pickaxes");
            getBank().depositAllExcept("Bronze pickaxe","Iron pickaxe","Steel pickaxe",
                                       "Mithril pickaxe","Adamant pickaxe","Rune pickaxe");
        }
    }

    @Override
    public int onLoop() throws InterruptedException {

        if(!miningArea.contains(myPosition()) || !Banks.LUMBRIDGE_UPPER.contains(myPosition())) {

            walking();
        }

        else if(miningArea.contains(myPosition())){

            levelUpWhile();
            mining();
            banking();
        }

        return 1000;
    }
}
Edited by t0r3
Link to comment
Share on other sites

Also

following line 

    private RS2Object copperRocks = getObjects().closest(7484,7453);

Should be in your mining() method. 

private void mining() throws InterruptedException {

    RS2Object copperRocks = getObjects().closest(7484,7453);
        
         if(copperRocks != null && !myPlayer().isAnimating() && !myPlayer().isMoving()){

            log("Interacting with copperRocks");
            copperRocks.interact("Mine");

            log("Sleeping a bit before 'going afk'");
            sleep(random(1000,1400));

            log("Moving mouse outside of screen,'going afk'");
            getMouse().moveOutsideScreen();
        }
    }

^^ now it will try to find copperRocks obj always when you run mining() method, not only at start of the script. 

  • Like 1
Link to comment
Share on other sites

3 minutes ago, ThatGamerBlue said:

You got your


@ScriptManifest

annotation?

Yeah :)  I have the ScriptManifest up, able to locate it, click run and then it just doesnt do anything.

When I click the Start button after choosing my script nothing happens. It doesn't even shift from the green play button to pause and stop button options.. :o 

Link to comment
Share on other sites

7 minutes ago, Xx pk xX said:

Also

following line 


    private RS2Object copperRocks = getObjects().closest(7484,7453);

Should be in your mining() method. 


private void mining() throws InterruptedException {

    RS2Object copperRocks = getObjects().closest(7484,7453);
        
         if(copperRocks != null && !myPlayer().isAnimating() && !myPlayer().isMoving()){

            log("Interacting with copperRocks");
            copperRocks.interact("Mine");

            log("Sleeping a bit before 'going afk'");
            sleep(random(1000,1400));

            log("Moving mouse outside of screen,'going afk'");
            getMouse().moveOutsideScreen();
        }
    }

^^ now it will try to find copperRocks obj always when you run mining() method, not only at start of the script. 

Thanks :)

Ah, yeah I put all the way up there because I use it both in;

private void levelUpWhile() {

and,

private void mining() throws InterruptedException {

This is completely wrong?

Put in both methods now, for reference :D

2 minutes ago, Script Kid said:

This value needs to be refreshed every time you try to mine a new rock. Do this in every method that uses this variable.

Thanks! :D Yeah I realize this now :) hahah

Edited by t0r3
Link to comment
Share on other sites

39 minutes ago, Xx pk xX said:

miningArea has only 2 tiles? Following condition probably won't run - my guess is that player is not in mining area. 


else if(miningArea.contains(myPosition())){

Just make mining area bigger. Also make sure that copperRocks id's are correct. Then it should run ?

Yeah :D

Ended up making this work;

@Override
public int onLoop() throws InterruptedException {

    if(!miningArea.contains(myPosition()) || !Banks.LUMBRIDGE_UPPER.contains(myPosition())) {

        walking();
    }

    if (miningArea.contains(myPosition())) {

        levelUpWhile();
        mining();
    }

    if (Banks.LUMBRIDGE_UPPER.contains(myPosition())){

        banking();
    }

    return 1000;
}

Tried putting 

else 

in front of

if (miningArea.contains(myPosition()))

Why won't this work?

 

-------------------------------------------------------------------------------------------------------------------------------------

 

Even though, - could just this work? The conditions for the different methods are already set in each one. Am I wrong? :o 

@Override
public int onLoop() throws InterruptedException {

    if(myPlayer.exists()) {

        walking();
        levelUpWhile();
        mining();
        banking();
    }

    return 1000;
}

Thanks for being so helpful :) :) I know I'm asking many questions haha :D getting really into it

Edited by t0r3
Link to comment
Share on other sites

Quote

Even though, - could just this work? The conditions for the different methods are already set in each one. Am I wrong? :o 


@Override
public int onLoop() throws InterruptedException {

    if(myPlayer.exists()) {

        walking();
        levelUpWhile();
        mining();
        banking();
    }

    return 1000;
}

Thanks for being so helpful :) :) I know I'm asking many questions haha :D getting really into it

That should work so long as all of your conditionals are correct. Easiest way to test that would be to just do it. The main things you have to ask yourself is calling any of those other methods while another one is happening going to screw with what your script tries to do? For instance if you call levelUpWhile() and the script is actually banking etc..

 

As for your second question regarding why sticking else in front of that if statement doesn't work i'm not sure why it isn't working, as logically it should as long as it's formatted like this:

 

@Override
public int onLoop() throws InterruptedException {

    if(!miningArea.contains(myPosition()) || !Banks.LUMBRIDGE_UPPER.contains(myPosition())) {
        walking();
    } else if (miningArea.contains(myPosition())) {
        levelUpWhile();
        mining();
    } else if (Banks.LUMBRIDGE_UPPER.contains(myPosition())){
        banking();
    }

    return 1000;
}

 

Edited by Nebulae
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...