Jump to content

How to ensure player only chops in specified area?


xxslasherrmx

Recommended Posts

I am a newbie working on my first woodcutting script, and everything is going good so far. However, using Objects.closest() sends the player on a wild Tree hunt as the nearest tree is a good distance away. 

How can I ensure that the bot only clicks on Trees inside the designated area? Thanks smile.png

Edited by xxslasherrmx
Link to comment
Share on other sites

private RS2Object tree;
private Area someArea = new Area(x1, y1, x2, y2;


public boolean chopTree(){
   List<RS2Object> trees = getObjects().getAll().stream().filter(ob -> ob != null && ob.getName().equalsIgnoreCase("Tree") && canChop(ob)).collect(Collectors.toList());

   if(!myPlayer().isAnimating() && trees.size() > 0){
      RS2Object tree = trees.get(Script.random(trees.size()));
      if(tree.interact("Chop down"){
         //sleep or something
         return true;
      }
   }

   return false;
} 

public boolean canChop(RS2Object tree){
     return someArea.contains(tree);
}

Alternative to @FrostBugs happy.png All code from my head so just double check.

Edited by Extreme Scripts
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...