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
  • Inefficient code


    Recommended Posts

    public int onLoop() {
    List<GameObject> trees = getGameObjects().all(GameObjects -> GameObjects != null && GameObjects.getName().equals("Tree"));         // Gets all the trees nearby
    List<Double> distance = new ArrayList();                // A new list to hold the distance of every tree
    for (int i = 0; i < trees.size(); i++) {
    distance.add(trees.get(i).distance());                 // Here we add all the distances to the distance list
       Collections.sort(distance);              // We sort it
    	int d = 0;       // d is the number we use to look through our tree list
    	int index = 0;       // index is the numer we use to decide where we insert stuff
    while (true) {
    if (distance.get(index) == trees.get(d).distance()) {              // if the distance in the distance list matches the distance in the tree list
     trees.add(index, trees.get(d));                         // We resort our tree list, we add the shortest tree to the first place in the tree list
     trees.remove(d + 1);                          // We remove that tree 
     index++;                         // We add one to the index so we wont mess up our sorted tree list
     d = 0;                         // We reset the counter which goes through the tree array
    if (d <= trees.size())           // If our counter reaches the end of the tree list we break out of the loop
    else {               // If it doesn't match we add +1 to our counter and we try again;

    This probably looks messy as hell but i tried to explain the most of it, so the thing I'm basically trying to do is have my wc bot not go to the closest tree all the time to make it more human like if that makes sense. I hope that there's an easy way to do this I just wanted to see if I would be able to code it myself and to some extent it works.


    My idea was to sort the tree list full of trees to the closest ones and then have a random number generator choose one of the three closest trees. For some reason it only manages to sort the first closest tree in the tree list, so obviously there's something wrong with my code the screenshot shows how far i am from the first 11 trees in the tree list.


    I started trying to code yesterday so don't bully me too much, but if anyone knows a simple way to not target the first tree 24/7, or see whats wrong with my code it'd be great :D


    EDIT - screenshot of log  - http://i.imgur.com/PFnnqZT.png also tried to make it more clean

    Link to comment
    Share on other sites

    also its more human like to go to the first tree, like cmon if ur legit woodcutting clearly u gonna click on the nearest thing

    Link to comment
    Share on other sites

    Upload it to pastebin lol

    looks just as aids there



    also its more human like to go to the first tree, like cmon if ur legit woodcutting clearly u gonna click on the nearest thing

    not with 100% accuracy over 6h

    Link to comment
    Share on other sites

    Make sure you select 'java' to highlight syntax

    There isn't an option for java, I took the next best thing javascript idk if it helps

    Link to comment
    Share on other sites


    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.