Jump to content
MidnightBlue

Midnight Blue's custom script skeleton, good for beginner scripts! :-)

Recommended Posts

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!

  • Like 1
Link to comment
Share on other sites

yeah i feel like this is as far away from noob friendly as it gets. ohmy.png

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

Link to comment
Share on other sites

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

  • Like 1
Link to comment
Share on other sites

for(Node n : nodes) {	loop();	return n.loop();}
This will call loop() twice.

Probably not what you want tongue.png

Not sure why you are using reflection to add the nodes though, but I'm also not sure why you shouldn't ph34r.png 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 by fixthissite
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...