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


    tehcrab

    Recommended Posts

    Posted

    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
     break;
    
    } 
    
    else {               // If it doesn't match we add +1 to our counter and we try again;
    d++;
    }
       	}
    

    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

    Posted

    b10bc7d72f0abcb28b5307bb4e8dddef.png

    to much aids to read that like that lol

    Posted

    b10bc7d72f0abcb28b5307bb4e8dddef.png

    to much aids to read that like that lol

     

    hahahah i have no idea how to sort it, tell me how and i will :D

    Posted

    shit

    cookies

    Posted

    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

    Posted

    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

    Posted

    looks just as aids there

     

     

    not with 100% accuracy over 6h

    Make sure you select 'java' to highlight syntax

    Posted

    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

    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.