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

22 minutes ago, hobfmule said:

Why is


public static ArrayList<Node> nodes = new ArrayList<>();

static?

I'm guessing because generally nodes wouldn't be changing, but I'm sure it wouldn't make a difference if it wasn't static.

Share this post


Link to post
Share on other sites
1 hour ago, Tsuyoshi said:

I'm guessing because generally nodes wouldn't be changing, but I'm sure it wouldn't make a difference if it wasn't static.

Static in Java has nothing to do with the actual definition of the word static, just so you are aware.

Share this post


Link to post
Share on other sites
2 hours ago, hobfmule said:

Sequential nodes:

 

I am working on a rebuild class for when accounts are banned, obviously this is like one big quest script.  Each task is sequential: Tutorial island, train skill 1, train skill 2, quest 1, quest 2, etc.

 

When an account is first made, all task nodes' validate() methods would return true, since none of the tasks have been completed yet.  To prevent switching tasks prematurely, should the for-loop be modified? What is the best way to accomplish this? I was thinking:

 


for(final Node node : nodes) {

            if(node.validate()) {

                node.execute();

                //sleep for some amount
                
                break;

            } else {

                nodes.remove(node);

            }

        }

 

Is there a better way?  Sorry for being a total noob at node framework and tasking. 

No. In the validate methods for each node you should have specific conditions for when when that node should validate.

Do not modify the for loop.

 

For example, the tutorial island node would have the validate method to return true if and only if the bot is on tutorial island.

For the quest script, the validate method would return true if and only if that quest has not been completed (you can check settings for this).

Note you can combine multiple validate statements, so for instance if you set the skill node to level a certain skill if under X level, also include that the bot must not be on tutorial island, because then the bot will try the tutorial island node and the skill level node at the same time.

Share this post


Link to post
Share on other sites
On 3/18/2016 at 6:21 PM, l6bus tank said:

Can confirm this still works as intended. Thanks for the tut :)

Lol what, this stuff can't just stop working

 

2 hours ago, hobfmule said:

Sequential nodes:

 

I am working on a rebuild class for when accounts are banned, obviously this is like one big quest script.  Each task is sequential: Tutorial island, train skill 1, train skill 2, quest 1, quest 2, etc.

 

When an account is first made, all task nodes' validate() methods would return true, since none of the tasks have been completed yet.  To prevent switching tasks prematurely, should the for-loop be modified? What is the best way to accomplish this? I was thinking:

 


for(final Node node : nodes) {

            if(node.validate()) {

                node.execute();

                //sleep for some amount
                
                break;

            } else {

                nodes.remove(node);

            }

        }

 

Is there a better way?  Sorry for being a total noob at node framework and tasking. 

Node framework isn't enough for what you're trying to do

Share this post


Link to post
Share on other sites
4 minutes ago, Flamo353 said:

Lol what, this stuff can't just stop working

 

Node framework isn't enough for what you're trying to do

Wrong. Read my post above.

Share this post


Link to post
Share on other sites
38 minutes ago, TacoManStan said:

Static in Java has nothing to do with the actual definition of the word static, just so you are aware.

Whoops, I'm getting mixed up with final :s

Share this post


Link to post
Share on other sites
2 hours ago, Worthy said:

Wrong. Read my post above.

Untrue. Essentially, what he's trying to do is queue up multiple scripts. So he should have a variant of the node framework. 

Encoded's upgraded version of the node framework -> the task framework, would be a much better choice. Example:


public interface Task {

    int priority();

    boolean validate();

    void execute();

}

 

import java.util.Arrays;
import java.util.TreeSet;

public abstract class TaskSet extends TreeSet<Task> {

    public TaskSet() {
        super((o1, o2) -> Integer.compare(o2.priority(), o1.priority()) < 0 ? -1 : 1);
    }

    public TaskSet(Task... tasks) {
        this();
        addAll(tasks);
    }

    public boolean addAll(Task... tasks) {
        return super.addAll(Arrays.asList(tasks));
    }

    public Task getValidTask() {
        for (Task task : this)
            if (task.validate())
                return task;
        return null;
    }

    public abstract boolean isCompleted();

    public abstract void onCompletion();

}

Use of this upgraded framework would look something like this:

Main Class
sSAJdxj.png

tKERONV.png

Cooks Assistant Class
Enavr33.png

i1hb5nc.png

Fill Bucket Class
xGX9Sjb.png

M0JntNN.png

Edited by Flamo353

Share this post


Link to post
Share on other sites
1 minute ago, Flamo353 said:

Untrue. Essentially, what he's trying to do is queue up multiple scripts. So he should have a variant of the node framework. 

Encoded's upgraded version of the node framework -> the task framework, would be a much better choice. Example:



public interface Task {

    int priority();

    boolean validate();

    void execute();

}

 


import java.util.Arrays;
import java.util.TreeSet;

public abstract class TaskSet extends TreeSet<Task> {

    public TaskSet() {
        super((o1, o2) -> Integer.compare(o2.priority(), o1.priority()) < 0 ? -1 : 1);
    }

    public TaskSet(Task... tasks) {
        this();
        addAll(tasks);
    }

    public boolean addAll(Task... tasks) {
        return super.addAll(Arrays.asList(tasks));
    }

    public Task getValidTask() {
        for (Task task : this)
            if (task.validate())
                return task;
        return null;
    }

    public abstract boolean isCompleted();

    public abstract void onCompletion();

}

Use of this upgraded framework would look something like this:

Main Class



Cooks Assistant Class


Fill Bucket Class


 

Of course its entirely possible. Ever heard of an if statement?

Use your head and think. There any many ways to queue up things still using the node framework.

Share this post


Link to post
Share on other sites
Just now, Worthy said:

Use your head and think.

I could say the same to you. Your advice was to use an unaltered version of the node framework to write a bot farm script. What's the point of telling a new scripter to run head first into a wall?

Share this post


Link to post
Share on other sites
12 minutes ago, Flamo353 said:

I could say the same to you. Your advice was to use an unaltered version of the node framework to write a bot farm script. What's the point of telling a new scripter to run head first into a wall?

I'm not. You said using the node framework was impossible to do the requested, which is incorrect.

I have written many bot farm scripts with the node framework, it is easy to implement.

 

Of course there are many other frameworks to use and many possible ways to implement it, but to rule out this framework entirely because it takes a little extra work and you can't write another if statement or have an external variable keeping track of node priorities is just plain ignorant.

Share this post


Link to post
Share on other sites
16 minutes ago, Worthy said:

but to rule out this framework entirely because it takes a little extra work and you can't write another if statement or have an external variable keeping track of node priorities is just plain ignorant.

I admit, I poorly worded what I said earlier. My point is that the node framework alone just isn't abstract enough for what he's trying to do. Abstraction exists for many reasons: one of them being to create order. And with that order, comes readability and maintainability, which is why we use the task/node framework in the first place.

Share this post


Link to post
Share on other sites
Quote

Encoded's upgraded version of the node framework

How is that any different than using nested nodes?

public class RebuildManager {

    public static ArrayList<Node> nodes = new ArrayList<>();

    public RebuildManager(){

        Collections.addAll(nodes, new TutorialIslandManager(), new MagicTrainerManager(), new FishingTrainerManager());

    }

    public void loop() {

        for(final Node node : nodes) {

            if(node.validate()) {

                node.execute();

                //sleep for some amount

                break;

            } else {

                nodes.remove(node);

            }

        }

    }

    public boolean completed() {

        return nodes.size() == 0;

    }

}

ArrayLists are iterated sequentially, only one "task" node is focused on at a time, and old "tasks" are thrown out.  In my main Script class I only have to make an instance of RebuildManager and loop it until it loses all of its nodes.

e9lmC0s.png

5NeUByk.png

8FUF78W.png

97qshbM.png

etc. 

Share this post


Link to post
Share on other sites
8 hours ago, Flamo353 said:

I admit, I poorly worded what I said earlier. My point is that the node framework alone just isn't abstract enough for what he's trying to do. Abstraction exists for many reasons: one of them being to create order. And with that order, comes readability and maintainability, which is why we use the task/node framework in the first place.

Worthy was ensuring that beginners understand that to use this framework as intended, you don't modify the for-loop. This is so beginners don't get confused, especially when in the "I'll just copy this code" phase of learning.

1 person likes this

Share this post


Link to post
Share on other sites
9 hours ago, hobfmule said:

How is that any different than using nested nodes?


public class RebuildManager {

    public static ArrayList<Node> nodes = new ArrayList<>();

    public RebuildManager(){

        Collections.addAll(nodes, new TutorialIslandManager(), new MagicTrainerManager(), new FishingTrainerManager());

    }

    public void loop() {

        for(final Node node : nodes) {

            if(node.validate()) {

                node.execute();

                //sleep for some amount

                break;

            } else {

                nodes.remove(node);

            }

        }

    }

    public boolean completed() {

        return nodes.size() == 0;

    }

}

ArrayLists are iterated sequentially, only one "task" node is focused on at a time, and old "tasks" are thrown out.  In my main Script class I only have to make an instance of RebuildManager and loop it until it loses all of its nodes.

e9lmC0s.png

5NeUByk.png

8FUF78W.png

97qshbM.png

etc. 

If a node doesn't validate, it will be removed from the node list, which will fuck up your script in most cases. Your validate method is used to validate an execution, NOT the removal of the node from a node list. If you would like to add a condition that will dictate when a node that is no longer of any use, add a completion abstract boolean method to your "Node" class. Look at my previous post for an example.

If you're confused, join the teamspeak server "elitescripts.org" for voice chat scripting help. We can give you an in-depth explanation on any topic you're having trouble with. The server is owned by Warfront1, a premium scripter here on TRiBot. If you're not familiar with TS, then I suggest clicking the discord link in tacomanstan's signature and asking for help there. Best of luck to you.

2 people like this

Share this post


Link to post
Share on other sites

Finally some talk on this! (As far as I've seen), This is extremely useful for large scale scripts! I'm doing my best to learn how to write scripts at the moment and this is really helpful for what I plan to do with my farm, thanks for the examples man.

1 person likes this

Share this post


Link to post
Share on other sites

This framework is memory inefficient; Needing to loop through all the conditions in order to just reach one matching.

Share this post


Link to post
Share on other sites
7 hours ago, Zeroun said:

This framework is memory inefficient; Needing to loop through all the conditions in order to just reach one matching.

Yes calling all of these strenuous boolean returns.

Maybe might use .0001% of all my memory.

Share this post


Link to post
Share on other sites
34 minutes ago, Worthy said:

Yes calling all of these strenuous boolean returns.

Maybe might use .0001% of all my memory.

Even if, why would it need to go through all that when the route could just be predefined which means 1 jump. In those boolean returns you might be performing all kind of check operations.

So you're mining or whatever and every action requires iterating through all that, makes no sense in the efficience of the design pattern.

Edited by Zeroun

Share this post


Link to post
Share on other sites
8 minutes ago, Zeroun said:

Even if, why would it need to go through all that when the route could just be predefined which means 1 jump. In those boolean returns you might be performing all kind of operations for a return.

So you're mining or whatever and every action requires iterating through all that, makes no sense in the efficience of the design pattern.

The amount of memory used is negligible in regards to calling booleans.

Edited by Worthy

Share this post


Link to post
Share on other sites

This is nice, but could you give me a few pointers as I'm new to java. How would I use like MessageListening07 in each class? Also variables throughout all classes, so the main class + nodes can see the contents. I m use to using states all in a single class files and trying to get away from that.

Share this post


Link to post
Share on other sites
6 minutes ago, Duhstin said:

This is nice, but could you give me a few pointers as I'm new to java. How would I use like MessageListening07 in each class? Also variables throughout all classes, so the main class + nodes can see the contents. I m use to using states all in a single class files and trying to get away from that.

You can have an external class for Variables.

MessageListening07 is an interface, your class needs to implement it.

 

If you don't know what inheritance/interfaces are then you should read the java docs:

https://docs.oracle.com/javase/tutorial/index.html

Share this post


Link to post
Share on other sites

I really appreciate this tutorial, will be using this framework in future scripts

 

EDIT: Can you put another framework inside of a framework?

Edited by Lizzzerd
1 person likes this

Share this post


Link to post
Share on other sites

great tutorial! How would one go about creating a more effective anti ban or an anti ban in general?

Share this post


Link to post
Share on other sites
3 minutes ago, owned ya said:

great tutorial! How would one go about creating a more effective anti ban or an anti ban in general?

 

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.