Cloudnine Posted July 31, 2013 Share Posted July 31, 2013 (edited) 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. Edited July 31, 2013 by Cloudnine Link to comment Share on other sites More sharing options...
Andrew Posted July 31, 2013 Share Posted July 31, 2013 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. 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 More sharing options...
l3reed Posted July 31, 2013 Share Posted July 31, 2013 Thanks for this man. Link to comment Share on other sites More sharing options...
NxJr Posted July 31, 2013 Share Posted July 31, 2013 Lol did not know about the ctrl shift f thanks! Link to comment Share on other sites More sharing options...
Joseph Posted July 31, 2013 Share Posted July 31, 2013 Retyping I just save this in my eclipse as a new class file and when ever I need it I just copy and paste. And there tons of Skelton script out there in the forum. Link to comment Share on other sites More sharing options...
GoldenGates Posted July 31, 2013 Share Posted July 31, 2013 Meh, thanks, but I use nodes more often when making new classes. :P Link to comment Share on other sites More sharing options...
Cloudnine Posted July 31, 2013 Author Share Posted July 31, 2013 Yeah there probably are quite a few script skeletons out there, but mine's explained decently, and I put some helpful tips for new scripters on mine. Link to comment Share on other sites More sharing options...
A lazy Cat Posted August 1, 2013 Share Posted August 1, 2013 Usefull tys Link to comment Share on other sites More sharing options...
Thinkingofyou Posted August 2, 2013 Share Posted August 2, 2013 It would be nice if the runtime was put into hours/minutes/seconds. any idea how I can do that? Link to comment Share on other sites More sharing options...
Virus Posted August 3, 2013 Share Posted August 3, 2013 Thank you very much for this! I can now start creating my own scripts... Link to comment Share on other sites More sharing options...
A lazy Cat Posted August 3, 2013 Share Posted August 3, 2013 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 More sharing options...
Superman Posted August 26, 2013 Share Posted August 26, 2013 Yay I have been looking for this... Thanks! Link to comment Share on other sites More sharing options...
xSnipeLikeGod Posted September 16, 2013 Share Posted September 16, 2013 Thanks for this! Link to comment Share on other sites More sharing options...
Levi Posted September 16, 2013 Share Posted September 16, 2013 Thanks alot for this, it's been very beneficial to me and helped me out. Link to comment Share on other sites More sharing options...
lolmanden Posted September 16, 2013 Share Posted September 16, 2013 This is cool. Thanks for this snippet. Link to comment Share on other sites More sharing options...