I have never been really big into coding but for a while now I have been playing around with Java and making rsbot scripts. For those that don't know rsbot is a runescape automation bot that does the shit for you so you don't have to be there.
Any who, this is my first script. anyone want to help me clean it up a bit, maybe show me some methods to coding that is a little less... well sloppy?
import org.rsbot.script.Script;
import org.rsbot.script.methods.Inventory;
import org.rsbot.script.methods.Mouse;
import org.rsbot.script.methods.MethodProvider;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.wrappers.RSObject;
import org.rsbot.script.wrappers.RSItem;
import org.rsbot.script.wrappers.RSTile;
import org.rsbot.script.methods.Walking;
import org.rsbot.script.methods.Calculations;
import java.awt.*;
import java.awt.event.KeyEvent;
import org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.methods.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import org.rsbot.script.wrappers.*;
import org.rsbot.script.methods.*;
import org.rsbot.script.methods.Game.CHAT_MODE;
import org.rsbot.script.methods.Skills;
import org.rsbot.event.events.ServerMessageEvent;
import org.rsbot.event.listeners.ServerMessageListener;
import org.rsbot.event.listeners.PaintListener;
import javax.imageio.ImageIO;
import java.io.IOException;
import java.net.URL;
@ScriptManifest(authors = "Hanorotu", name = "Power Fletcher", version = 1.2, description = "Chops normal trees and fletches them into arrow shafts.")
public class HPowerFletcher extends Script implements PaintListener,
ServerMessageListener {
int[] TreeID = {1276, 1277, 1278, 1315, 1316};
int[] KnifeID = {946};
int[] LogsID = {1511};
int[] ShaftID = {52};
int[] BadTreeID = {0};
int[] Square = {0,0,0,0};
int switch1 = 0;
public long startTime = 0;
public long millis = 0;
public long hours = 0;
public long minutes = 0;
public long seconds = 0;
public long last = 0;
public int expGained = 0;
public int startLevel;
public int lvlsGained;
public int currLevel;
private int startExp;
public int expForShaft = 5;
private int made;
public void antiban() {
int b = random(0, 10);
switch (b) {
case 1:
if (random(0, 10) == 5) {
log("Antiban- move mouse");
mouse.moveSlightly();
sleep(200, 600);
mouse.moveRandomly(150, 350);
}
break;
case 2:
if (random(0, 13) == 2) {
log("Antiban- Turn screen");
camera.setAngle(random(30, 70));
sleep(400, 1200);
}
break;
case 3:
if (random(0, 24) == 6) {
log("Antiban- mouse off screen");
mouse.moveOffScreen();
sleep(random(600, random(1200, 2000)));
}
break;
case 4:
if (random(0, 18) == 3) {
log("Antiban- Checking Xp.");
game.openTab(1);
skills.doHover(Skills.INTERFACE_FLETCHING);
sleep(random(2100, 3400));
}
break;
default:
break;
}
}
public boolean onStart(){
log("Welcome to Hanorotu's PowerFletcher.");
startTime = System.currentTimeMillis();
int expForShaft = 5;
startExp = skills.getCurrentExp(skills.FLETCHING);
startLevel = skills.getCurrentLevel(skills.FLETCHING);
return true;
}
public void onFinish() {
log("Thanks for using Hanorotu's PowerFletcher, exclusive to Powerbot.org");
}
//START PAINT
private Image getImage(String url) {
try {
return ImageIO.read(new URL(url));
} catch(IOException e) {
return null;
}
}
private final Color color1 = new Color(255, 255, 255);
private final Color color2 = new Color(0, 0, 0);
private final BasicStroke stroke1 = new BasicStroke(1);
private final Font font1 = new Font("Comic Sans MS", 0, 12);
private final Font font2 = new Font("Comic Sans MS", 0, 10);
private final Image img1 = getImage("http://images1.wikia.nocookie.net/runescape/images/8/87/Flecthing.PNG");
public void onRepaint(Graphics g1) {
Graphics2D g = (Graphics2D)g1;
millis = System.currentTimeMillis() - startTime;
hours = millis / (1000 * 60 * 60);
millis -= hours * (1000 * 60 * 60);
minutes = millis / (1000 * 60);
millis -= minutes * (1000 * 60);
seconds = millis / 1000;
expGained = skills.getCurrentExp(skills.FLETCHING) - startExp;
currLevel = skills.getCurrentLevel(skills.FLETCHING);
lvlsGained = currLevel - startLevel;
g.setColor(color1);
g.fillRoundRect(289, 234, 226, 98, 16, 16);
g.setColor(color2);
g.setStroke(stroke1);
g.drawRoundRect(289, 234, 226, 98, 16, 16);
g.setFont(font1);
g.drawString("Hanorotu's PowerFletcher", 365, 247);
g.setFont(font2);
g.drawString("Time Ran: " + hours +":"+ minutes + ":" + seconds, 309, 269);
g.drawString("EXP Gained: " + expGained, 302, 283);
g.drawString("Arrowshafts Made: " + made * 15, 293, 299);
g.drawString("Current Level: " + currLevel + " (" + lvlsGained + ")", 293, 318);
g.drawImage(img1, 466, 280, null);
}
//END Paint
public void serverMessageRecieved(ServerMessageEvent arg0) {
final String serverString = arg0.getMessage();
if (serverString.contains("You carefully cut the wood into 15 arrow shafts")) {
made++;
}
}
public void Chop() {
RSObject tree = objects.getNearest(TreeID);
if (tree != null && getMyPlayer().getAnimation() == -1 ) {
RSTile treetochop = tree.getLocation();
if (calc.canReach( treetochop, true)) {
if (tree != null && getMyPlayer().getAnimation() == -1 && !calc.tileOnScreen(treetochop)) {
walking.walkTileMM(treetochop);
}
antiban();
if (tree != null && getMyPlayer().getAnimation() == -1 && calc.tileOnScreen(treetochop)) {
tree.doAction("Chop");
}
}
else {
log("Finding alternative tree..");
mouse.click( 656, 40, 10, 10, true);
}
sleep(random(500,800));
}
}
public void checkRun() {
if(!walking.isRunEnabled()) {
if(walking.getEnergy() < random(66,90)) {
walking.rest(random(78,100));
} else
walking.setRun(true);
}
}
public void Fletch() {
while (inventory.contains(1521)) {
RSItem Oak = inventory.getItem(1521);
Oak.doAction("Drop");
sleep(random(500,800));
}
RSItem Log = inventory.getItem(LogsID);
RSItem Knife = inventory.getItem(KnifeID);
inventory.useItem(Knife, Log);
sleep(random(3000,4000));
mouse.click(100, 419, 10, 10, true);
sleep(random(500,800));
}
@Override
public int loop(){
if (inventory.isFull()) {
Fletch();
}else{
if (!inventory.isFull()) {
Chop();
}
}
checkRun();
antiban();
return (random(1000, 1500));
}
}