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
  • How to interact with NPC


    FriedNuts

    Recommended Posts

    I've been trying to figure this out but can't seem to figure it out. I've seen multiple examples but they are using a deprecated class/method to obtain the NPC as shown below. Anyone point me to the right direction on how to interact with an NPC. 

    NPC cook = getNPCs().closest("Cook");
    cook.interact("Talk");

     

    Link to comment
    Share on other sites

    17 minutes ago, FriedNuts said:

    I've been trying to figure this out but can't seem to figure it out. I've seen multiple examples but they are using a deprecated class/method to obtain the NPC as shown below. Anyone point me to the right direction on how to interact with an NPC. 

    NPC cook = getNPCs().closest("Cook");
    cook.interact("Talk");

     

    Hey, very close!

    NPC cook = NPCs.closest("Cook");
    if(cook != null)
    {
        if(cook.interact("Talk"))
            log("Talking to cook");
    }

    2 things:
    1 - Always check if it has been found before attempting to interact or it will through null point exceptions if it can't be found
    2 - IMO its best to put the interact within an if statement as that way you KNOW you're interacting. Miss clicks can happen

    Link to comment
    Share on other sites

    1 minute ago, Axolotl said:

    Hey, very close!

    NPC cook = NPCs.closest("Cook");
    if(cook != null)
    {
        if(cook.interact("Talk"))
            log("Talking to cook");
    }

    2 things:
    1 - Always check if it has been found before attempting to interact or it will through null point exceptions if it can't be found
    2 - IMO its best to put the interact within an if statement as that way you KNOW you're interacting. Miss clicks can happen

    wow thank you. 

    Link to comment
    Share on other sites

    Archived

    This topic is now archived and is closed to further replies.

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