Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

Sign up now!

Question Tree bot - Check is fully logged in

Joined
Jun 25, 2019
Messages
24
So i'm having an issue similar to this thread -> Resolved - [OSRS] Runescape.isLoggedIn() = true in "lobby screen"?

The thing is im using a tree bot instead of a looping bot. I have structured my bot so that if it can't find a fishing spot it logs out. The problem being the fishing spot is not visible until I log in completely. However runemate executes all of my logic before the login handler has logged me completely in e.g clicked through the "lobby".

My question is what is the best way using a tree bot structure to check if a player is completely logged in?

I have tried:
- delayUntil in the branch that checks if i'm near a fishing spot -> didnt work, it returned a null pointer exception on Execution.delayUntil(() -> p.isVisible());

Code:
public class IsNearFishSpot extends BranchTask {

    private Fish fish = new Fish();
    private Logout logout = new Logout();

    private Npc fishing_spot;
    private Player p;

    @Override
    public boolean validate() {
        fishing_spot = Npcs.newQuery().names("Fishing spot").actions("Net").results().nearest();
        p = Players.getLocal();
        Execution.delayUntil(() -> p.isVisible());
        if (fishing_spot != null) {
            return true;
        } else {
            return false;
        }

    }


    @Override
    public TreeTask failureTask() {
        return logout;
    }

    @Override
    public TreeTask successTask() {
        return fish;
    }
}

- I've tried doing this check in the root node but im not sure what to return outside of the if statement:

Code:
public class PowaFisher extends TreeBot {
    private Player p;

    @Override
    public TreeTask createRootTask() {
        if ((p = Players.getLocal()) == null || !p.isVisible()) {
            return new IsInventoryFull();
        }
        return null; // is it ok to return null? whats the proper return statement here?
    }

So yeah not sure how to properly check that im logged in so that I can start looping through my bot logic.
 
Last edited:
12 year old normie
Joined
Jan 8, 2015
Messages
2,769
To answer some of your questions:

Your if check in your createRootTask() method returns the task when it is not logged in.

Code:
(p = Players.getLocal()) == null || !p.isVisible())

  1. Local player == null means it's not loaded, in the odd case it is you still want to check if it's visible. I suspect that this will return false when on the lobby screen. You could verify this yourself. Basically inverting this boolean will do the trick.
  2. Second, you should not return null as root task. Your root task should be a branch that checks for logged in and then returns a failure or success task based on that. Keep any logic outside of the main class regarding your tree.
  3. Third, look up the naming conventions in Java/Kotlin. Underscores in variable names are heavily frowned upon.
  4. Fourth, don't delay in your validate() method, you just want a simple boolean that either guides you to the success or failure task. Do any logical operations in the respective LeafTask execute() blocks.
  5. Fifth, you are getting the NullPointerException on the delay because you have not nullchecked 'p'. Invoking .isVisible() on a null 'p' results in this exception. You don't want the delay here anyways, so this won't be a problem anymore. But it is good to keep in mind that you need to nullcheck your instances before invoking functions on them.

Please correct me where I'm wrong @ any other developer if you find mistakes. :)
 
Joined
Jun 25, 2019
Messages
24
Thanks for the reply. I ended up creating a IsLoggedIn branch task:

Code:
public class IsLoggedIn extends BranchTask {

    private IsInventoryFull isInventoryFull = new IsInventoryFull();
    private WaitUntilLoggedIn waitUntilLoggedIn = new WaitUntilLoggedIn();

    Player p;

    @Override
    public boolean validate() {
        p = Players.getLocal();
        if (p != null) {
            if (p.isVisible()) {
                return true;
            }
        }
        return false;
    }

    @Override
    public TreeTask failureTask() {
        return waitUntilLoggedIn;
    }

    @Override
    public TreeTask successTask() {
        return isInventoryFull;
    }

}

its working well so far. As for the variable names I was going through the java tutorials last night and have started camel casing my vars :)
 
Top