Famous Scripts
Would you like to react to this message? Create an account in a few clicks or log in to continue.


Scripts for RSBot made by Famous
 
HomePortalLatest imagesRegisterLog in
New scripts being created everyday! Go to GameKiller.net!

 

 Tutorial 2: Writing your first script

Go down 
+8
sh2head
streak224
Benny
ImNewMem
pattty
Eons
Ben
Famous
12 posters
AuthorMessage
Famous
Administrator
Administrator
Famous


Posts : 50
Join date : 2009-10-23
Age : 29
Location : Chicago

Tutorial 2: Writing your first script Empty
PostSubject: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyFri 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.

• import
This 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.

• @ScriptManifest
RSBot 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.

•• class
Tells the compiler to make it a class file. (There's a lot more to this, but I won't explain)

•• ScriptTemplate
This is what you will name your script.

•• extends
This is a programming concept that you probably wouldn't understand. Don't worry about it.

•• Script
This just tells RSBot that it's a script.

•• implements
This means that means it uses the following:

•• PaintListener
Without this included at the end of your script, you won't be able to have paint.

• public boolean onStart
This tells the script what will happen when you start your script.

• public void onFinish

This tells the script what will happen when you end your script.

• public int loop
This is where your main code will be. I'll explain this later in the tutorial.

• public void onRepaint
This 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. Tutorial 2: Writing your first script Icon_e_wink Let's go back to the base of our script.

Tutorial 2: Writing your first script Icon_exclaim 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

Tutorial 2: Writing your first script Icon_arrow
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. Tutorial 2: Writing your first script Icon_e_smile


Last edited by Famous on Sat Jun 19, 2010 4:06 pm; edited 1 time in total
Back to top Go down
https://famousscripts.forumotion.com
Ben

Ben


Posts : 43
Join date : 2009-10-28
Age : 30
Location : United Kingdom

Tutorial 2: Writing your first script Empty
PostSubject: Very Nice!   Tutorial 2: Writing your first script EmptyWed 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 Tutorial 2: Writing your first script Icon_razz Tutorial 2: Writing your first script Icon_razz

Dw.. I'll do my research Tutorial 2: Writing your first script Icon_study and I will read your tutorial 1. Tutorial 2: Writing your first script Icon_rr


Ben. Tutorial 2: Writing your first script Lol


Last edited by Ben on Wed Oct 28, 2009 9:22 pm; edited 1 time in total
Back to top Go down
Ben

Ben


Posts : 43
Join date : 2009-10-28
Age : 30
Location : United Kingdom

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyWed Oct 28, 2009 5:19 pm

Forgot to mention, Keep up the good work.
Back to top Go down
Eons




Posts : 6
Join date : 2009-12-12

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptySat Dec 12, 2009 11:58 am

Err, Famous. Its very easyy to understand. I read them all. Hoping for more tutorial. Will be donating Smile
Back to top Go down
pattty




Posts : 1
Join date : 2010-01-01

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyFri 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?
Back to top Go down
Famous
Administrator
Administrator
Famous


Posts : 50
Join date : 2009-10-23
Age : 29
Location : Chicago

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyFri Jan 01, 2010 2:28 am

I use Eclipse. I prefer that over a lot of other IDE
Back to top Go down
https://famousscripts.forumotion.com
ImNewMem




Posts : 3
Join date : 2010-01-28

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptySat Jan 30, 2010 6:33 pm

Mind explaing a bit more about import
Back to top Go down
Benny

Benny


Posts : 25
Join date : 2010-01-30
Age : 30
Location : Australia.

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyThu 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.
Back to top Go down
streak224




Posts : 2
Join date : 2010-02-22

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyWed Feb 24, 2010 8:41 pm

how come you do not mention how to write loops?
Back to top Go down
sh2head




Posts : 3
Join date : 2010-03-15

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyMon Mar 15, 2010 11:55 pm

nice Tutorial !!!!!!! BUT how to wirte loops !!!!
Back to top Go down
DaChubz




Posts : 1
Join date : 2010-05-20

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyThu May 20, 2010 6:49 pm

I think im too stuiped for this Tutorial 2: Writing your first script Icon_cry
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 Tutorial 2: Writing your first script Icon_rabbit
I need the begging code w/o all the things explaining it
I will try and get them off myself
Back to top Go down
infernalni




Posts : 1
Join date : 2010-07-28

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyWed 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?
Back to top Go down
Sanuka

Sanuka


Posts : 17
Join date : 2010-07-27
Age : 30
Location : Boskoop, the Netherlands

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptySun 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 Razz)
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 ? Very Happy

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 Smile

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;
}

}
Back to top Go down
Switchbladed




Posts : 2
Join date : 2010-09-22

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyWed 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:

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:
Back to top Go down
Sanuka

Sanuka


Posts : 17
Join date : 2010-07-27
Age : 30
Location : Boskoop, the Netherlands

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyThu 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:

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:

It might be a good idea to post the errors, seeing as how huge the code is Very Happy 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 Very Happy
Back to top Go down
Switchbladed




Posts : 2
Join date : 2010-09-22

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyFri 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
}

}
Back to top Go down
Sanuka

Sanuka


Posts : 17
Join date : 2010-07-27
Age : 30
Location : Boskoop, the Netherlands

Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script EmptyTue 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 Surprised
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
}

}
Back to top Go down
Sponsored content





Tutorial 2: Writing your first script Empty
PostSubject: Re: Tutorial 2: Writing your first script   Tutorial 2: Writing your first script Empty

Back to top Go down
 
Tutorial 2: Writing your first script
Back to top 
Page 1 of 1
 Similar topics
-
» [Request Tutorial] Video Tutorial Scripting
» script please
» I need a new script please
» Script Please?
» Tutorial 4: Banking

Permissions in this forum:You cannot reply to topics in this forum
Famous Scripts :: Tutorials :: Tutorials :: Famous' Scripting Tutorials-
Jump to: