Welcome to TRiBot Forums

Register now to gain access to all of our features. Once registered and logged in, you will be able to contribute to this site by submitting your own content or replying to existing content. You'll be able to customize your profile, receive reputation points as a reward for submitting content, while also communicating with other members via your own private inbox, plus much more! This message will be removed once you have signed in.

Worthy

Node Framework Tutorial [increase efficiency and clarity]

75 posts in this topic

Node Framework Tutorial
by Worthy

 

What is Node Framework?
A node based framework breaks actions into different classes.
Each class extends a Node and has a validate and execute function.
 
In this tutorial
I will be writing a basic powerminer to demonstrate the effectiveness of using Nodes.
 
________
Node class:

 

package scripts.powerminer.api;

public abstract class Node {

	public abstract void execute();

	public abstract boolean validate();
	
}


 
Validate: if true, will run the execute method.
Execute: where the action happens
 
________
Second, we will plan and break down the actions we'll be creating.
In a powerminer, there are really only a couple classes necessary:

  • A GUI class (optional)
  • A MineOre class
  • A DropOre class

Since this is a basic tutorial, I'm going to skip the GUI class :P
And for simplicity's sake, I won't be externalizing any variables (I usually have separate classes for Constants and Variables).
 
The MineOre class:

 

package scripts.powerminer.nodes;

import org.tribot.api.General;
import org.tribot.api2007.Inventory;
import org.tribot.api2007.Objects;
import org.tribot.api2007.Player;
import org.tribot.api2007.types.RSObject;

import scripts.api.Node;

public class MineOre extends Node {
	private final int[] ROCK_IDS = {20843, 20844, 20845};	//tin ore 
	
	@Override
	public void execute() {
		final RSObject rock = findNearest(15, ROCK_IDS);
		if (rock != null && Player.getAnimation() == -1) {
			rock.click("Mine");
			
			int timeout = 0;
			while (Player.getAnimation() == -1) {	
				timeout++;
				General.sleep(10);
				if (timeout > 250)	//waits up to 2.5 seconds until the players animation changes
					break;			//prevents bot from spam clicking ore
			}
		}
	}

	@Override
	public boolean validate() {
		return !Inventory.isFull();
	}
	
	private RSObject findNearest(int distance, int ...ids) {
		RSObject[] objs = Objects.findNearest(distance, ids);
		if (objs.length > 0)
			return objs[0];
		return null;
	}
}

 


 
____
The DropOre class:

 

package scripts.powerminer.nodes;

import org.tribot.api2007.Inventory;

import scripts.api.Node;

public class DropOre extends Node {
	private final int[] PICKAXE_IDS = {1265};	//TODO add other pickaxes
	
	@Override
	public void execute() {
		Inventory.dropAllExcept(PICKAXE_IDS);
	}

	@Override
	public boolean validate() {
		return Inventory.isFull();
	}
}


 
____
Lastly, the main class, PowerMiner:

 

package scripts.powerminer;

import java.util.ArrayList;
import java.util.Collections;

import org.tribot.api.General;
import org.tribot.script.Script;
import org.tribot.script.ScriptManifest;

import scripts.api.Node;
import scripts.powerminer.nodes.DropOre;
import scripts.powerminer.nodes.MineOre;

@ScriptManifest (authors = {"Worthy"}, category = "Framework Example", name = "Basic Powerminer")
public class PowerMiner extends Script {
	private final List<Node> nodes = new ArrayList<>();
	 
	@Override
	public void run() {
		Collections.addAll(nodes, new MineOre(), new DropOre());
		loop(20, 40);
	}

	private void loop(int min, int max) {
		while (true) {
			for (final Node node : nodes) {
				if (node.validate()) {
					node.execute();
					sleep(General.random(min, max));	//time in between executing nodes
				}
			}
		}
	}
}

 


 
 
Tying everything together:
When the script is initiated we add all the nodes we want into the ArrayList of nodes.
The script then loops indefinitely, looping through each node in the ArrayList, validating it, and then executing.
 
The min and max parameters I have set in the loop method, ensure the bot waits at least 20 to 40 milliseconds in between nodes.
 
_________
As you can see you can do much much more with a node-based framework, but this tutorial shows the barebone basics.
For example: if you have an AIO script, you can have the GUI determine which nodes to add to the ArrayList. You can delete nodes to run if an action is completed, etc.
 
Full script on GitHub: https://github.com/WorthyTRiBot/PowerMiner

 

 

 

Regards,

Worthy

Edited by Worthy
3 people like this

Share this post


Link to post
Share on other sites

I use the node structure in my scripts :) Well written and easy to understand guide. Well done, will be great for intermediate scripters who are ready to branch away from the switch style scripting

Share this post


Link to post
Share on other sites

Very nice. You made it easy to understand .

I use the node structure in my scripts :) Well written and easy to understand guide. Well done, will be great for intermediate scripters who are ready to branch away from the switch style scripting

 

Glad you guys found it useful!

I've rejoined TRiBot (took a small break previously) and will continue to be posting some new a useful tutorials, as well as scripts.

Share this post


Link to post
Share on other sites

I really love the node framework concept, helped my script making alot. 

But i still have few problems.

 

Could you please extend the tutorial so it contains implementing a GUI?

It would really help alot.

 

Also someone make this a sticky, this is so amazing!

Share this post


Link to post
Share on other sites

I am very confused on how to use this... every time i try it, it claims that well ugh can you help me on the side or something?

Share this post


Link to post
Share on other sites

I am very confused on how to use this... every time i try it, it claims that well ugh can you help me on the side or something?

Add me on skype.

Share this post


Link to post
Share on other sites

This is the best way, if you want to keep your script legible/easy to maintain or update ALWAYS follow this method. I know a lot of newbies like to use states cos its easy, but as your script gets bigger I guarantee you will get lost in your code. Worthy the way you explain it is so clear and easy. Thanks :)

Share this post


Link to post
Share on other sites

Nice tutorial, although this framework doesn't have any effect efficiency wise.

Share this post


Link to post
Share on other sites

Nice tutorial, although this framework doesn't have any effect efficiency wise.

Debatable. Makes it more efficient for the user, finding bugs, organizing a clear and effective framework, etc.

Share this post


Link to post
Share on other sites

It might be because I learned Java in school, but, um, would the equivalent of not coding this way be just putting all your methods into one long class?

 

People actually do that? lol

Share this post


Link to post
Share on other sites

It might be because I learned Java in school, but, um, would the equivalent of not coding this way be just putting all your methods into one long class?

 

People actually do that? lol

It would be like that for every framework ever.

Share this post


Link to post
Share on other sites

um no...you can separate as much code as you want between any classes you want. 

 

It would be better to go even further, and make a framework that does the actions for you in scripts you code later on, instead of typing up all of the code required every time you want to do something.

 

Like Walking from Point A to Point B going a certain path, using the map a certain way at a certain position, you would define how those would be dealt with, make an update handler and when you are executing walking, you put those variable objects in.

 

Like Make a path of tiles named bankPath and a path of tiles named taskPath, or something. 

When you want to walk to the bank, you would say, scriptClass.walkTo(bankPath,Area'to use the minimap, or only tiles on the screen')

 

And you can also have the script update manager interfere with the script depending on whether it's banking/traversing/doing actions for the task, and do some really cool stuff like meandering around for no reason to throw jagex off your trail.

Edited by Karmik

Share this post


Link to post
Share on other sites

um no...you can separate as much code as you want between any classes you want. 

 

It would be better to go even further, and make a framework that does the actions for you in scripts you code later on, instead of typing up all of the code required every time you want to do something.

 

Like Walking from Point A to Point B going a certain path, using the map a certain way at a certain position, you would define how those would be dealt with, make an update handler and when you are executing walking, you put those variable objects in.

 

Like Make a path of tiles named bankPath and a path of tiles named taskPath, or something. 

When you want to walk to the bank, you would say, scriptClass.walkTo(bankPath,Area'to use the minimap, or only tiles on the screen')

 

And you can also have the script update manager interfere with the script depending on whether it's banking/traversing/doing actions for the task, and do some really cool stuff like meandering around for no reason to throw jagex off your trail.

34373859.jpg

2 people like this

Share this post


Link to post
Share on other sites

You clearly know nothing of the tribot API stop don't try to sound smart.

I don't have to know  anything about the tribot API (But I do). 

 

Using booleans and if statements isn't that hard. What does the API of tribot have to do with how you come up with a skeleton?

 

Just because I don't implement my code the same way you do doesn't mean anything.

 

http://pastebin.com/JytBYqZJ

http://pastebin.com/YpN2vfKt

http://pastebin.com/K3qvUGQ5

http://pastebin.com/B2wX8EQd

http://pastebin.com/yVuhuK1A

http://pastebin.com/FzFcTiK2

 

How much of tribot API matters with my skeleton?

 

The only code I use within my Utilities class (which holds most of the functions that hold calls to its actual API.) Uses calls to the API.

 

Am I stupid?

Edited by Karmik

Share this post


Link to post
Share on other sites

I don't have to know  anything about the tribot API (But I do). 

 

Using booleans and if statements isn't that hard. What does the API of tribot have to do with how you come up with a skeleton?

 

Just because I don't implement my code the same way you do doesn't mean anything.

 

http://pastebin.com/JytBYqZJ

http://pastebin.com/YpN2vfKt

http://pastebin.com/K3qvUGQ5

http://pastebin.com/B2wX8EQd

http://pastebin.com/yVuhuK1A

http://pastebin.com/FzFcTiK2

 

How much of tribot API matters with my skeleton?

 

The only code I use within my Utilities class (which holds most of the functions that hold calls to its actual API.) Uses calls to the API.

 

Am I stupid?

Yes

2 people like this

Share this post


Link to post
Share on other sites

*scratches head* 

 

Well I'm off to play some poker tourneys at the start of next year. Then playing cash games with the winnings, rinse and repeat. I guess that's my sign.

Share this post


Link to post
Share on other sites

*scratches head* 

 

Well I'm off to play some poker tourneys at the start of next year. Then playing cash games with the winnings, rinse and repeat. I guess that's my sign.

Good luck. When you create a good script using your advanced super amazing framework, tag me in the post and show me a long proggie and some (or all) of the source with your framework.

1 person likes this

Share this post


Link to post
Share on other sites

Sure thing dude, was planning to make it open source. It's more of a high level api similar to how TriBot's api is, except it does most of the stuff like swap item slots, bank in a customized manner (can be configured) or using parameters to set the style of banking. 

 

Parallel human emulative behavior (could be antiban) run during states and points in the task that won't obstruct the flow of the task that can be defined by the scripter.

 

So say you are wanting to chop trees, and while chopping, you have a boredom/add class that just throws RNG until it thinks it should click somewhere on accident (rare enough and chanced a certain way to allow alot of deviation between everyone using the script), while chopping the tree. That would be certainly possible.

 

Or while banking, you could tell the framework to omit an item(s) before going back to the task if it were to require multiple items. Then upon reaching the task, tell the framework not to go back unless the item was a key to get into the task area, or detrimental to the task. So like, if the player were to "forget" to bring pure ess while running nats or law runes, this would be some sort of antiban so it throws jagex off if they look for this at all.

 

I really like the idea of users be able to configure how the camera moves while the player walks at specific locations, what position they put their mouse when playing legit, or what objects they move the mouse/cam to. Would be cool to see a script that could be customized up to the point of frequency by the player (the script would avoid doing it 100% of the time though, based on numbers the user punches in).

 

I could brainstorm on this stuff all day and put in more and more implementations of it. 

Share this post


Link to post
Share on other sites

Sure thing dude, was planning to make it open source. It's more of a high level api similar to how TriBot's api is, except it does most of the stuff like swap item slots, bank in a customized manner (can be configured) or using parameters to set the style of banking. 

 

Parallel human emulative behavior (could be antiban) run during states and points in the task that won't obstruct the flow of the task that can be defined by the scripter.

 

So say you are wanting to chop trees, and while chopping, you have a boredom/add class that just throws RNG until it thinks it should click somewhere on accident (rare enough and chanced a certain way to allow alot of deviation between everyone using the script), while chopping the tree. That would be certainly possible.

 

Or while banking, you could tell the framework to omit an item(s) before going back to the task if it were to require multiple items. Then upon reaching the task, tell the framework not to go back unless the item was a key to get into the task area, or detrimental to the task. So like, if the player were to "forget" to bring pure ess while running nats or law runes, this would be some sort of antiban so it throws jagex off if they look for this at all.

 

I really like the idea of users be able to configure how the camera moves while the player walks at specific locations, what position they put their mouse when playing legit, or what objects they move the mouse/cam to. Would be cool to see a script that could be customized up to the point of frequency by the player (the script would avoid doing it 100% of the time though, based on numbers the user punches in).

 

I could brainstorm on this stuff all day and put in more and more implementations of it. 

The TRiBot API already does pretty much every thing your framework does, but alright.

Check out https://tribot.org/doc/

 

It has a built-in antiban as well. Check out the Inventory, Banking, and Camera classes specifically. They do everything you said. 

Edited by Worthy

Share this post


Link to post
Share on other sites

I'm talking about things like closing gates just because. Picking up an item not specified in the script as something to usually loot, and then puts it back on the ground to make space.

 

This stuff you call antiban already in the api? It's just 1 type of input initiation, nothing more. Sure, checking skills is done, whatever. I'm talking, while doing an agility task, "messing up" the timing on obstacles and starting all the way over, or w/e.

 

Not just, oh, I'll randomly have the script sleep here in terms of task execution, then just run the task.

 

Click a tree, if inventory is full bank, if not, click the next tree. Awesome, that's easy. .... What about timing on bird's nest drops, waiting until a point to "notice" the bird's nest. Banking before the inventory is actually full. Deviating the duration/load size before banking.

 

This is just a more immersed layout of the bot than the API.

 

And also, I'm working on a way to integrate me playing alongside the script while it's running, and the script tracks how I'm playing, and emulates me while I'm not paying attention.

I'm just separating points in the code and categorizing which is what and when so that my code can adapt to me playing in real time and know which objects to interact how I am, when, and how.

Not just me moving the mouse randomly, or moving the camera. (and also adjusting the angle and pattern of my mouse, so no more sharp mouse angles with no arc.)

 

I'm also paranoid jagex is tracking everything clientside, and sending the data to them while my player is not logged in. So I'm always trying to stay ahead without triggering them to flag me.

Edited by Karmik

Share this post


Link to post
Share on other sites

I'm talking about things like closing gates just because. Picking up an item not specified in the script as something to usually loot, and then puts it back on the ground to make space.

 

This stuff you call antiban already in the api? It's just 1 type of input initiation, nothing more. Sure, checking skills is done, whatever. I'm talking, while doing an agility task, "messing up" the timing on obstacles and starting all the way over, or w/e.

 

Not just, oh, I'll randomly have the script sleep here in terms of task execution, then just run the task.

 

Click a tree, if inventory is full bank, if not, click the next tree. Awesome, that's easy. .... What about timing on bird's nest drops, waiting until a point to "notice" the bird's nest. Banking before the inventory is actually full. Deviating the duration/load size before banking.

 

This is just a more immersed layout of the bot than the API.

 

And also, I'm working on a way to integrate me playing alongside the script while it's running, and the script tracks how I'm playing, and emulates me while I'm not paying attention.

I'm just separating points in the code and categorizing which is what and when so that my code can adapt to me playing in real time and know which objects to interact how I am, when, and how.

Not just me moving the mouse randomly, or moving the camera. (and also adjusting the angle and pattern of my mouse, so no more sharp mouse angles with no arc.)

 

I'm also paranoid jagex is tracking everything clientside, and sending the data to them while my player is not logged in. So I'm always trying to stay ahead without triggering them to flag me.

 

 

95% of what you plan to do is in the tribot API.

 

5% of your plans can be easily accomplished without making a new API or framework.

1 person likes this

Share this post


Link to post
Share on other sites

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

  • Recently Browsing   0 members

    No registered users viewing this page.