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
  • Try asking for help in the chatbox
  • [Tutorial] Creating The Base Of a AIO Using Node Script pt. 2


    Notorious
     Share

    Recommended Posts

    Creating a AIO Script using NodeScript. (Fishing) pt.2

     
    Well if you read the first part of this tutorial, we left off right before we started creating the accept() method inside of FishNode class. Some of the things that we need to check before interacting with a fishing spot is:
    • Are we inside of the designated Area?
    • Do we have all of our equipment?
    • Do we have enough inventory space?
    • Are we moving?
    • Are we interacting?
    • Are we less than 5 tiles away from best spot?
    Since there are quite a few qualifications for being able to fish or not, which could take a few lines. If we remember the KISS(Keep It Simple Stupid) rule, we don't want to repeat ourselves a ton of times, nor make it overly complex. So lets start with checking equipment, and since this will be used in multiple nodes, it is smart to place it in a area which can be accessed from most places of the script if need be. I chose to use MainScript for this, as we already pass a instance into our node.
    Inside our settings, we use a List for our equipment, and this can use quite a few lines, since we need to iterate through each item in the list to check if our inventory contains it. For this we are going to use one of the advantages of Java 8, by adding this to our MainScript class:

        public boolean checkEquipment () {
            return !settings.getEquipmentList().stream().filter(e -> !getInventory().contains(e.getId())).findFirst().isPresent();
        }
    

     
    Once this is added, we can add a few other classes/methods we will need. For one, being the type of fishing we are going to do, for this we can create a enum holding different values, and store the value inside of user settings. The class should look similar to this:

    /**
     * Created with IntelliJ IDEA.
     * User: NotoriousPP
     * Date: 12/11/2014
     * Time: 9:23 PM
     */
    public enum FishingType {
    
        NET,
        LURE,
        BAIT,
        CAGE,
        HARPOON;
    
        @Override
        public String toString() {
            String s = super.toString().replace('_',' ');
            return s.charAt(0) + s.substring(1, s.length()).toLowerCase();
        }
    }
    

    We can now use this FishingType to differentiate the types of fishing spots, so we do no need to rely on IDs which are not very stable. While were on the subject of fishing spots, lets add our optimal fishing spot finder method. I quickly came up with this, and by no means the best or only method that should be used.

        private NPC getBestFishingSpot (String action) {
            return getNpcs().getClosest(npc -> npc.getName().equals("Fishing spot") &&
                    Arrays.asList(npc.getActions()).contains(action) &&
                    npc.getModel() != null && npc.getModel().getVertexCount() < 50);
        }
    

     
    With these components all added we can now finish our accept method inside of our FishNode, which should now look similar to this: (currentSpot is a local variable I created inside of FishNode, which will be used to store the best fishing spot, so were not always trying to find a new spot)

     

     

        @Override
        public boolean accept() {
            if(script.getSettings().getFishingArea().getArea().contains(getPlayers().myPlayer())) {
                if(currentSpot == null || !currentSpot.exists())
                    currentSpot = getBestFishingSpot(script.getSettings().getFishingType().toString());
                return currentSpot != null &&
                        !getInventory().isFull() &&
                        script.checkEquipment() &&
                        !getPlayers().myPlayer().isMoving() &&
                        getPlayers().myPlayer().getInteractingCharacter() == null;
            }
            return false;
        }
    

     

     

     

    We now have a node which has a valid accept method, and will return true if we have a current fishing spot, inventory isn't full, we have our equipment, and our play is idle. Though now our node has a activation trigger, we now need a action to preform once this node has been triggered.

     

    To begin, we move onto our execute method! Since in our accept method, we ensure that we have a current fishing spot, we need to check it's distance to see if we need to walk, as well it's visibility. Once we evaluated those terms, we can then proceed to interacting with the fishing spot. After we have finished it our execute method should look similar to this! (I added a few methods which I thought should be included)

     

     

     

        @Override
        public int execute() {
            if(currentSpot != null){
                if(currentSpot.distance(getPlayers().myPlayer()) > 5)
                    getWalking().walkGlobalTile(currentSpot.getTile());
                if(!currentSpot.isOnScreen()) {
                    if (Math.random() > .40) // 60% chance of using the mouse to rotate, 40% chance of using keys
                        getCamera().mouseRotateToEntity(currentSpot);
                    else
                        getCamera().rotateToEntity(currentSpot);
                }
                if(currentSpot.distance(getPlayers().myPlayer()) < 5 && currentSpot.isOnScreen()){
                    currentSpot.interact(script.getSettings().getFishingType().toString());
                }
            }
            return (int)Calculations.gRandom(1000, 200);
        }
    

     

     

     

    Well congratulations! If you followed all these steps, you have now created a TaskNode! Though we cannot use them just yet, we have laid a expandable foundation of AIO script! But don't worry I'm not ending the tutorial just yet, we have another part! Before we end this part of the tutorial I want to review how we implement these nodes inside of our Main Script.

     

    So if we look at MainScript, we extended NodeScript, which means our onLoop is handled internally, though gives you the freedom to adjust how you want your nodes to be executed! Node script has a few methods that should be pointed out:

    • addNodes(TaskNodes... nodes) Adds nodes to executor list.
    • setFailLimit(int amount) Sets the amount of times the onLoop is allowed to fail before stopping the script. (Failure is define as not finding a node)

    So since we have already created a node, we can add it to our executor list. We do this by adding the call inside of our onStart method. Which now should look similar to this:

     

     

      @Override
        public void onStart() {
            settings = new UserSettings();
            /* Later we can handle this using a GUI */
            //We add our equipment we need to use
            settings.addEquipment(FishingEquipment.SMALL_NET);
            //We set which location we want to fish at
            settings.setFishingArea(FishingArea.DRAYNOR_VILLAGE);
            addNodes(new FishNode(this));
            setFailLimit(-1); // By settings this to -1, we ignore the fail counter, meaning it will not stop the script.
        }
    

     

     

     

    Once your node has been added, you may run your script, and the onLoop will be executed automatically! So no more is needed in order for your node to execute!

     

    So tomorrow I will be creating a Walking node, as well as a basic banking node so we can have a complete script! Then for our final part we will create a GUI to bring everything all together in a easy to use interface, so that settings/locations can be changed with ease.

     

    Thank you for you reading and I'll see you in part 3!

    (Please let me know what you think, any errors, suggestions, just your thoughts in general! Anything is appreciated! )

    Link to comment
    Share on other sites

    im guessing you are using something like

    public UserSettings getSettings() {
    		return settings;
    	}
    

    to get the settings?

     

    anyway good guide, i always just used states because i refused to spend time to learn how to use nodes...good job @Notorious!

    Link to comment
    Share on other sites

    • 2 weeks later...

    This one is great aswell did find 2 errors i believe:

    When you make the accept() method in the very last part: getPlayers().myPlayer().getInteractingCharacter() != null 

    shouldn't the interactingCharacter actually be null for it to be accepted.

     

    And there is a typo in the last code example: setFailLimit(-1); // By settings this to -1, we ignore the fail counter, meaning it will stop the script.

    Should be "Meaning it will not stop the script" i think.

     

    Thanks for the guide

    Link to comment
    Share on other sites

    • 2 months later...

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • 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.