Jump to content

NPE during world hop


Zummy

Recommended Posts

Hey guys I've been struggling with this NPE for a week now and I can't seem to find what I'm doing wrong.

I have a method defining a new Player variable: Player toTrade  = getPlayers().closest(this.trade_name);

However during world hop this method is throwing nullpointers at the getName() api method.

I tried nullchecking the this.trade_name and checking getClient().getLoginState() LOADING, LOADING_MAP and LOGGED_IN.

It seems to me that getName() can't be reached due to world hopping but I could be wrong. Please help! Thanks <3

Edited by Zummy
Link to comment
Share on other sites

1 hour ago, Alek said:

Can you elaborate exactly what you are doing? Are you running the client on mirror mode, no randoms, low cpu? Are you using Worlds hop method or do you have your own world hopping method?  You said you're using getName() but your code snipped doesn't show it. 

I'm sorry, I'll elaborate. I am trying to have one player trade the other but the first one is required to change to a specific world before he does. I'm using stealth injection, no randoms, low cpu and low resources. I'm also using the normal world hopping method osbot provides. The two methods below are part of a loop that is active during the world hopping. The nullpointer is pointed at:

Player trader = getPlayers().closest(this.trader_name);

This is the world changing code:

public void changeWorld(){
        Area bankArea = new Area(3088, 3246, 3097, 3240);

        if (getWorlds().getCurrentWorld() != 335 && bankArea.contains(myPlayer())) {
            if (getWorlds().hop(335)) {
                new ConditionalSleep(4000, 100) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getWorlds().getCurrentWorld() == 335;
                    }
                }.sleep();
            }
        }
    }

The trading code with LoginState checks:

public boolean loggedIn(){
        return getClient().getLoginState() == Client.LoginState.LOGGED_IN && getClient().getLoginState() != Client.LoginState.LOADING &&
                getClient().getLoginState() != Client.LoginState.LOADING_MAP && getClient().getLoginState() != Client.LoginState.LOGGED_OUT;
    }

    public void tradePlayer() throws InterruptedException {
        Player trader = getPlayers().closest(this.trader_name);

        if (this.trader_name != null && trader != null && trader.isOnScreen() && trader.isVisible() && !getTrade().isCurrentlyTrading() && getInventory().isEmptyExcept(notDeposit)) {
            if (trader.interact("Trade with")) {
                new ConditionalSleep(12000, 1000) {
                    @Override
                    public boolean condition() throws InterruptedException {
                        return getTrade().isCurrentlyTrading();
                    }
                }.sleep();
            }
        }
    }

The stack trace:

[ERROR][Bot #1][09/19 08:54:41 PM]: Error in script executor!
java.lang.NullPointerException
at org.osbot.rs07.api.model.Player.getName(vo:65)
at org.osbot.rs07.api.filter.NameFilter.match(mo:118)
at org.osbot.rs07.api.filter.NameFilter.match(mo:122)
at org.osbot.rs07.api.filter.FilterAPI.filter(dk:70)
at org.osbot.rs07.api.EntityAPI.closest(jm:162)
at org.osbot.rs07.api.EntityAPI.closest(jm:271)
at org.osbot.rs07.api.EntityAPI.closest(jm:259)
at Main.tradePlayer(Main.java:728)
at Main.onLoop(Main.java:106)
at org.osbot.rs07.event.ScriptExecutor$InternalExecutor.run(we:242)
at java.lang.Thread.run(Unknown Source)

Please let me know if you need more information, thanks for taking a look!

Link to comment
Share on other sites

So a few things, OSBot (by default) will not execute the script unless you are fully logged in - so you don't need to rely on your custom method. It's possible that you are fully logged in, but the player data hasn't been sent yet (especially on populated areas/worlds). Normally this isn't an issue but you mentioned using low cpu mode, which may cause an issue. Try running OSBot without low cpu mode and see if that makes a difference.

Also remove this:

trader.isOnScreen() && trader.isVisible()

You're using interaction event which has its own set of guidelines on how to interact with entities, which may conflict with your code (trust me). If you don't want OSBot to move the camera/walk to the entity then do something like:

InteractionEvent event = new InteractionEvent(trader);
event.setCamera(false);
event.setWalking(false);
execute(event);

Something like that, I don't remember the exact syntax off hand.


But back on topic, let me know how running it normally goes.
 

 

Link to comment
Share on other sites

2 hours ago, Alek said:

So a few things, OSBot (by default) will not execute the script unless you are fully logged in - so you don't need to rely on your custom method. It's possible that you are fully logged in, but the player data hasn't been sent yet (especially on populated areas/worlds). Normally this isn't an issue but you mentioned using low cpu mode, which may cause an issue. Try running OSBot without low cpu mode and see if that makes a difference.

Also remove this:

trader.isOnScreen() && trader.isVisible()

You're using interaction event which has its own set of guidelines on how to interact with entities, which may conflict with your code (trust me). If you don't want OSBot to move the camera/walk to the entity then do something like:

InteractionEvent event = new InteractionEvent(trader);
event.setCamera(false);
event.setWalking(false);
execute(event);

Something like that, I don't remember the exact syntax off hand.


But back on topic, let me know how running it normally goes.
 

 

Good call! Low cpu is actually causing this! I've been pulling my hairs out over this one haha. Now how to circumvent this while still using low cpu? Any thoughts?

Actually scratch that, after some more testing, it also happens (but not always) with low cpu turned off.

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