Jump to content

Script Layout


Cloudnine

Recommended Posts

I hate retyping the basic script layout every time I write a new script so I made this class. I figured it could also benefit new scripters if I released it on the forums.
I'll explain the code in notes.

import java.awt.Graphics;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;

@ScriptManifest(author = "Cloudnine", info = "TemplateScript v0.1", name = "TemplateScript", version = 0.1)//How the script will show up when you go to start it
public class TemplateScript extends Script {
	long startTime;
	long runTime;

	public void onStart() {//This code executes when the script is started
		log("TemplateScript v0.1 by Cloudnine has initialized!");
		startTime = System.currentTimeMillis();
	}

	public void onExit() {//This code executes when the script is stopped
		log("Thank you for using TemplateScript v0.1 by Cloudnine!");
		log("Ran for " + runTime / 1000 + " seconds.");
	}

	public void onPaint(Graphics g) {//This is to "paint", or display, content on the screen
		runTime = System.currentTimeMillis() - startTime;
		g.drawString("TemplateScript v0.1", 450, 345);//X: 450 (left and right), Y: 345 (up and down)
		g.drawString("by Cloudnine", 450, 360);
		g.drawString("Run Time: " + (runTime / 1000), 450, 385);
	}

	public int onLoop() throws InterruptedException {
		/*
		 * Place Code Here
		 */
		return 100;//sleeps for 100ms, then restarts this loop
	}
}

Even if you don't need the explanation, you can put this in Eclipse and do Ctrl+F, Replace TemplateScript with ScriptName, rather than retyping this over and over.

If you want to see the functions OSBot provide you with, visit the api. http://osbot.org/api

 

If you are new to java, and want to learn enough to begin scripting, you can try out the Oracle Java Tutorials. That's where I learned. (Look it up on Google, it's easy to find).
Also, for the beginner programmers, download an IDE if you don't use one. That will help you script 10x more efficiently. It's practically impossible to program efficiently without an IDE. An IDE is a text editor made for programmers. Ex: Eclipse, Netbeans, etc.. I prefer Eclipse.

Random Tip: If you use Eclipse, press Ctrl+Shift+F to automatically format your code neatly. smile.png

Edited by Cloudnine
Link to comment
Share on other sites

I hate retyping the basic script layout every time I write a new script so I made this class. I figured it could also benefit new scripters if I released it on the forums.

I'll explain the code in notes.

import java.awt.Graphics;

import org.osbot.script.Script;
import org.osbot.script.ScriptManifest;

@ScriptManifest(author = "Cloudnine", info = "TemplateScript v0.1", name = "TemplateScript", version = 0.1)//How the script will show up when you go to start it
public class TemplateScript extends Script {
	long startTime;
	long runTime;

	public void onStart() {//This code executes when the script is started
		log("TemplateScript v0.1 by Cloudnine has initialized!");
		startTime = System.currentTimeMillis();
	}

	public void onExit() {//This code executes when the script is stopped
		log("Thank you for using TemplateScript v0.1 by Cloudnine!");
		log("Ran for " + runTime / 1000 + " seconds.");
	}

	public void onPaint(Graphics g) {//This is to "paint", or display, content on the screen
		runTime = System.currentTimeMillis() - startTime;
		g.drawString("TemplateScript v0.1", 450, 345);//X: 450 (left and right), Y: 345 (up and down)
		g.drawString("by Cloudnine", 450, 360);
		g.drawString("Run Time: " + (runTime / 1000), 450, 385);
	}

	public int onLoop() throws InterruptedException {
		/*
		 * Place Code Here
		 */
		return 100;//sleeps for 100ms, then restarts this loop
	}
}

Even if you don't need the explanation, you can put this in Eclipse and do Ctrl+F, Replace TemplateScript with ScriptName, rather than retyping this over and over.

If you want to see the functions OSBot provide you with, visit the api. http://osbot.org/api

 

If you are new to java, and want to learn enough to begin scripting, you can try out the Oracle Java Tutorials. That's where I learned. (Look it up on Google, it's easy to find).

Also, for the beginner programmers, download an IDE if you don't use one. That will help you script 10x more efficiently. It's practically impossible to program efficiently without an IDE. An IDE is a text editor made for programmers. Ex: Eclipse, Netbeans, etc.. I prefer Eclipse.

Random Tip: If you use Eclipse, press Ctrl+Shift+F to automatically format your code neatly. smile.png

 

Thanks for template, however I believe there is already a skeleton on the forums but not as in depth.

Link to comment
Share on other sites

lol

 

 

handleHaters(){
if(client.getBot().getUsername().equals("Kati"){
log("Gg.");
System.exit(0);//Sorry, please don't ban me...
} else if (client.getBot().getUsername().equals("XavierM"){
log("Your scripts are overpriced.");
} else if (client.getBot().getUsername().equals("Led Zeppelin") {
log("Post whore.");
} else {
log("GTFO. This script isn't for you.");
}
}

 

Link to comment
Share on other sites

  • 4 weeks later...
  • 3 weeks later...
Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

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