GoldenGates 72 Posted November 26, 2014 In scripting throughout many clients, Nodes have been a popular framework to organize and run scripts. Though this isn't the most efficient way, it's certainly quite simple for beginners to start with as I did many years ago. I decided to quickly write this tutorial on how to setup your Node framework and get scripting. Please excuse the lousy formatting, just didn't have that much time. 1. Create your Node class for your framework, now this may seem a bit confusing, but don't fret, you'll understand why this is here. I'll go through this line by line: //Your import of AbstractScript import org.dreambot.api.script.AbstractScript; //Class must be abstract public abstract class Node { //Your global AbstractScript, this comes from the import protected AbstractScript aS; //Your Constructor, this 'connects' your Node in your script to AbstractClass since you cannot access it directly (eg. importing) from your Node public Node(AbstractScript aS) { //Set the local aS to the global aS since this is what you'll be using in your Node this.aS = aS; } //An abstract method, doesn't need to be initiated with curly braces or anything public abstract boolean activate() throws InterruptedException; //An abstract method, doesn't need to be initiated with curly braces or anything public abstract void execute() throws InterruptedException; } I don't expect you to grasp this yet if you're still new but for the time being, you'll figure it out some day when the light shines upon you. 2. Creating your Node class for your script, this is where the magic happens: //Again, your import import org.dreambot.api.script.AbstractScript; //Your class where you do what you want, in this case banking; must extend Node!!! public class Banking extends Node { //This will default be here, just don't touch this public Banking(AbstractScript aS) { super(aS); } //This is here by default as well, this is where you run your check to see if the Node should activate/run @Override public boolean activate() throws InterruptedException { //This will return true if based on the following conditions, basically like your if statement for running methods return aS.getInventory().getEmptySlots() != 28 || aS.getInventory().getEmptySlots() == 28 && aS.getBank().isOpen(); } //Default method, this is what will happen if the activate() method returns true @Override public void execute() throws InterruptedException { //If bank is open if (aS.getBank().isOpen()) { //If Inventory has at least 1 item in it if (aS.getInventory().getEmptySlots() != 28) { //Deposit everything aS.getBank().depositAll(); //Sleep till inventory is empty or until 1000ms passed MethodProvider.sleepUntil(new Condition() { public boolean verify() { return aS.getInventory().isEmpty(); } }, 1000); //Close the bank aS.getBank().close(); //Sleep till bank is closed or 750ms passed MethodProvider.sleepUntil(new Condition() { public boolean verify() { return !aS.getBank().isOpen(); } }, 750); } } else { //If bank isn't open, then interact with Banker aS.getNpcs().getClosest("Banker").interact("Bank"); //Sleep till bank is open or 1000ms passed MethodProvider.sleepUntil(new Condition() { public boolean verify() { return aS.getBank().isOpen(); } }, 1000); } } } This is a very basic example, and by no means complete, just a very vague example of what you'll be doing in nodes. So if the inventory contains an item in it OR if the inventory is empty and the bank is still open, then run the Banking node. The rest is explained in the execute() method. 3. Now we have to put it in our onLoop() method in our main class since that's what the script runs: //Create a Node Array to put all your nodes in, must reference 'this' as a parameter since 'this' is referring to AbstractScript (class should extend AbstractScript) private final Node[] array = new Node[] { new Banking(this) }; @Override public int onLoop() throws InterruptedException { //Goes through all the Nodes, checks if activate() is true, then runs it, simple. for (final Node node : array) if (node.activate()) node.execute(); return Calculations.random(250, 500); } The modifiers aren't really important, but what the variable is, is important. It's all been explained in the code. So now when you run the script, the onLoop() will run, then cycle through your list of Nodes, in our case Banking, see if node.activate() returns true, and if it does, it'll run the execute() method we wrote earlier. If it was false, it would continue on the next one and so on. Note: You should have at least 1 Node returning true at all times unless you are idling on purpose, which even then should have it's own Node since it gives/shows you full control of the script at all times. This is also very easy to fix bugs on as it's organized and neat and makes scripting that less painful. Thanks for reading this long and unnecessary guide, I put quite a bit of time into it and I'm just plain tired now so please give it a + rep and I'll really appreciate that. (Wrote this all in 1 go lol) If you have any tips/corrections you wish to improve on this guide, please post and I'll get back to you. Also don't hesitate to ask questions, me and other scripters would probably be more than willing to help!
Gh0st 7 Posted November 26, 2014 Any suggestions on what script could made using a node system? like a fletcher or what? and etc?
GoldenGates 72 Author Posted November 26, 2014 Any suggestions on what script could made using a node system? like a fletcher or what? and etc? Literally anything, almost all my scripts are node based. Well there may be a few things you can't but I can't think of any right now. And thanks guys. + rep it too.
Eliot 193 Posted November 26, 2014 Nice tutorial, nodes are cool. They're definitely a more object-oriented way of scripting. Maybe some day I will stop using states. Hehe.
GoldenGates 72 Author Posted November 26, 2014 Nice tutorial, nodes are cool. They're definitely a more object-oriented way of scripting. Maybe some day I will stop using states. Hehe. Damnit Eliot, y u still use states .-. I told u many teims.
Recommended Posts
Archived
This topic is now archived and is closed to further replies.