MidnightBlue Posted May 3, 2015 Share Posted May 3, 2015 Here's the new script skeleton you will be using, please import the class files down below as these are not in the OsBot API. In the scriptStart method, add your class, or classes that extend my custom Node class. (Example shown below) package ca.midnightblue.scripts.wc; import java.awt.Graphics2D; import org.osbot.rs07.script.ScriptManifest; import ca.midnightblue.scripts.wc.nodes.Idling; @ScriptManifest(name = "Custom Script Skeleton", author = "Midnight Blue", version = 1.0, info = "", logo = "") public class Core extends CustomScript { @Override public void scriptStart() { add(Woodcut.class, Walk.class, Bank.class); } @Override public void scriptStop() { } @Override public void loop() { } @Override public void paint(Graphics2D g) { } } Now in your classes that extend Node, which will contain the back bone aka the script functionality, the function "loop" that returns an integer is where you want to put what the bot does during that loop, you will return the amount of time you want the bot to sleep, by default it sleeps a random interval of 10 to 100MS. Your validate method will return when you want this script to activate. (You don't want to run all of your scripts at the same time) And lastly, your getStatus method should return a string with a brief description of what the bot is doing at the moment. Example: If your bot is banking return "banking". Here's an example of how to use my new script skeleton package ca.midnightblue.scripts.wc.nodes; import org.osbot.rs07.script.Script; public class Idling extends Node { private long then; public Idling(Script script) { super(script); then = System.currentTimeMillis(); } @Override public int loop() { long now = System.currentTimeMillis(); if(now - then <= 300000L) { //every 5 minutes then = now; //open tabs or something } return 0; } @Override public boolean validate() { return !script.myPlayer().isMoving(); } @Override public String getStatus() { return "Idling"; } } Node.java package ca.midnightblue.scripts.wc.nodes; import org.osbot.rs07.script.Script; public abstract class Node { protected final Script script; public Node(Script script) { this.script = script; } public abstract int loop(); public abstract boolean validate(); public abstract String getStatus(); } CustomScript.java package ca.midnightblue.scripts.wc; import java.awt.Graphics2D; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import org.osbot.rs07.script.Script; import ca.midnightblue.scripts.wc.nodes.Node; public abstract class CustomScript extends Script { protected ArrayList<Node> nodes = new ArrayList<Node>(); protected Script script; @Override public void onStart() { script = this; scriptStart(); } @Override public void onExit() { scriptStop(); } @Override public int onLoop() { for(Node n : nodes) { loop(); return n.loop(); } return random(10, 100); } @Override public void onPaint(Graphics2D g) { paint(g); } protected void add(Class<? extends Node>... node) { for(Class c : node) { try { Node n = (Node) c.getConstructor(Script.class).newInstance(script); if(!nodes.contains(n)) nodes.add(n); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException e) { e.printStackTrace(); } } } public abstract void scriptStart(); public abstract void scriptStop(); public abstract void loop(); public abstract void paint(Graphics2D g); } Hope you enjoy! :-) Please comment if you like this noob-friendly node snippet I made! 1 Quote Link to comment Share on other sites More sharing options...
AresScripts Posted May 3, 2015 Share Posted May 3, 2015 How is this different from the node framework? 1 Quote Link to comment Share on other sites More sharing options...
moore Posted May 3, 2015 Share Posted May 3, 2015 I think it is just more complicated for new scripters 1 Quote Link to comment Share on other sites More sharing options...
MidnightBlue Posted May 3, 2015 Author Share Posted May 3, 2015 How is this different from the node framework? I just like the how it's used, you don't need to add the parameter to each constructor when you initialize a new class that extends Node. Quote Link to comment Share on other sites More sharing options...
AresScripts Posted May 3, 2015 Share Posted May 3, 2015 I think it is just more complicated for new scriptersyeah i feel like this is as far away from noob friendly as it gets. Quote Link to comment Share on other sites More sharing options...
MidnightBlue Posted May 3, 2015 Author Share Posted May 3, 2015 yeah i feel like this is as far away from noob friendly as it gets. It's noob friendly if you're approaching making scripts from a java perspective, not copy and paste script kiddie. It's merely the same as the current node system except you only have to input the class name which in my mind makes it a lot easier :-P Quote Link to comment Share on other sites More sharing options...
AresScripts Posted May 3, 2015 Share Posted May 3, 2015 I just like the how it's used, you don't need to add the parameter to each constructor when you initialize a new class that extends Node. whats wrong with "new Banking(this)"? Quote Link to comment Share on other sites More sharing options...
MidnightBlue Posted May 3, 2015 Author Share Posted May 3, 2015 whats wrong with "new Banking(this)"? I think add(Cut.class, Walk.class, Bank.class) looks neather than add(new Cut(this), new Walk(this), new Bank(this); I'm sure I could add more features to this Node system, I only spent a few minutes on it. :P Quote Link to comment Share on other sites More sharing options...
AresScripts Posted May 3, 2015 Share Posted May 3, 2015 I think add(Cut.class, Walk.class, Bank.class) looks neather than add(new Cut(this), new Walk(this), new Bank(this); I'm sure I could add more features to this Node system, I only spent a few minutes on it. :P i can tell 1 Quote Link to comment Share on other sites More sharing options...
MidnightBlue Posted May 3, 2015 Author Share Posted May 3, 2015 i can tell Rather than bluntly criticizing it, why don't you give me some constructive criticism? What could be implemented in to this that OSBot does not currently support? Quote Link to comment Share on other sites More sharing options...
AresScripts Posted May 3, 2015 Share Posted May 3, 2015 Rather than bluntly criticizing it, why don't you give me some constructive criticism? What could be implemented in to this that OSBot does not currently support?the node framework doesnt need to be changed. This is a whole lot of work to get the same result. Quote Link to comment Share on other sites More sharing options...
AresScripts Posted May 3, 2015 Share Posted May 3, 2015 Rather than bluntly criticizing it, why don't you give me some constructive criticism? What could be implemented in to this that OSBot does not currently support? Nothing against you. I appreciate that you want to contribute, but when you say stuff like "this is the framework you will now be using" youre going to piss a few people off 1 Quote Link to comment Share on other sites More sharing options...
Botre Posted May 6, 2015 Share Posted May 6, 2015 (edited) for(Node n : nodes) { loop(); return n.loop(); } This will call loop() twice. Probably not what you want Not sure why you are using reflection to add the nodes though, but I'm also not sure why you shouldn't I will notify fixthissite of this thread :x Edited May 6, 2015 by Botre Quote Link to comment Share on other sites More sharing options...
fixthissite Posted May 7, 2015 Share Posted May 7, 2015 (edited) for(Node n : nodes) { loop(); return n.loop();}This will call loop() twice.Probably not what you want Not sure why you are using reflection to add the nodes though, but I'm also not sure why you shouldn't I will notify fixthissite of this thread :x There's no drawback; it just doesn't seem necessary in this case. My guess is he wanted to encapsulate the creation of node objects.Logically, the client (in this case, the Script class that uses the Node classes) shouldn't be in charge of the amount of instances of a specific node in the first place; being able to do "new MyNode()" is a design flaw itself. Only one instance of each node should exist, and there's no reason the client should be in charge of creating it. This allows you to increase encapsulation by preventing the client from being able to instantiate multiple objects of the same type and taking care of it for them in the framework. So yeah, that's my guess. As for performance, it's perfectly fine. I'd hardly refer to "newInstance()" as reflection, seeing how that's what goes on under the hood anyways. A lot of popular frameworks like Spring use reflection to provide a clean experience for the developer. Performance only takes an impact if you use it excessively through-out the entire application's life-cycle (such as in a loop, using reflection to constantly invoke a method). A few reflective actions performed only at the beginning of the application won't have any noticable effect on performance. I'm actually using reflection in my script related project as well ;) It's just for a more justifiable use.. Long story short, it could break encapsulation, but it can also increase it. Yes, performing things reflectively is more expensive than performing them through the actual language, but with a few simple benchmarks, you'll notice it's not as bad as some people might put it out to be. Just don't use it to continuously invoke methods (like invoking onLoop) or create multiple objects at a fast rate (like particle systems) Just a tip for the OP, you can't expect people to change based on a few tiny aspects Edited May 7, 2015 by fixthissite 1 Quote Link to comment Share on other sites More sharing options...