Scripts for RSBot made by Famous |
New scripts being created everyday! Go to GameKiller.net! |
| | Tutorial 2: Writing your first script | |
|
+8sh2head streak224 Benny ImNewMem pattty Eons Ben Famous 12 posters | Author | Message |
---|
Famous Administrator
Posts : 50 Join date : 2009-10-23 Age : 29 Location : Chicago
| Subject: Tutorial 2: Writing your first script Fri Oct 23, 2009 9:31 pm | |
| Hopefully you understood the last tutorial of mine, so we can get through this as quick as possible. Anyways, every script starts out with a base. Currently, this is the base for all of those scripts. - Code:
-
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = { "YourNameHere" }, category = "CategoryHere", name = "ScriptNameHere", version = 1.0, description = " style='font-family: Arial; padding: 10px;'>Script Description Here") public class ScriptTemplate extends Script implements PaintListener {
private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts goes here return true; }
public void onFinish() { // All commands you want executed when the script finishes goes here }
public int loop() { // This is your main code return 0; }
public void onRepaint(Graphics g) { // Paint goes here. I'll explain paint in another tutorial. }
} Since you are new to scripting, let me explain what each of these do. They're pretty self explanatory if you really look at it, but I'll tell you anyway. • importThis just tells the script to take methods used from other locations and use them in this script. Just remember that you have to have imports or your script won't function properly. • @ScriptManifestRSBot added this during the last update. I don't know why, but you need it now in your scripts. Don't worry to much about this. • public class ScriptTemplate extends Script implements PaintListener {Okay. Don't freak out here. Let me try to explain this in the best way possible. •• public Tells whether or not other classes can use it. •• classTells the compiler to make it a class file. (There's a lot more to this, but I won't explain) •• ScriptTemplateThis is what you will name your script. •• extendsThis is a programming concept that you probably wouldn't understand. Don't worry about it. •• ScriptThis just tells RSBot that it's a script. •• implementsThis means that means it uses the following: •• PaintListenerWithout this included at the end of your script, you won't be able to have paint. • public boolean onStartThis tells the script what will happen when you start your script. • public void onFinishThis tells the script what will happen when you end your script. • public int loopThis is where your main code will be. I'll explain this later in the tutorial. • public void onRepaintThis is where you will put your paint. Now that I've explained that, let's move on. If you still don't understand it, read it over again and be sure to read carefully. Since mining scripts are usually the base for new script writers, I'll write one on mining. Let's go back to the base of our script. To start, I always name my script first. For this example, we will be making a tin miner. - Code:
-
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = { "Famous" }, category = "Mining", name = "TinMiner", version = 1.0, description = "A simple Tin Miner") public class TinMiner extends Script implements PaintListener {
private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts go here return true; }
public void onFinish() { // All commands you want executed when the script finishes go here }
public int loop() { // This is your main code return 0; }
public void onRepaint(Graphics g) { // Paint goes here. I'll explain paint in another tutorial. }
} As you can see above, all I did was name the script, put it into the category Mining, and give it a simple description. "A simple Tin Miner" is where you will place your description when you make your script. Now that we have named our script, put it into a category, and given it a description, we will need to get the ID of the tin rock, and of course, the pickaxe. To do this, we will go into RSBot, then open the tab "Debug", then check the name "Objects", and "Inventory" (We check inventory to show us the ID of the pickaxe). After you do this, you should see numbers over various objects on your screen. These are the IDs of those objects and items in your inventory. Because this is a tin miner, we will get the ID for tin. So, look for a tin rock, and in your script you are going to declare it. Do you remember which variable to use from the previous tutorial? Since it is a whole number, and not a decimal or negative number, we will use the variable "Integer." So let's go back into our script. I like to organize my scripts, so I put the different variables into sections. You don't have to do this, but it keeps things organized. - Code:
-
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = { "Famous" }, category = "Mining", name = "TinMiner", version = 1.0, description = "A simple Tin Miner") public class TinMiner extends Script implements PaintListener {
//Main Variables int tin = 11957; //<<<< Don't forget to put a semicolon after you are done. int pickaxe = 1265; //<<<< Again, since this is your first script, I will only use the ID of a bronze pickaxe. I will explain how to use the method to make it more than one object in a different tutorial.
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts go here return true; }
public void onFinish() { // All commands you want executed when the script finishes go here }
public int loop() { // This is your main code return 0; }
//Paint public void onRepaint(Graphics g) { // Paint goes here. I'll explain paint in another tutorial. }
} I know that there may be more than one tin rock in the mine that your using, but since this is your first script, I will only use one of these rocks. Lastly, we will need the animation for mining. To do this, we again open RSBot, then open the tab "Debug", then check "Animation." We then mine the rock to get the animation for mining. Once you get that animation, we will need to declare it in our script. - Code:
-
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = { "Famous" }, category = "Mining", name = "TinMiner", version = 1.0, description = "A simple Tin Miner") public class TinMiner extends Script implements PaintListener {
//Publics int tin = 11957; //<<<< Don't forget to put a semicolon after you are done. int pickaxe = 1265; //<<<< Again, since this is your first script, I will only use the ID of a bronze pickaxe. I will explain // how to use the method to make it more than one object in a different tutorial. int miningAnimation = 625; //<<<< This is the animation that we get when we mine a rock.
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts go here return true; }
public void onFinish() { // All commands you want executed when the script finishes go here }
public int loop() { // This is your main code return 0; }
//Paint public void onRepaint(Graphics g) { // Paint goes here. I'll explain paint in another tutorial. }
} Now that we have all of our IDs needed to write the script, we need to put it into our loop. This may be hard to understand, so I urge you to read it over maybe 2 or 3 times to understand it. Anyways, here we go. - Code:
-
public int loop() { final RSObject Rock = getNearestObjectByID(tin); if(!isInventoryFull() && !getMyPlayer().getAnimation() == miningAnimation){ atObject(Rock, "Mine"); } if(isInventoryFull()){ dropAllExcept(pickaxe); } return 1000; }
• final RSObject Rock = getNearestObjectByID(tin);All this is saying is to find the nearest tin rock, and that Rock can be used as a shortcut for saying tin. • if(!isInventoryFull() && !getMyPlayer().getAnimation() == miningAnimation)If your inventory is not full and you are not mining: • atObject(Rock, "Mine");Click the tin rock. • if(isInventoryFull())If your inventory is full: • dropAllExcept(pickaxe); Drop everything except your pickaxe
Well, this is the best that I could explain this, so experiment with it, and try your best. This is one of the hardest things to tackle and understand, but if you work on it, you should be fine. And don't forget, if you have any questions, don't be afraid to ask them! I'm always happy to help.
Last edited by Famous on Sat Jun 19, 2010 4:06 pm; edited 1 time in total | |
| | | Ben
Posts : 43 Join date : 2009-10-28 Age : 30 Location : United Kingdom
| Subject: Very Nice! Wed Oct 28, 2009 4:56 pm | |
| I don't know how I exactly came across your video, however I really enjoyed Tutorial 2, I haven't read Tutorial 1 yet, however I'm trying to develop my own Script, it's an Iron miner, so I'm just waiting for ya to update the Loop bit, I can't complete it because none of the other guides help Dw.. I'll do my research and I will read your tutorial 1. Ben.
Last edited by Ben on Wed Oct 28, 2009 9:22 pm; edited 1 time in total | |
| | | Ben
Posts : 43 Join date : 2009-10-28 Age : 30 Location : United Kingdom
| Subject: Re: Tutorial 2: Writing your first script Wed Oct 28, 2009 5:19 pm | |
| Forgot to mention, Keep up the good work. | |
| | | Eons
Posts : 6 Join date : 2009-12-12
| Subject: Re: Tutorial 2: Writing your first script Sat Dec 12, 2009 11:58 am | |
| Err, Famous. Its very easyy to understand. I read them all. Hoping for more tutorial. Will be donating | |
| | | pattty
Posts : 1 Join date : 2010-01-01
| Subject: Re: Tutorial 2: Writing your first script Fri Jan 01, 2010 1:53 am | |
| SOO much easier than other sites to understand it. Can't wait till you update the loop bit, i think ive got most of it down. But what program would i use to write all this in? | |
| | | Famous Administrator
Posts : 50 Join date : 2009-10-23 Age : 29 Location : Chicago
| Subject: Re: Tutorial 2: Writing your first script Fri Jan 01, 2010 2:28 am | |
| I use Eclipse. I prefer that over a lot of other IDE | |
| | | ImNewMem
Posts : 3 Join date : 2010-01-28
| Subject: Re: Tutorial 2: Writing your first script Sat Jan 30, 2010 6:33 pm | |
| Mind explaing a bit more about import | |
| | | Benny
Posts : 25 Join date : 2010-01-30 Age : 30 Location : Australia.
| Subject: Re: Tutorial 2: Writing your first script Thu Feb 04, 2010 12:28 pm | |
| LOL 40 Compiling errors on my first attempt at a script, but thanks for this guide, it has helped me understand scripting for rsbot alot, it is alot diffrent to PHP programming, probaly should have suspected that but. Can you please tell me if this is correct, I studied your mining script, and this was the conclusion i came to for multiple rock's, its probaly wrong, but not sure. - Code:
-
import java.awt.*; import java.util.*; import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*; @scriptManifest(authors = { "Unique!" }, category = "Mining", name = "Grand Tree Iron Power Miner", version = 1.0, description = "<html><body style='font-family: Arial; padding: 10px;'>A Simple Grand tree Power Miner.</body></html>") public class scriptTemplate extends script implements PaintListener { private final scriptManifest properties = getClass().getAnnotation(scriptManifest.class); //publics public int iron = 32443, 32442, 32441; // public int pickaxe = 1275; // public int miningAnimation = 624; // public boolean onStart(Map<String, String> args) { // All commands you want executed when the script starts goes here return true; } public void onFinish() { // All commands you want executed when the script finishes goes here } @Override public int loop() { if(Isinventoryfull()){ dropallexcept(1275) RSObject iron = getNearestObjectbyID(32443, 32442, 32441); if(iron == null){ return 500; } atObject(iron,"mine"); return 100; } public void onRepaint(Graphics g) { // Paint goes here. I'll explain paint in another tutorial. } } Down to 15 error's, cant workout how to fix them but. | |
| | | streak224
Posts : 2 Join date : 2010-02-22
| Subject: Re: Tutorial 2: Writing your first script Wed Feb 24, 2010 8:41 pm | |
| how come you do not mention how to write loops? | |
| | | sh2head
Posts : 3 Join date : 2010-03-15
| Subject: Re: Tutorial 2: Writing your first script Mon Mar 15, 2010 11:55 pm | |
| nice Tutorial !!!!!!! BUT how to wirte loops !!!! | |
| | | DaChubz
Posts : 1 Join date : 2010-05-20
| Subject: Re: Tutorial 2: Writing your first script Thu May 20, 2010 6:49 pm | |
| I think im too stuiped for this I have read all the tuts more than 3 times each and I still don't know what to do. I really need the dead basic of the begging script, I put this in Eclipse and I see all this slashes and all these letters when I really don't want them I need the begging code w/o all the things explaining it I will try and get them off myself | |
| | | infernalni
Posts : 1 Join date : 2010-07-28
| Subject: Re: Tutorial 2: Writing your first script Wed Jul 28, 2010 1:21 am | |
| [code]import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = "Iam PK Kingz" , category = "Mining", name = "KingMiner", version = 0.1, description = "<html><head>" + "</head><body>" + "<center><strong><h2>Iam PK Kingz First Script - KingMiner</h2></strong></center>" + "<center>Start in Varrock East Mining Area (Currently only mining area that works)</center>" + "<center><br /></center>" + "<center>Make SURE you have a pickaxe you can use. Will mine tin forever.</center>" + "<br /><center><b>Wish me luck on updates =]</b></center>" + "</body></html>")
public class KingMiner extends Script{
//Variables int[] pickaxe = {1265, 1267, 1269, 1271, 1273, 1275, 1296, 13661, 14107, 380302, 379433, 379181, 995, 14664, 2528}; int miningAnimation = 625; int[] tin = {11957, 11959}; private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class); public int loop() { final RSObject Rock = getNearestObjectByID(tin); if(isInventoryFull() && getMyPlayer().getAnimation() == miningAnimation) { atObject(Rock, "Mine"); } if(isInventoryFull()) { dropAllExcept(pickaxe); } return 1000; } }[/code]
This is what i got out of the tutorial and another one, BUT HOWEVER!!!! when it logs in, it does not start mining. i start at varrock east mining area right in front of a tin mine rock. help? | |
| | | Sanuka
Posts : 17 Join date : 2010-07-27 Age : 30 Location : Boskoop, the Netherlands
| Subject: Re: Tutorial 2: Writing your first script Sun Aug 01, 2010 1:02 pm | |
| Ok so, the script loops everything that is in the function "loop" wow! and for infernali, i'll get back to you in 'bout half an hour i have dinner atm edit: back, first off, you know how to check for id's right? (otherwise contact me ) the first thing i did is power up rsbot, and check the id's you have in the script. the second thing was checking the if statements woops problem found! :"if(isInventoryFull() && getMyPlayer().getAnimation() == miningAnimation)" this if statement checks if the inventory is full, and wether or not the player is mining. right now, your saying:if(myinventoryisfull and i am mining) mine a rock. now how does that make sense ? the corrected version is: if(!isInventoryFull() && getMyPlayer().getAnimation() != miningAnimation) explanation? ! is the programming equivelent of not. so it now checks to see wether or not both are false instead of true corrected script: - Code:
-
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = "Iam PK Kingz" , category = "Mining", name = "KingMiner", version = 0.1, description = "<html><head>" + "</head><body>" + "<center><strong><h2>Iam PK Kingz First Script - KingMiner</h2></strong></center>" + "<center>Start in Varrock East Mining Area (Currently only mining area that works)</center>" + "<center> </center>" + "<center>Make SURE you have a pickaxe you can use. Will mine tin forever.</center>" + " <center><b>Wish me luck on updates =]</b></center>" + " <center><h1>Credits to Sanuka for fixing my script :D</h1></center>" + "</body></html>")
public class KingMiner extends Script{
//Variables int[] pickaxe = {1265, 1267, 1269, 1271, 1273, 1275, 1296, 13661, 14107, 380302, 379433, 379181, 995, 14664, 2528}; int miningAnimation = 625; int[] tinRock = {11957, 11959}; //ok! int tinOre = 483;// just added this :P
private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public int loop() { final RSObject Rock = getNearestObjectByID(tinRock); //here's your problem! //if(isInventoryFull() && getMyPlayer().getAnimation() == miningAnimation) //this if statement checks if the inventory is full, and wether or not the player is mining. //right now, your saying:if(myinventoryisfull and i am mining) mine a rock. //the corrected version is below: if(!isInventoryFull() && getMyPlayer().getAnimation() != miningAnimation) { atObject(Rock, "Mine"); } if(isInventoryFull()) { log("InVen full, dropping!"); dropAllExcept(pickaxe); } return 1000; }
}
| |
| | | Switchbladed
Posts : 2 Join date : 2010-09-22
| Subject: Re: Tutorial 2: Writing your first script Wed Sep 22, 2010 10:06 pm | |
| Anyone wanna help me out? I havent got all the variable things and stuff yet and i dont have walking and banking.. But im lost atm i dunno what to do next, and im getting some errors.. i wanted to make a woodcutter that cuts all trees in lots of places. I also dont know how to make a paint... can anyone help me? Old (Don't fix this one I edited and made it better) - Spoiler:
- Code:
-
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = { "Switchbladed" }, category = "Woodcutting", name = "SuperSwitchChopper", version = 1.0, description = " style='font-family: Arial; padding: 10px;'>Chops all types of trees.") public class SuperSwitchChopper extends Script implements PaintListener {
//Variables int Tree = {}; int Logs = {}; int Oak = {}; int Oak Logs = {}; int Willow = {5551, 5552}; int Willow Logs = {1519}; int Maple = {}; int Maple Logs = {}; int Yew = {}; int Yew Logs = {}; int Magic = {}; int Magic Logs = {}; int Bronze hatchet = {}; int Iron hatchet = {}; int Steel hatchet = {}; int Black hatchet = {}; int Mithril hatchet = {}; int Adamant hatchet = {}; int Rune hatchet = {}; int Dragon hatchet = {}; int woodcuttingAnimation = 867;
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts goes here return true; }
public void onFinish() { // All commands you want executed when the script finishes goes here }
public int loop() { // final RSObject tree = getNearestObjectByID(Willow); if(!isInventoryFull() && !getMyPlayer().getAnimation() == woodcuttingAnimation){ atObject(Tree, "Chop down"); } if(isInventoryFull()){ dropAllExcept(Rune hatchet); }
return 1000; }
public void onRepaint(Graphics g) { // Paint goes here. I'll explain paint in another tutorial. }
}
New One (Fix this please I have no Idea what to do, Also I have a paint but I dunno if it works.. Help plz =] I need variables fixed too.. and all the errors...) - Spoiler:
- Code:
-
import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Point; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Map;
import org.rsbot.bot.Bot; import org.rsbot.bot.input.Mouse; import org.rsbot.event.listeners.PaintListener; import org.rsbot.script.Calculations; import org.rsbot.script.Constants; import org.rsbot.script.GEItemInfo; import org.rsbot.script.Script; import org.rsbot.script.wrappers.RSInterface; import org.rsbot.script.wrappers.RSObject; import org.rsbot.script.wrappers.RSTile;
@ScriptManifest(authors = { "Switchbladed" }, category = "Woodcutting", name = "SuperSwitchChopper", version = 1.0, description = "<html><head></head><body bgcolor='#222222'><center><table><tr><td width='350' valign='top'><center><div style='font-family:Calibri, Arial;color:#FF3300; font-size:36px'>SuperSwitchChopper</div><div style='font-family:Calibri, Arial;color:#FFFFFF; font-size:16px'>v1.0 by Switchbladed </div><div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Quick Select</div><div><table bordercolor='#FF3300' border='1' cellpadding='0' cellspacing='0' ><tr><td align='center' style='font-family:Calibri, Arial;color:#FFFFFF; font-size:12px'><b>Tree Locations</b> <select name='trees'><option>Trees 1<option>Trees 2<option>Trees 3</select> <select name='oaks'><option>Oaks 1</select> <select name='willows'><option>Willows 1<option>Willows 2<option>Willows 3</select> <strong>Hatchet Retrieval</strong> [Bronze<input type='checkbox' name='getBronzeAxeArg' value='true' checked='checked'>][[Iron<input type='checkbox' name='getIronAxeArg' value='true' checked='checked'>][Steel<input type='checkbox' name='getSteelAxeArg' value='true' checked='checked'>][Black<input type='checkbox' name='getBlackAxeArg' value='true' checked='checked'>][Mithril<input type='checkbox' name='getMithrilAxeArg' value='true' checked='checked'>][Adamant<input type='checkbox' name='getAdamantAxeArg' value='true' checked='checked'>][Rune<input type='checkbox' name='getRuneAxeArg' value='true' checked='checked'>] <strong>Yews</strong> <div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Instructions</div><div style='font-family:Calibri, Arial;color:#FFFFFF; font-size:11px' align='justify'>This script is a woodcutter that cuts every tree. It has a built in deathwalk and will find its way to the trees wherever you start it. It will retrieve the selected axes from the bank when you reach the required level to use them, You can also just select the axe you want to use if you don't have one in your inventory. It will automatically go get it. Note that it is best to start with the axe in the inventory, not wielded. The detauls of what trees the script will cut can be found below. It is important to not that while it powercuts normal, oak and willow trees, it does bank yew trees for profit. <ul><li> 1-20 - Normal Trees </li><li> 20-35 - Oak Trees </li><li> 35-Selected - Willow Trees </li><li> Selected onwards - Yew Trees </li></ul>If you have any questions, or any ideas for next release of the script don't hesitate to ask! Just send me a pm.</div></center> </td></tr></table></center></body></html>") public class SuperSwitchChopper extends Script implements PaintListener {
//Variables int[] normalTrees = { 5004, 5005, 5045, 2879, 3881, 3882, 3883, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3928, 3967, 3968, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 3033, 3034, 3035, 3036, 2409, 2447, 2448, 1330, 1331, 1332, 1310, 1305, 1304, 1303, 1301, 1276, 1277, 1278, 1279, 1280, 8742, 8743, 8973, 8974, 1315, 1316 }; int normalLogs = {}; int[] oakTrees = { 1281, 3037, 8462, 8463, 8464, 8465, 8466, 8467 }; int oakLogs = {}; int[] willowTrees = { 1308, 5551, 5552, 5553, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488 }; int willowLogs = 1519; int[] mapleTrees = {}; int mapleLogs = {}; int[] yewTrees = { 1309, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513 }; int yewLogs = {}; int magicTrees = {}; int magicLogs = {}; int bronzeAxe = {}; int ironAxe = {}; int steelAxe = {}; int blackAxe = {}; int mithrilAxe = 1355; int adamantAxe = 1357; int runeAxe = 1359; int dragonAxe = {}; int woodcuttingAnimation = 867;
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts goes here return true; }
public void onFinish() { // All commands you want executed when the script finishes goes here }
public int loop() { // final RSObject tree = getNearestObjectByID(Willow); if(!isInventoryFull() && !getMyPlayer().getAnimation() == woodcuttingAnimation){ atObject(Tree, "Chop down"); } if(isInventoryFull()){ dropAllExcept(runeAxe); }
return 1000; }
public void onRepaint(Graphics g) { //help me fix this part!! I have no idea what Im doing!! if (isLoggedIn()) { long millis = System.currentTimeMillis() - startTime; final long hours = millis / (1000 * 60 * 60); millis -= hours * 1000 * 60 * 60; final long minutes = millis / (1000 * 60); millis -= minutes * 1000 * 60; final long seconds = millis / 1000;
/* * g.setColor(new Color(0, 0, 0, 100)); g.fillRoundRect(10, 209, * 110, 123, 10, 10); */
final long totalSeconds = (System.currentTimeMillis() - startTime) / 1000;
EXPGained = skills.getCurrentSkillExp(8) - startEXP; levelsGained = skills.getCurrentSkillLevel(8) - startLevel; if (totalSeconds == 0) { EXPPerHour = 0; } else { EXPPerHour = EXPGained * 3600 / totalSeconds; }
long secondsToLvl;
if (EXPPerHour == 0) { secondsToLvl = 0; } else { secondsToLvl = skills.getXPToNextLevel(8) * 3600 / EXPPerHour; } ; final long hoursToLvl = secondsToLvl / (60 * 60); secondsToLvl -= hoursToLvl * 60 * 60; final long minutesToLvl = secondsToLvl / 60; secondsToLvl -= minutesToLvl * 60;
g.setColor(backgroundBottom); g.fillRect(0, 319, 519, 20);
g.setColor(new Color(255, 30, 30, 200)); g.fillRoundRect(15, 324, 100, 10, 5, 10); g.setColor(new Color(30, 255, 30, 200)); g .fillRoundRect(15, 324, skills.getPercentToNextLevel(8), 10, 5, 10); g.setColor(new Color(200, 200, 200, 200)); g.drawRoundRect(15, 324, 100, 10, 5, 10);
g.setFont(new Font("Calibri", Font.BOLD, 14));
g.setColor(white); drawStringWithShadow("" + skills.getPercentToNextLevel(8) + "%", 125, 333, g);
g.drawRect(517, 319, 1, 19); g.drawRect(417, 319, 1, 19); g.drawRect(317, 319, 1, 19); g.drawRect(217, 319, 1, 19);
g.setFont(new Font("Calibri", Font.BOLD, 16)); g.setColor(title); drawStringWithShadow("Status", 245, 334, g); drawStringWithShadow("Experience", 332, 334, g); drawStringWithShadow("Profit", 450, 334, g);
g.setColor(backgroundTop); g.fillRect(0, 319, 519, 10);
int y = 220; int x; final int spacing = 15;
g.setFont(new Font("Calibri", Font.BOLD, 12));
final Mouse m = Bot.getClient().getMouse(); final Point p = new Point(m.x, m.y);
if (isWithinBounds(p, 217, 319, 100, 20)) { g.setColor(backgroundBottom); g.fillRect(217, 235, 102, 84); x = 222; y = 235; g.setColor(green); drawStringWithShadow("" + status, x, y += spacing, g); g.setColor(title); drawStringWithShadow("Runtime: " + hours + ":" + minutes + ":" + seconds, x, y += spacing, g); drawStringWithShadow("Version: " + version, x, y += spacing, g); if (version < latestVersion) { g.setColor(red); drawStringWithShadow("***Outdated***", x, y += spacing, g); drawStringWithShadow( "v" + latestVersion + " is available!", x, y += spacing, g); g.setColor(title); } else { drawStringWithShadow("Fully updated", x, y += spacing, g); drawStringWithShadow("Latest version", x, y += spacing, g); }
} if (isWithinBounds(p, 317, 319, 100, 20)) { g.setColor(backgroundBottom); g.fillRect(317, 235, 102, 84); x = 322; y = 235; g.setColor(title); drawStringWithShadow("Current Level: " + skills.getCurrentSkillLevel(8), x, y += spacing, g); drawStringWithShadow("Levels Gained: " + levelsGained, x, y += spacing, g); drawStringWithShadow("EXP Gain: " + EXPGained, x, y += spacing, g); drawStringWithShadow("EXP/Hour: " + EXPPerHour, x, y += spacing, g); drawStringWithShadow("Level in: " + hoursToLvl + ":" + minutesToLvl + ":" + secondsToLvl, x, y += spacing, g); } if (isWithinBounds(p, 417, 319, 100, 20)) { g.setColor(backgroundBottom); g.fillRect(417, 235, 102, 84); x = 422; y = 235; g.setColor(title); if (logType == "yews") { drawStringWithShadow("Log Type: Yews", x, y += spacing, g); drawStringWithShadow("Log Price: " + yewPrice + "gp", x, y += spacing, g); drawStringWithShadow("Logs Banked: " + EXPGained / 175, x, y += spacing, g); drawStringWithShadow("Profit: " + EXPGained / 175 * yewPrice + "gp", x, y += spacing, g); drawStringWithShadow("GP/Hour: " + EXPPerHour * yewPrice / 175, x, y += spacing, g); } else { drawStringWithShadow("Log Type: " + logType, x, y += spacing, g); drawStringWithShadow("Log Price: N/A", x, y += spacing, g); drawStringWithShadow("Logs Banked: N/A", x, y += spacing, g); drawStringWithShadow("Profit: N/A", x, y += spacing, g); drawStringWithShadow("GP/Hour: N/A", x, y += spacing, g); } } } }
public boolean onStart(final Map<String, String> args) {
if (args.get("getRuneAxeArg") != null) { if (args.get("getRuneAxeArg").equals("true")) { getRuneAxe = true; } } if (args.get("getAdamantAxeArg") != null) { if (args.get("getAdamantAxeArg").equals("true")) { getAdamantAxe = true; } } if (args.get("getMithrilAxeArg") != null) { if (args.get("getMithrilAxeArg").equals("true")) { getMithrilAxe = true; } }
if (args.get("cutYewsArg").equals("Yews from 60")) { cutYewsAt = 60; cutYews = true; } if (args.get("cutYewsArg").equals("Yews from 65")) { cutYewsAt = 65; cutYews = true; } if (args.get("cutYewsArg").equals("Yews from 70")) { cutYewsAt = 70; cutYews = true; } if (args.get("cutYewsArg").equals("never")) { cutYewsAt = 100; cutYews = false; }
if (cutYews == true) { final GEItemInfo yew = grandExchange.loadItemInfo(YEWLOGID); yewPrice = yew.getMarketPrice(); }
if (args.get("trees").equals("Trees 1")) { normalTreesLocation = new RSTile(2996, 3228); } if (args.get("trees").equals("Trees 2")) { normalTreesLocation = new RSTile(2995, 3252); } if (args.get("trees").equals("Trees 3")) { normalTreesLocation = new RSTile(2990, 3206); }
if (args.get("oaks").equals("Oaks 1")) { oakTreesLocation = new RSTile(2984, 3205); }
if (args.get("willows").equals("Willows 1")) { willowTreesLocation = new RSTile(2989, 3187); } if (args.get("willows").equals("Willows 2")) { willowTreesLocation = new RSTile(2998, 3166); } if (args.get("willows").equals("Willows 3")) { willowTreesLocation = new RSTile(2970, 3195); }
getLatestVersion(); if (latestVersion > version) { log("This version of EpicWoodcutter is now outdated!"); log("Please visit the RSBot site (www.rsbot.org) for the update!"); } return true; }
public void swapAxe(final int axeID) { try { if (distanceTo(faladorEastBank) < random(2, 4) && !bank.getInterface().isValid()) { walkTo(faladorEastBank); wait(random(200, 500)); } final RSObject bankbooth = getNearestObjectByID(bankBooth); if (bankbooth != null && !bank.getInterface().isValid()) { atObjectEpic(bankbooth, "use-quickly"); } wait(random(800, 1600));
if (bank.getInterface().isValid()) { if (bank.getCount(axeID) == 0) { if (axeID == runeAxe) { getRuneAxe = false; log("Could not find rune hatchet in bank. Next time don't select it at the start!"); } if (axeID == adamantAxe) { getAdamantAxe = false; log("Could not find adamant hatchet in bank. Next time don't select it at the start!"); } if (axeID == mithrilAxe) { getMithrilAxe = false; log("Could not find mithril hatchet in bank. Next time don't select it at the start!"); }
wait(500); atInterface(Constants.INTERFACE_BANK, Constants.INTERFACE_BANK_BUTTON_CLOSE); return; } bank.depositAll(); wait(random(400, 800)); bank.atItem(axeID, "Withdraw-1"); wait(random(1500, 2100)); atInterface(Constants.INTERFACE_BANK, Constants.INTERFACE_BANK_BUTTON_CLOSE); } } catch (final Exception e) { } return; }
public RSTile tileOnMap2(RSTile tile) { if (distanceTo(tile) < 15) { return tile; }
for (int i = 0; i < 100; i++) { final RSTile tileLoc = getMyPlayer().getLocation(); final RSTile tile2 = new RSTile( (tile.getX() * 2 + tileLoc.getX()) / 3, (tile.getY() * 2 + tileLoc.getY()) / 3); if (distanceTo(tile2) < 15) { return tile2; } tile = tile2; }
return tile; }
public void walkPathEpic(final RSTile tilePath[]) { int nearest = 0; int distance = 999;
for (int i = 0; i < tilePath.length; i++) { if (distanceTo(tilePath[i]) < distance) { nearest = i; distance = distanceTo(tilePath[i]); } }
for (int j = nearest; j < tilePath.length; j++) { if (walkToTile(tilePath[j]) == false) { return; } }
}
public boolean walkToTile(final RSTile tile) { int failsRemaining = 6; int locationFailsRemaining = 5; RSTile lastLocation = getMyPlayer().getLocation(); while (distanceTo(tile) > 8) { if (getEnergy() > random(30, 60)) { setRun(true); } if (walkTo(tileOnMap2(randomizeTile(tile, 2, 2))) == false) { failsRemaining -= 1; if (failsRemaining <= 0) { status = "Walking failed"; log("Walking failed (invalid location), checking for randoms"); if (random(1, 3) == 2) { walkTo(new RSTile( getMyPlayer().getLocation().getX() + 2, getMyPlayer().getLocation().getY() + 2)); } return false; } wait(random(300, 800)); } else { failsRemaining = 5; } if (getMyPlayer().getLocation().getX() == lastLocation.getX() && getMyPlayer().getLocation().getY() == lastLocation .getY()) { locationFailsRemaining -= 1; if (locationFailsRemaining <= 0) { status = "Walking failed"; log("Walking failed (not moving), checking for randoms"); return false; } wait(random(300, 800)); } else { lastLocation = getMyPlayer().getLocation(); locationFailsRemaining = 5; } int countDown = 100; while (distanceTo(getDestination()) > 8 && getMyPlayer().isMoving()) { wait(200); countDown -= 1; if (countDown <= 0) { if (distanceTo(lumbridge) > 40) { return false; } } } } if (distanceTo(tile) > 5) { walkTo(tile); } return true; } }
| |
| | | Sanuka
Posts : 17 Join date : 2010-07-27 Age : 30 Location : Boskoop, the Netherlands
| Subject: Re: Tutorial 2: Writing your first script Thu Sep 23, 2010 10:52 am | |
| - Switchbladed wrote:
- Anyone wanna help me out?
I havent got all the variable things and stuff yet and i dont have walking and banking.. But im lost atm i dunno what to do next, and im getting some errors.. i wanted to make a woodcutter that cuts all trees in lots of places. I also dont know how to make a paint... can anyone help me?
Old (Don't fix this one I edited and made it better)
- Spoiler:
- Code:
-
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = { "Switchbladed" }, category = "Woodcutting", name = "SuperSwitchChopper", version = 1.0, description = " style='font-family: Arial; padding: 10px;'>Chops all types of trees.") public class SuperSwitchChopper extends Script implements PaintListener {
//Variables int Tree = {}; int Logs = {}; int Oak = {}; int Oak Logs = {}; int Willow = {5551, 5552}; int Willow Logs = {1519}; int Maple = {}; int Maple Logs = {}; int Yew = {}; int Yew Logs = {}; int Magic = {}; int Magic Logs = {}; int Bronze hatchet = {}; int Iron hatchet = {}; int Steel hatchet = {}; int Black hatchet = {}; int Mithril hatchet = {}; int Adamant hatchet = {}; int Rune hatchet = {}; int Dragon hatchet = {}; int woodcuttingAnimation = 867;
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts goes here return true; }
public void onFinish() { // All commands you want executed when the script finishes goes here }
public int loop() { // final RSObject tree = getNearestObjectByID(Willow); if(!isInventoryFull() && !getMyPlayer().getAnimation() == woodcuttingAnimation){ atObject(Tree, "Chop down"); } if(isInventoryFull()){ dropAllExcept(Rune hatchet); }
return 1000; }
public void onRepaint(Graphics g) { // Paint goes here. I'll explain paint in another tutorial. }
}
New One (Fix this please I have no Idea what to do, Also I have a paint but I dunno if it works.. Help plz =] I need variables fixed too.. and all the errors...)
- Spoiler:
- Code:
-
import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Point; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Map;
import org.rsbot.bot.Bot; import org.rsbot.bot.input.Mouse; import org.rsbot.event.listeners.PaintListener; import org.rsbot.script.Calculations; import org.rsbot.script.Constants; import org.rsbot.script.GEItemInfo; import org.rsbot.script.Script; import org.rsbot.script.wrappers.RSInterface; import org.rsbot.script.wrappers.RSObject; import org.rsbot.script.wrappers.RSTile;
@ScriptManifest(authors = { "Switchbladed" }, category = "Woodcutting", name = "SuperSwitchChopper", version = 1.0, description = "<html><head></head><body bgcolor='#222222'><center><table><tr><td width='350' valign='top'><center><div style='font-family:Calibri, Arial;color:#FF3300; font-size:36px'>SuperSwitchChopper</div><div style='font-family:Calibri, Arial;color:#FFFFFF; font-size:16px'>v1.0 by Switchbladed </div><div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Quick Select</div><div><table bordercolor='#FF3300' border='1' cellpadding='0' cellspacing='0' ><tr><td align='center' style='font-family:Calibri, Arial;color:#FFFFFF; font-size:12px'><b>Tree Locations</b> <select name='trees'><option>Trees 1<option>Trees 2<option>Trees 3</select> <select name='oaks'><option>Oaks 1</select> <select name='willows'><option>Willows 1<option>Willows 2<option>Willows 3</select> <strong>Hatchet Retrieval</strong> [Bronze<input type='checkbox' name='getBronzeAxeArg' value='true' checked='checked'>][[Iron<input type='checkbox' name='getIronAxeArg' value='true' checked='checked'>][Steel<input type='checkbox' name='getSteelAxeArg' value='true' checked='checked'>][Black<input type='checkbox' name='getBlackAxeArg' value='true' checked='checked'>][Mithril<input type='checkbox' name='getMithrilAxeArg' value='true' checked='checked'>][Adamant<input type='checkbox' name='getAdamantAxeArg' value='true' checked='checked'>][Rune<input type='checkbox' name='getRuneAxeArg' value='true' checked='checked'>] <strong>Yews</strong> <div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Instructions</div><div style='font-family:Calibri, Arial;color:#FFFFFF; font-size:11px' align='justify'>This script is a woodcutter that cuts every tree. It has a built in deathwalk and will find its way to the trees wherever you start it. It will retrieve the selected axes from the bank when you reach the required level to use them, You can also just select the axe you want to use if you don't have one in your inventory. It will automatically go get it. Note that it is best to start with the axe in the inventory, not wielded. The detauls of what trees the script will cut can be found below. It is important to not that while it powercuts normal, oak and willow trees, it does bank yew trees for profit. <ul><li> 1-20 - Normal Trees </li><li> 20-35 - Oak Trees </li><li> 35-Selected - Willow Trees </li><li> Selected onwards - Yew Trees </li></ul>If you have any questions, or any ideas for next release of the script don't hesitate to ask! Just send me a pm.</div></center> </td></tr></table></center></body></html>") public class SuperSwitchChopper extends Script implements PaintListener {
//Variables int[] normalTrees = { 5004, 5005, 5045, 2879, 3881, 3882, 3883, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3928, 3967, 3968, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 3033, 3034, 3035, 3036, 2409, 2447, 2448, 1330, 1331, 1332, 1310, 1305, 1304, 1303, 1301, 1276, 1277, 1278, 1279, 1280, 8742, 8743, 8973, 8974, 1315, 1316 }; int normalLogs = {}; int[] oakTrees = { 1281, 3037, 8462, 8463, 8464, 8465, 8466, 8467 }; int oakLogs = {}; int[] willowTrees = { 1308, 5551, 5552, 5553, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488 }; int willowLogs = 1519; int[] mapleTrees = {}; int mapleLogs = {}; int[] yewTrees = { 1309, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513 }; int yewLogs = {}; int magicTrees = {}; int magicLogs = {}; int bronzeAxe = {}; int ironAxe = {}; int steelAxe = {}; int blackAxe = {}; int mithrilAxe = 1355; int adamantAxe = 1357; int runeAxe = 1359; int dragonAxe = {}; int woodcuttingAnimation = 867;
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class);
public boolean onStart(Map args) { // All commands you want executed when the script starts goes here return true; }
public void onFinish() { // All commands you want executed when the script finishes goes here }
public int loop() { // final RSObject tree = getNearestObjectByID(Willow); if(!isInventoryFull() && !getMyPlayer().getAnimation() == woodcuttingAnimation){ atObject(Tree, "Chop down"); } if(isInventoryFull()){ dropAllExcept(runeAxe); }
return 1000; }
public void onRepaint(Graphics g) { //help me fix this part!! I have no idea what Im doing!! if (isLoggedIn()) { long millis = System.currentTimeMillis() - startTime; final long hours = millis / (1000 * 60 * 60); millis -= hours * 1000 * 60 * 60; final long minutes = millis / (1000 * 60); millis -= minutes * 1000 * 60; final long seconds = millis / 1000;
/* * g.setColor(new Color(0, 0, 0, 100)); g.fillRoundRect(10, 209, * 110, 123, 10, 10); */
final long totalSeconds = (System.currentTimeMillis() - startTime) / 1000;
EXPGained = skills.getCurrentSkillExp(8) - startEXP; levelsGained = skills.getCurrentSkillLevel(8) - startLevel; if (totalSeconds == 0) { EXPPerHour = 0; } else { EXPPerHour = EXPGained * 3600 / totalSeconds; }
long secondsToLvl;
if (EXPPerHour == 0) { secondsToLvl = 0; } else { secondsToLvl = skills.getXPToNextLevel(8) * 3600 / EXPPerHour; } ; final long hoursToLvl = secondsToLvl / (60 * 60); secondsToLvl -= hoursToLvl * 60 * 60; final long minutesToLvl = secondsToLvl / 60; secondsToLvl -= minutesToLvl * 60;
g.setColor(backgroundBottom); g.fillRect(0, 319, 519, 20);
g.setColor(new Color(255, 30, 30, 200)); g.fillRoundRect(15, 324, 100, 10, 5, 10); g.setColor(new Color(30, 255, 30, 200)); g .fillRoundRect(15, 324, skills.getPercentToNextLevel(8), 10, 5, 10); g.setColor(new Color(200, 200, 200, 200)); g.drawRoundRect(15, 324, 100, 10, 5, 10);
g.setFont(new Font("Calibri", Font.BOLD, 14));
g.setColor(white); drawStringWithShadow("" + skills.getPercentToNextLevel(8) + "%", 125, 333, g);
g.drawRect(517, 319, 1, 19); g.drawRect(417, 319, 1, 19); g.drawRect(317, 319, 1, 19); g.drawRect(217, 319, 1, 19);
g.setFont(new Font("Calibri", Font.BOLD, 16)); g.setColor(title); drawStringWithShadow("Status", 245, 334, g); drawStringWithShadow("Experience", 332, 334, g); drawStringWithShadow("Profit", 450, 334, g);
g.setColor(backgroundTop); g.fillRect(0, 319, 519, 10);
int y = 220; int x; final int spacing = 15;
g.setFont(new Font("Calibri", Font.BOLD, 12));
final Mouse m = Bot.getClient().getMouse(); final Point p = new Point(m.x, m.y);
if (isWithinBounds(p, 217, 319, 100, 20)) { g.setColor(backgroundBottom); g.fillRect(217, 235, 102, 84); x = 222; y = 235; g.setColor(green); drawStringWithShadow("" + status, x, y += spacing, g); g.setColor(title); drawStringWithShadow("Runtime: " + hours + ":" + minutes + ":" + seconds, x, y += spacing, g); drawStringWithShadow("Version: " + version, x, y += spacing, g); if (version < latestVersion) { g.setColor(red); drawStringWithShadow("***Outdated***", x, y += spacing, g); drawStringWithShadow( "v" + latestVersion + " is available!", x, y += spacing, g); g.setColor(title); } else { drawStringWithShadow("Fully updated", x, y += spacing, g); drawStringWithShadow("Latest version", x, y += spacing, g); }
} if (isWithinBounds(p, 317, 319, 100, 20)) { g.setColor(backgroundBottom); g.fillRect(317, 235, 102, 84); x = 322; y = 235; g.setColor(title); drawStringWithShadow("Current Level: " + skills.getCurrentSkillLevel(8), x, y += spacing, g); drawStringWithShadow("Levels Gained: " + levelsGained, x, y += spacing, g); drawStringWithShadow("EXP Gain: " + EXPGained, x, y += spacing, g); drawStringWithShadow("EXP/Hour: " + EXPPerHour, x, y += spacing, g); drawStringWithShadow("Level in: " + hoursToLvl + ":" + minutesToLvl + ":" + secondsToLvl, x, y += spacing, g); } if (isWithinBounds(p, 417, 319, 100, 20)) { g.setColor(backgroundBottom); g.fillRect(417, 235, 102, 84); x = 422; y = 235; g.setColor(title); if (logType == "yews") { drawStringWithShadow("Log Type: Yews", x, y += spacing, g); drawStringWithShadow("Log Price: " + yewPrice + "gp", x, y += spacing, g); drawStringWithShadow("Logs Banked: " + EXPGained / 175, x, y += spacing, g); drawStringWithShadow("Profit: " + EXPGained / 175 * yewPrice + "gp", x, y += spacing, g); drawStringWithShadow("GP/Hour: " + EXPPerHour * yewPrice / 175, x, y += spacing, g); } else { drawStringWithShadow("Log Type: " + logType, x, y += spacing, g); drawStringWithShadow("Log Price: N/A", x, y += spacing, g); drawStringWithShadow("Logs Banked: N/A", x, y += spacing, g); drawStringWithShadow("Profit: N/A", x, y += spacing, g); drawStringWithShadow("GP/Hour: N/A", x, y += spacing, g); } } } }
public boolean onStart(final Map<String, String> args) {
if (args.get("getRuneAxeArg") != null) { if (args.get("getRuneAxeArg").equals("true")) { getRuneAxe = true; } } if (args.get("getAdamantAxeArg") != null) { if (args.get("getAdamantAxeArg").equals("true")) { getAdamantAxe = true; } } if (args.get("getMithrilAxeArg") != null) { if (args.get("getMithrilAxeArg").equals("true")) { getMithrilAxe = true; } }
if (args.get("cutYewsArg").equals("Yews from 60")) { cutYewsAt = 60; cutYews = true; } if (args.get("cutYewsArg").equals("Yews from 65")) { cutYewsAt = 65; cutYews = true; } if (args.get("cutYewsArg").equals("Yews from 70")) { cutYewsAt = 70; cutYews = true; } if (args.get("cutYewsArg").equals("never")) { cutYewsAt = 100; cutYews = false; }
if (cutYews == true) { final GEItemInfo yew = grandExchange.loadItemInfo(YEWLOGID); yewPrice = yew.getMarketPrice(); }
if (args.get("trees").equals("Trees 1")) { normalTreesLocation = new RSTile(2996, 3228); } if (args.get("trees").equals("Trees 2")) { normalTreesLocation = new RSTile(2995, 3252); } if (args.get("trees").equals("Trees 3")) { normalTreesLocation = new RSTile(2990, 3206); }
if (args.get("oaks").equals("Oaks 1")) { oakTreesLocation = new RSTile(2984, 3205); }
if (args.get("willows").equals("Willows 1")) { willowTreesLocation = new RSTile(2989, 3187); } if (args.get("willows").equals("Willows 2")) { willowTreesLocation = new RSTile(2998, 3166); } if (args.get("willows").equals("Willows 3")) { willowTreesLocation = new RSTile(2970, 3195); }
getLatestVersion(); if (latestVersion > version) { log("This version of EpicWoodcutter is now outdated!"); log("Please visit the RSBot site (www.rsbot.org) for the update!"); } return true; }
public void swapAxe(final int axeID) { try { if (distanceTo(faladorEastBank) < random(2, 4) && !bank.getInterface().isValid()) { walkTo(faladorEastBank); wait(random(200, 500)); } final RSObject bankbooth = getNearestObjectByID(bankBooth); if (bankbooth != null && !bank.getInterface().isValid()) { atObjectEpic(bankbooth, "use-quickly"); } wait(random(800, 1600));
if (bank.getInterface().isValid()) { if (bank.getCount(axeID) == 0) { if (axeID == runeAxe) { getRuneAxe = false; log("Could not find rune hatchet in bank. Next time don't select it at the start!"); } if (axeID == adamantAxe) { getAdamantAxe = false; log("Could not find adamant hatchet in bank. Next time don't select it at the start!"); } if (axeID == mithrilAxe) { getMithrilAxe = false; log("Could not find mithril hatchet in bank. Next time don't select it at the start!"); }
wait(500); atInterface(Constants.INTERFACE_BANK, Constants.INTERFACE_BANK_BUTTON_CLOSE); return; } bank.depositAll(); wait(random(400, 800)); bank.atItem(axeID, "Withdraw-1"); wait(random(1500, 2100)); atInterface(Constants.INTERFACE_BANK, Constants.INTERFACE_BANK_BUTTON_CLOSE); } } catch (final Exception e) { } return; }
public RSTile tileOnMap2(RSTile tile) { if (distanceTo(tile) < 15) { return tile; }
for (int i = 0; i < 100; i++) { final RSTile tileLoc = getMyPlayer().getLocation(); final RSTile tile2 = new RSTile( (tile.getX() * 2 + tileLoc.getX()) / 3, (tile.getY() * 2 + tileLoc.getY()) / 3); if (distanceTo(tile2) < 15) { return tile2; } tile = tile2; }
return tile; }
public void walkPathEpic(final RSTile tilePath[]) { int nearest = 0; int distance = 999;
for (int i = 0; i < tilePath.length; i++) { if (distanceTo(tilePath[i]) < distance) { nearest = i; distance = distanceTo(tilePath[i]); } }
for (int j = nearest; j < tilePath.length; j++) { if (walkToTile(tilePath[j]) == false) { return; } }
}
public boolean walkToTile(final RSTile tile) { int failsRemaining = 6; int locationFailsRemaining = 5; RSTile lastLocation = getMyPlayer().getLocation(); while (distanceTo(tile) > 8) { if (getEnergy() > random(30, 60)) { setRun(true); } if (walkTo(tileOnMap2(randomizeTile(tile, 2, 2))) == false) { failsRemaining -= 1; if (failsRemaining <= 0) { status = "Walking failed"; log("Walking failed (invalid location), checking for randoms"); if (random(1, 3) == 2) { walkTo(new RSTile( getMyPlayer().getLocation().getX() + 2, getMyPlayer().getLocation().getY() + 2)); } return false; } wait(random(300, 800)); } else { failsRemaining = 5; } if (getMyPlayer().getLocation().getX() == lastLocation.getX() && getMyPlayer().getLocation().getY() == lastLocation .getY()) { locationFailsRemaining -= 1; if (locationFailsRemaining <= 0) { status = "Walking failed"; log("Walking failed (not moving), checking for randoms"); return false; } wait(random(300, 800)); } else { lastLocation = getMyPlayer().getLocation(); locationFailsRemaining = 5; } int countDown = 100; while (distanceTo(getDestination()) > 8 && getMyPlayer().isMoving()) { wait(200); countDown -= 1; if (countDown <= 0) { if (distanceTo(lumbridge) > 40) { return false; } } } } if (distanceTo(tile) > 5) { walkTo(tile); } return true; } }
It might be a good idea to post the errors, seeing as how huge the code is I don't feel like digging in and getting to understand how you coded, what logic you used etc. Helping will be faster and more likely with errors posted | |
| | | Switchbladed
Posts : 2 Join date : 2010-09-22
| Subject: Re: Tutorial 2: Writing your first script Fri Sep 24, 2010 3:12 am | |
| How do I post errors? I have 85 errors left can you compile it and check? This is the new code with 85 errors, is it possible to post all the errors? - Code:
-
import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Point; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Map;
import org.rsbot.bot.Bot; import org.rsbot.bot.input.Mouse; import org.rsbot.event.listeners.PaintListener; import org.rsbot.script.Calculations; import org.rsbot.script.Constants; import org.rsbot.script.GEItemInfo; import org.rsbot.script.Script; import org.rsbot.script.wrappers.RSInterface; import org.rsbot.script.wrappers.RSObject; import org.rsbot.script.wrappers.RSTile;
@ScriptManifest(authors = { "Switchbladed" }, category = "Woodcutting", name = "SuperSwitchChopper", version = 1.0, description = "<html><body bgcolor='#0099CC'><center><table><tr><td width='350' valign='top'><center><div style='font-family:Calibri, Arial;color:#333333; font-size:36px'>SuperSwitchChopper</div><div style='font-family:Calibri, Arial;color:#333333; font-size:16px'>v1.0 by Switchbladed </div><div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Quick Select</div><div><table bordercolor='#FF3300' border='1' cellpadding='0' cellspacing='0' ><tr><td align='center' style='font-family:Calibri, Arial;color:#333333; font-size:12px'><b>Which trees do you wish to cut?</b> <select name='trees'><option>Normal Trees<option>Oak Trees<option>Willow Trees<option>Maple Trees<option>Yew Trees<option>Magic Trees</select> <strong>Get these Hatchets from bank at required level:</strong> [Bronze<input type='checkbox' name='getBronzeAxeArg' value='true' checked='checked'>][[Iron<input type='checkbox' name='getIronAxeArg' value='true' checked='checked'>][Steel<input type='checkbox' name='getSteelAxeArg' value='true' checked='checked'>][Black<input type='checkbox' name='getBlackAxeArg' value='true' checked='checked'>][Mithril<input type='checkbox' name='getMithrilAxeArg' value='true' checked='checked'>][Adamant<input type='checkbox' name='getAdamantAxeArg' value='true' checked='checked'>][Rune<input type='checkbox' name='getRuneAxeArg' value='true' checked='checked'>] <strong>Yews</strong> <div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Instructions</div><div style='font-family:Calibri, Arial;color:#FFFFFF; font-size:11px align=justify>This script is a woodcutter that cuts every tree. Start anywhere and it will start automatically. It will retrieve the selected axes from the bank when you reach the required level to use them, You can also just select the axe you want to use if you dont have one in your inventory. It will automatically go get it from yor bank. The levels below are the levels you will cut each tree. <ul><li> 1-20 - Normal Trees </li><li> 20-35 - Oak Trees </li><li> 35 - Willow Trees </li><li> 60, 65 or 70 - 80 - Yew Trees </li><li> 80 - 99 - Magic Trees </li></ul>If you have any questions, or any ideas for next release of the script please ask me! Just send me a pm. This script is not for fast training. It is also for good cash.</div></center></td></tr></table></center></body></html> public class SuperSwitchChopper extends Script implements PaintListener {
//Variables int[] normalTrees = { 5004, 5005, 5045, 2879, 3881, 3882, 3883, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3928, 3967, 3968, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 3033, 3034, 3035, 3036, 2409, 2447, 2448, 1330, 1331, 1332, 1310, 1305, 1304, 1303, 1301, 1276, 1277, 1278, 1279, 1280, 8742, 8743, 8973, 8974, 1315, 1316 }; int normalLogs = {}; int[] oakTrees = { 1281, 3037, 8462, 8463, 8464, 8465, 8466, 8467 }; int oakLogs = {}; int[] willowTrees = { 1308, 5551, 5552, 5553, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488 }; int willowLogs = 1519; int[] mapleTrees = {}; int mapleLogs = {}; int[] yewTrees = { 1309, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513 }; int yewLogs = {}; int magicTrees = {}; int magicLogs = {}; int bronzeAxe = {}; int ironAxe = {}; int steelAxe = {}; int blackAxe = {}; int mithrilAxe = 1355; int adamantAxe = 1357; int runeAxe = 1359; int dragonAxe = {}; int woodcuttingAnimation = 867;
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class); public boolean onStart(Map args) { // All commands you want executed when the script starts goes here return true; } public void onFinish() { // All commands you want executed when the script finishes goes here } public int loop() { // final RSObject tree = getNearestObjectByID(Willow); if(!isInventoryFull() && !getMyPlayer().getAnimation() == woodcuttingAnimation){ atObject(Tree, "Chop down"); }
if(isInventoryFull()){ dropAllExcept(runeAxe); }
return 1000; } public void onRepaint(Graphics g) { //paint goes here }
} | |
| | | Sanuka
Posts : 17 Join date : 2010-07-27 Age : 30 Location : Boskoop, the Netherlands
| Subject: Re: Tutorial 2: Writing your first script Tue Oct 12, 2010 3:43 pm | |
| - Switchbladed wrote:
- How do I post errors? I have 85 errors left can you compile it and check?
This is the new code with 85 errors, is it possible to post all the errors?
First off sorry for the huge wait lol, real life be giving me troubles also as im typing this im placing this code into eclipse. Also, i don't see at first glance how this code is giving you 85 errors lol. (aah 15 minutes till i have to sleep lol) ILl be back with results So yeah im back, and your script is fixed. 1. Be more carefull, your description was all fked up 2. When defining variables: int lol = { } is not correct. { } indicates it's an array thus you should do: int[] lol = { } 3. REMEMBER or WRITE DOWN all your variable names. As with the final RSObject tree = getNearestObjectByID(Willow); first off, why was it commented out in the first place? to make an error dissapear i guess. secondly YOU HAVE NO VARIABLE NAMED "Willow" you do however have willowTrees, fixing...: final RSObject tree = getNearestObjectByID(willowTrees); 4. this is a annoying one, get eclipse and set it up right k? if(!isInventoryFull() && !getMyPlayer().getAnimation() == woodcuttingAnimation) the above does not work. Why? You're saying if(notinventoryfull(); and notmyplayer.getanimation == woodcutting animation. it should be: if(!isInventoryFull() && getMyPlayer().getAnimation() != woodcuttingAnimation) the != is just instead of the !getplayerblablah because you cant say !getplayer and then compare it to something you have to do != lol. anyhow, good luck and ill try to be more regular. Hope this helps! YEAH im probably too late lol. finished code: - Code:
-
import java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.Point; import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.URL; import java.net.URLConnection; import java.util.Map;
import org.rsbot.bot.Bot; import org.rsbot.bot.input.Mouse; import org.rsbot.event.listeners.PaintListener; import org.rsbot.script.Calculations; import org.rsbot.script.Constants; import org.rsbot.script.GEItemInfo; import org.rsbot.script.Script; import org.rsbot.script.wrappers.RSInterface; import org.rsbot.script.wrappers.RSObject; import org.rsbot.script.wrappers.RSTile;
import java.awt.*; import java.util.*;
import org.rsbot.bot.Bot; import org.rsbot.script.*; import org.rsbot.script.wrappers.*; import org.rsbot.event.listeners.*; import org.rsbot.event.events.*;
@ScriptManifest(authors = { "Switchbladed" }, category = "Woodcutting", name = "SuperSwitchChopper", version = 1.0, description = "<html><body bgcolor='#0099CC'><center><table><tr><td width='350' valign='top'><center><div style='font-family:Calibri, Arial;color:#333333; font-size:36px'>SuperSwitchChopper</div><div style='font-family:Calibri, Arial;color:#333333; font-size:16px'>v1.0 by Switchbladed" +"</div><div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Quick Select</div><div><table bordercolor='#FF3300' border='1' cellpadding='0' cellspacing='0' ><tr><td align='center' style='font-family:Calibri, Arial;color:#333333; font-size:12px'><b>Which trees do you wish to cut?</b> " +"<select name='trees'><option>Normal Trees<option>Oak Trees<option>Willow Trees<option>Maple Trees<option>Yew Trees<option>Magic Trees</select>" +"<strong>Get these Hatchets from bank at required level:</strong> " +"[Bronze<input type='checkbox' name='getBronzeAxeArg' value='true' checked='checked'>][[Iron<input type='checkbox' name='getIronAxeArg' value='true' checked='checked'>][Steel<input type='checkbox' name='getSteelAxeArg' value='true' checked='checked'>][Black<input type='checkbox' name='getBlackAxeArg' value='true' checked='checked'>][Mithril<input type='checkbox' name='getMithrilAxeArg' value='true' checked='checked'>][Adamant<input type='checkbox' name='getAdamantAxeArg' value='true' checked='checked'>][Rune<input type='checkbox' name='getRuneAxeArg' value='true' checked='checked'>]" +"<strong>Yews</strong> " +"<div style='font-family:Calibri, Arial;color:#FF3300; font-size:16px'>Instructions</div><div style='font-family:Calibri, Arial;color:#FFFFFF; font-size:11px align=justify>This script is a woodcutter that cuts every tree. Start anywhere and it will start automatically." +"It will retrieve the selected axes from the bank when you reach the required level to use them, You can also just select the axe you want to use if you dont have one in your inventory. It will automatically go get it from yor bank. The levels below are the levels you will cut each tree." +"<ul><li> 1-20 - Normal Trees </li><li> 20-35 - Oak Trees </li><li> 35 - Willow Trees </li><li> 60, 65 or 70 - 80 - Yew Trees </li><li> 80 - 99 - Magic Trees </li></ul>If you have any questions, or any ideas for next release of the script please ask me! Just send me a pm." +"This script is not for fast training. It is also for good cash.</div></center></td></tr></table></center></body></html>")
public class SuperSwitchChopper extends Script implements PaintListener {
//Variables int[] normalTrees = { 5004, 5005, 5045, 2879, 3881, 3882, 3883, 3885, 3886, 3887, 3888, 3889, 3890, 3891, 3892, 3893, 3928, 3967, 3968, 4048, 4049, 4050, 4051, 4052, 4053, 4054, 3033, 3034, 3035, 3036, 2409, 2447, 2448, 1330, 1331, 1332, 1310, 1305, 1304, 1303, 1301, 1276, 1277, 1278, 1279, 1280, 8742, 8743, 8973, 8974, 1315, 1316 }; int[] normalLogs = {0, 0};//Don't forget to tell the compiler its an array :o [] brackets int[] oakTrees = { 1281, 3037, 8462, 8463, 8464, 8465, 8466, 8467 }; int[] oakLogs = {};//Same here int[] willowTrees = { 1308, 5551, 5552, 5553, 8481, 8482, 8483, 8484, 8485, 8486, 8487, 8488 }; int willowLogs = 1519; int[] mapleTrees = {}; int[] mapleLogs = {};//Same here.. int[] yewTrees = { 1309, 8503, 8504, 8505, 8506, 8507, 8508, 8509, 8510, 8511, 8512, 8513 }; int[] yewLogs = {}; int[] magicTrees = {}; int[] magicLogs = {}; int[] bronzeAxe = {}; int[] ironAxe = {}; int[] steelAxe = {}; int[] blackAxe = {}; int mithrilAxe = 1355; int adamantAxe = 1357; int runeAxe = 1359; //Might i suggest you make 1 array thats like Hatchets = { 0, 1, 2} only then with real id's? int[] dragonAxe = {}; int woodcuttingAnimation = 867;
//Script Manifest private final ScriptManifest properties = getClass().getAnnotation(ScriptManifest.class); public boolean onStart(Map args) { // All commands you want executed when the script starts goes here return true; } public void onFinish() { // All commands you want executed when the script finishes goes here } public int loop() { final RSObject tree = getNearestObjectByID(willowTrees); //Don't comment this out lol. also get your variables right :D if(!isInventoryFull() && getMyPlayer().getAnimation() != woodcuttingAnimation){ atObject(tree, "Chop down"); }
if(isInventoryFull()){ dropAllExcept(runeAxe); }
return 1000; } public void onRepaint(Graphics g) { //paint goes here }
} | |
| | | Sponsored content
| Subject: Re: Tutorial 2: Writing your first script | |
| |
| | | | Tutorial 2: Writing your first script | |
|
Similar topics | |
|
| Permissions in this forum: | You cannot reply to topics in this forum
| |
| |
| |
|