1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Tutorial How to quickly make TreeBot classes

Discussion in 'Tutorials & Resources' started by Swych, Feb 28, 2017.

  1. Swych

    Joined:
    Dec 9, 2016
    Messages:
    2,975
    Likes Received:
    1,024
    If, like me, you find it tedious to create a new empty Java class each time you want to create another branch or leaf then this tutorial is for you. Using IntelliJ you are able to manipulate the templates and create new templates to suit your custom needs. I'll show you how to do this and then supply the code you will need in order to create your automatic Branch and Leaf classes.

    1) Navigate to File -> Other Settings -> Default Settings.
    [​IMG]
    2) In the left-side panel of the window that has now opened navigate to Editor -> File and Code Templates.
    3) Select the green '+' .
    4) In this window name the new file whatever you want, preferably something easy to identify when making these classes later on. For this example I will be using 'RuneMate BranchTask' and 'RuneMate LeafTask'.
    5) Copy the code below like so into the relevant templates you've created. In the example I've created a template to use for Branch Tasks so I've pasted the Branch Task template.
    6) Ensure the file extension is java. There's no need to have it as '.java' as IntelliJ will automatically put it in there for you.
    [​IMG]
    7) Hit 'Apply' and 'Ok'. Now you'll be able to find your template classes when you go to create a new class.
    [​IMG]

    Happy botting!

    RESOURCES:
    Branch Tasks
    Code (Text):
    1. package ${PACKAGE_NAME};
    2.  
    3. import com.runemate.game.api.script.framework.tree.BranchTask;
    4. import com.runemate.game.api.script.framework.tree.TreeTask;
    5.  
    6. /**
    7. * Created by ${USER} on ${DATE}.
    8. */
    9. public class ${NAME} extends BranchTask {
    10.     @Override
    11.     public TreeTask failureTask() {
    12.         return null;
    13.     }
    14.  
    15.     @Override
    16.     public TreeTask successTask() {
    17.         return null;
    18.     }
    19.  
    20.     @Override
    21.     public boolean validate() {
    22.         return false;
    23.     }
    24. }
    Leaf Tasks
    Code (Text):
    1. package ${PACKAGE_NAME};
    2.  
    3. import com.runemate.game.api.script.framework.tree.LeafTask;
    4.  
    5. /**
    6. * Created by ${USER} on ${DATE}.
    7. */
    8. public class ${NAME} extends LeafTask {
    9.     @Override
    10.     public void execute() {
    11.        
    12.     }
    13. }
    14.  
    TreeBot
    Code (Text):
    1. package ${PACKAGE_NAME};
    2.  
    3. import com.runemate.game.api.script.framework.tree.TreeBot;
    4. import com.runemate.game.api.script.framework.tree.TreeTask;
    5.  
    6. /**
    7. * Created by ${USER} on ${DATE}.
    8. */
    9. public class ${NAME} extends TreeBot {
    10.     @Override
    11.     public TreeTask createRootTask() {
    12.         return new null;
    13.     }
    14. }
    15.  
     
  2. Geashaw

    Joined:
    Jan 8, 2015
    Messages:
    1,429
    Likes Received:
    252
    Gotta love lazy but efficient programmers. <3
     
  3. Swych

    Joined:
    Dec 9, 2016
    Messages:
    2,975
    Likes Received:
    1,024
    It's the only way to be!
     
  4. Yuuki Asuna

    Joined:
    Aug 11, 2016
    Messages:
    778
    Likes Received:
    110
    What about for eclipse? :O
     
  5. Swych

    Joined:
    Dec 9, 2016
    Messages:
    2,975
    Likes Received:
    1,024
    You're on your own there, unless you can find a tutorial ;)
     
  6. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    Not the best file template i have seen but should work for most users :p
     
  7. Geashaw

    Joined:
    Jan 8, 2015
    Messages:
    1,429
    Likes Received:
    252
    If you were to place a similar but better template here, what would you change?
     
  8. Savior

    Savior Java Warlord

    Joined:
    Nov 17, 2014
    Messages:
    4,906
    Likes Received:
    2,748
    For example parse the file heading instead of having it hard coded. A lot of devs have their own header.
     

Share This Page

Loading...