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
  • Need help using states and finding npc's


    bzmake

    Recommended Posts

    Posted

    Hello Dreambot users,

     

    I'm trying to learn to script for Dreambot and using it's API.

     

    How do I make my bot look for a NPC (monster) and return the state to ATTACK it?

     

     

    or something like :

     

     private state ATTACK(){
             if (getLocalPlayer().myPlayer().isInCombat()) {
                 //find npc
                 NPC cow = getNpcs().getClosest(new Filter<NPC>() {     

     

     

    I'm so confused

    Posted

    In your onLoop() 

    switch(getState()) {

    case ATTACK:

     if (getLocalPlayer().myPlayer().isInCombat()) {
                   NPC cow = getNpcs().getClosest(Cow);

                  //checks if cow isnt null and cow is on screen

                   if(cow!=null && cow.isOnScreen()) 

                   {

                  cow.interact("Attack");

    }

      

     

    break;

    }

     

    Something like that

    Posted

    In your onLoop() 

    switch(getState()) {

    case ATTACK:

     if (getLocalPlayer().myPlayer().isInCombat()) {

                   NPC cow = getNpcs().getClosest(Cow);

                  //checks if cow isnt null and cow is on screen

                   if(cow!=null && cow.isOnScreen()) 

                   {

                  cow.interact("Attack");

    }

      

     

    break;

    }

     

    Something like that

     

     

    Thanks! will try it out!

     

     

    Can I ask you to review my script maybe?

    Posted

    Thanks! will try it out!

     

     

    Can I ask you to review my script maybe?

    Sure.

    Posted

    I'd recommend to first take a read at this link: http://www.tutorialspoint.com/java/java_decision_making.htm

     

     

    How do I make my bot look for a NPC (monster) and return the state to ATTACK it?

    //This is how you will get the NPC in-game
    NPC cow = getNpcs().closest("Cow");
    
    //To attack it
    cow.interact("Attack");

    Also for your player, you can directly call getLocalPlayer(), or getPlayers().myPlayer(), instead of calling getLocalPlayer().myPlayer().

     

    Another thing to point out is to watch out the condition in the if:

    private state ATTACK(){
        if (!getLocalPlayer().isInCombat()) {  //if my player is NOT in combat, then I will want to interact w/ an NPC
        //find npc and attack it
        NPC cow = getNpcs().getClosest("Cow")
        cow.interact("Attack");
    
        //to avoid getting the player do a lot of clicks to attack the monster, you can add a sleep condiiton
    sleepUntil(new Condition(){
    @Override
    public boolean verify() {
    return getLocalPlayer().isInCombat();
    }
    }, 3000); //the amount of milliseconds the player will wait to click the monster again}
    }

    For the sleepUntil & other methods, check here: http://dreambot.org/javadocs/org/dreambot/api/methods/MethodProvider.html

     

    Then you could add an Else statement, and add some sleeps there (that would be while your player is certainly in combat)

    Posted

    In your onLoop() 

    switch(getState()) {

    case ATTACK:

     if (!getLocalPlayer().myPlayer().isInCombat()) {

                   NPC cow = getNpcs().getClosest(Cow);

                  //checks if cow isnt null and cow is on screen

                   if(cow!=null && cow.isOnScreen()) 

                   {

                  cow.interact("Attack");

    }

      

     

    break;

    }

     

    Something like that

     

    Fixed that for you.

     

    Nice explanation @Fran. =)

    Posted

    Fixed that for you.

     

    Nice explanation @Fran. =)

    Shouldn't copied his code xD

    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.