Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Try asking for help in the chatbox
  • npc.interact doesn't work


    Likeyou343
     Share

    Recommended Posts

    I have this kind of code here and for some reason the npc interaction doesn't work.

    NPC npc = getNpcs().closest(new String[]{"Name1", "Name2"});
    if (npc != null) {
        // npc.toString() outputs Name1: [id]
        // code reaches up till here
        npc.interact("Trade");
        // code does not reach here
    }
    

    I tried making getNpcs().closest("Name1") only but it still does not work.

    Code doesn't go further if I try to do npc.isOnScreen() as well

     

    Edit: randomly started working. Did not change anything

    Edited by Likeyou343
    Link to comment
    Share on other sites

    I have this kind of code here and for some reason the npc interaction doesn't work.

    NPC npc = getNpcs().closest(new String[]{"Name1", "Name2"});
    if (npc != null) {
        // npc.toString() outputs Name1: [id]
        // code reaches up till here
        npc.interact("Trade");
        // code does not reach here
    }
    

    I tried making getNpcs().closest("Name1") only but it still does not work.

    Code doesn't go further if I try to do npc.isOnScreen() as well

    Do any npcs actually have a "trade" option? It sounds like you may be trying to trade with a player. If that is the case, you should use `getPlayers()` and not `getNpcs()`.

    Link to comment
    Share on other sites

    Do any npcs actually have a "trade" option? It sounds like you may be trying to trade with a player. If that is the case, you should use `getPlayers()` and not `getNpcs()`.

    It is npcs with trade option

    Link to comment
    Share on other sites

    Do any npcs actually have a "trade" option? It sounds like you may be trying to trade with a player. If that is the case, you should use `getPlayers()` and not `getNpcs()`.

    According to his code commentation, he has successfully found the Entity that he's looking for. So the getNpcs() method looks all good. 

     

     

    @OP: Did you get an error message in the client? If not, run the client in debug mode so we can see any errors through the cmd prompt.

    Edited by DefCon
    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.