rendered paste bodyimport org.rsbot.script.Script;
import org.rsbot.script.ScriptManifest;
import org.rsbot.script.wrappers.*;
import org.rsbot.event.listeners.*;
import org.rsbot.event.events.MessageEvent;
import org.rsbot.Configuration;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.net.*;
import javax.imageio.ImageIO;
import org.rsbot.script.methods.Skills;
@ScriptManifest(authors = "Al", keywords = {"L2Smith", "smithing", "smith", "smither"}, name = "L2Smith", version = 1.0, description = "Learn to smith.")
public class L2Smith extends Script implements PaintListener, MessageListener, WindowListener {
private int[] barIDs = {2349, 2351, 2353, 2359, 2361, 2363};
private int[] plateIDs = {1117, 1115, 1119, 1121, 1123, 1127};
private int anvilID = 2783;
private int bankID = 782;
private int barPrice, platePrice;
private int barID, plateID;
private boolean stopScript;
private long idleTimer;
private boolean smithing = false;
private boolean bankClosed = false;
//Paint variables
private long startTime = 0;
private long millis = 0;
private long hours = 0;
private long minutes = 0;
private long seconds = 0;
private int barsUsed, itemsMade, startLevel, startXP;
private Image paintBG;
// GUI variables
private final JFrame frame = new JFrame();
private javax.swing.JComboBox barComboBox;
private javax.swing.JLabel barTitle;
private javax.swing.JComboBox itemComboBox;
private javax.swing.JLabel itemLabel;
private javax.swing.JComboBox locationComboBox;
private javax.swing.JLabel locationLabel;
private javax.swing.JPanel settingsPanel;
private javax.swing.JButton startButton;
private javax.swing.JLabel titleLabel;
private Properties scriptSettings = new Properties();
private Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
@Override
public boolean onStart() {
stopScript = false;
initGUI();
while(frame.isVisible())
sleep(200);
try {
paintBG = ImageIO.read(new URL("http://img98.imageshack.us/img98/5715/l2smithpaint.png"));
}
catch (final java.io.IOException e) {}
startTime = System.currentTimeMillis();
mouse.setSpeed(1);
if (game.isLoggedIn()) {
startLevel = skills.getRealLevel(Skills.SMITHING);
startXP = skills.getCurrentExp(Skills.SMITHING);
barPrice = grandExchange.lookup(barID).getGuidePrice();
platePrice = grandExchange.lookup(plateID).getGuidePrice();
}
return true;
}
@Override
public int loop() {
if (stopScript)
stopScript();
else if (walking.getEnergy() <= 10)
walking.rest(90);
else if (game.isLoggedIn()) {
if (inventory.getCount(barID) >= 5 || bankClosed) {
if (bankClosed && inventory.contains(plateID))
bank();
else
smith();
}
else
bank();
}
return 300;
}
public void smith() {
bankClosed = false;
if (!objects.getNearest(anvilID).isOnScreen() || bank.isOpen()) {
walking.walkTo(new RSTile(3189, 3426));
sleep(1000,1500);
if (objects.getNearest(anvilID) != null)
camera.turnTo(objects.getNearest(anvilID));
}
else if (smithing) {
if (random(0,50) == 25)
antiBan();
if (interfaces.canContinue())
interfaces.getContinueComponent().doClick();
if (inventory.getCount(barID) < 5 || (System.currentTimeMillis() - idleTimer) >= 3000) {
smithing = false;
}
sleep(200);
}
else {
if (interfaces.get(300).isValid()) {
if(interfaces.get(300).getComponent(241).getAbsoluteY() > 270) {
interfaces.get(300).getComponent(16).getComponent(5).doClick();
sleep(200,300);
}
else {
while (!menu.isOpen()) {
interfaces.get(300).getComponent(241).doClick(false);
sleep(100,200);
mouse.moveRandomly(5);
sleep(100,200);
}
menu.clickIndex(3);
sleep(100,200);
mouse.moveOffScreen();
smithing = true;
idleTimer = System.currentTimeMillis();
}
}
else {
inventory.getItem(barID).doAction("Use");
sleep(200,300);
if (inventory.isItemSelected()) {
if (objects.getNearest(anvilID) != null)
objects.getNearest(anvilID).doClick(false);
sleep(200,300);
if (menu.isOpen() && menu.contains("Anvil"))
menu.clickIndex(menu.getIndex("Anvil"));
sleep(500,800);
}
}
}
}
public void bank() {
if (!objects.getNearest(bankID).isOnScreen()) {
walking.walkTo(new RSTile(3189,3435));
sleep(1000,1500);
if (objects.getNearest(bankID) != null)
camera.turnTo(objects.getNearest(bankID));
}
else if (bank.isOpen()) {
if (inventory.contains(plateID)) {
inventory.getItem(plateID).doClick(false);
sleep(200,300);
if(menu.isOpen())
menu.doAction("Deposit-All");
sleep(200,300);
}
else {
bank.getItem(barID).doClick(false);
sleep(200,300);
if(menu.isOpen())
menu.doAction("Withdraw-All");
bankClosed = true;
}
}
else {
RSObject bankBooth = objects.getNearest(bankID);
bankBooth.doAction("Use-quickly");
sleep(1000,1500);
}
}
public void antiBan() {
int rand = random(1,2);
if (rand == 1)
camera.setAngle(random(0,360));
else
mouse.moveSlightly();
}
@Override
public void messageReceived(MessageEvent e) {
if (e.getID() == MessageEvent.MESSAGE_ACTION) {
if (e.getMessage().toLowerCase().contains("platebody")) {
itemsMade++;
barsUsed += 5;
idleTimer = System.currentTimeMillis();
}
}
}
// Paint
@Override
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;
String hoursString = "" + hours;
String minutesString = "" + minutes;
String secondsString = "" + seconds;
if (hours < 10)
hoursString = "0" + hours;
if (minutes < 10)
minutesString = "0" + minutes;
if (seconds < 10)
secondsString = "0" + seconds;
int x = (int) mouse.getLocation().getX();
int y = (int) mouse.getLocation().getY();
g.drawLine(x, y-5, x, y+5);
g.drawLine(x-5,y,x+5,y);
g.setFont(new Font("Arial", Font.BOLD, 12));
g.setColor(new Color(85, 80, 63, 255));
g.drawImage(paintBG, 1, 309, null);
g.drawString("Runtime: " + hoursString + ":" + minutesString + ":" + secondsString, 16, 363);
g.drawString("Bars used: " + barsUsed + " (" + (int) (barsUsed * 3600000D / (System.currentTimeMillis() - startTime)) + "/hour)", 16, 375);
g.drawString("Items made: " + itemsMade + " (" + (int) (itemsMade * 3600000D / (System.currentTimeMillis() - startTime)) + "/hour)", 16, 387);
g.drawString("Profit: " + ((barPrice*barsUsed)-platePrice) + "gp (" + (int) (((barPrice*barsUsed)-platePrice) * 3600000D / (System.currentTimeMillis() - startTime)) + "gp/hour)", 16, 399);
g.drawString("Level: " + skills.getRealLevel(Skills.SMITHING) + " (+" + (skills.getRealLevel(Skills.SMITHING)-startLevel) + ")", 250, 363);
g.drawString("XP: " + skills.getCurrentExp(Skills.SMITHING) + " (+" + (skills.getCurrentExp(Skills.SMITHING)-startXP) + ")", 250, 375);
g.drawString("XP/hour: " + (int) ((skills.getCurrentExp(Skills.SMITHING)-startXP) * 3600000D / (System.currentTimeMillis() - startTime)), 250, 387);
g.drawString("XP TNL: " + skills.getExpToNextLevel(Skills.SMITHING), 250, 399);
//Progress bar
g.setColor(Color.green);
double percent = (double) skills.getPercentToNextLevel(Skills.SMITHING)/100.00;
int width = (int) (350 * percent);
g.fillRect(153, 317, width, 13);
g.setColor(Color.white);
g.drawString(skills.getPercentToNextLevel(Skills.SMITHING) + "% To Level", 300, 328);
}
// GUI
private void initGUI() {
try {
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception e) {}
titleLabel = new javax.swing.JLabel();
settingsPanel = new javax.swing.JPanel();
barTitle = new javax.swing.JLabel();
itemLabel = new javax.swing.JLabel();
barComboBox = new javax.swing.JComboBox();
itemComboBox = new javax.swing.JComboBox();
locationLabel = new javax.swing.JLabel();
locationComboBox = new javax.swing.JComboBox();
startButton = new javax.swing.JButton();
frame.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
frame.setTitle("L2Smith");
frame.setResizable(false);
titleLabel.setFont(new java.awt.Font("Tahoma", 1, 32)); // NOI18N
titleLabel.setForeground(new java.awt.Color(51, 51, 51));
titleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
titleLabel.setText("L2Smith");
settingsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Settings", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 12), new java.awt.Color(102, 102, 102))); // NOI18N
barTitle.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
barTitle.setText("Bar");
itemLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
itemLabel.setText("Item");
barComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Bronze", "Iron", "Steel", "Mithril", "Adamant", "Rune" }));
itemComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Platebody" }));
locationLabel.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
locationLabel.setText("Location");
locationComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Varrock" }));
javax.swing.GroupLayout settingsPanelLayout = new javax.swing.GroupLayout(settingsPanel);
settingsPanel.setLayout(settingsPanelLayout);
settingsPanelLayout.setHorizontalGroup(
settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(settingsPanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(barTitle)
.addComponent(itemLabel)
.addComponent(locationLabel))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(locationComboBox, 0, 95, Short.MAX_VALUE)
.addComponent(itemComboBox, 0, 95, Short.MAX_VALUE)
.addComponent(barComboBox, 0, 95, Short.MAX_VALUE))
.addContainerGap())
);
settingsPanelLayout.setVerticalGroup(
settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, settingsPanelLayout.createSequentialGroup()
.addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(locationLabel)
.addComponent(locationComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(barTitle)
.addComponent(barComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(settingsPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(itemLabel)
.addComponent(itemComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap())
);
startButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
startButton.setText("Start");
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(frame.getContentPane());
frame.getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(startButton, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(titleLabel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 177, Short.MAX_VALUE)
.addComponent(settingsPanel, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(titleLabel)
.addGap(1, 1, 1)
.addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(startButton, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
try {
scriptSettings.load(new FileInputStream(Configuration.Paths.getScriptsSourcesDirectory()+"\\L2Smith.ini"));
if (scriptSettings.getProperty("location").length() != 0)
locationComboBox.setSelectedIndex(Integer.parseInt(scriptSettings.getProperty("location")));
if (scriptSettings.getProperty("bar").length() != 0)
barComboBox.setSelectedIndex(Integer.parseInt(scriptSettings.getProperty("bar")));
if (scriptSettings.getProperty("item").length() != 0)
itemComboBox.setSelectedIndex(Integer.parseInt(scriptSettings.getProperty("item")));
}
catch(Exception e) {}
startButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
scriptSettings.setProperty("location", "" + locationComboBox.getSelectedIndex());
scriptSettings.setProperty("bar", "" + barComboBox.getSelectedIndex());
scriptSettings.setProperty("item", "" + itemComboBox.getSelectedIndex());
barID = barIDs[barComboBox.getSelectedIndex()];
plateID = plateIDs[barComboBox.getSelectedIndex()];
frame.setVisible(false);
try {
scriptSettings.save(new FileOutputStream(Configuration.Paths.getScriptsSourcesDirectory() + "\\L2Smith.ini"), "Settings for L2Smith");
}
catch (Exception f) {}
}
});
frame.pack();
frame.setLocation((dim.width-frame.getSize().width)/2, (dim.height-frame.getSize().height)/2);
frame.setVisible(true);
}
public void windowClosed(WindowEvent e) {
stopScript = true;
}
public void windowOpened(WindowEvent e) {
}
public void windowIconified(WindowEvent e) {
}
public void windowDeiconified(WindowEvent e) {
}
public void windowActivated(WindowEvent e) {
}
public void windowDeactivated(WindowEvent e) {
}
public void windowGainedFocus(WindowEvent e) {
}
public void windowLostFocus(WindowEvent e) {
}
public void windowClosing(WindowEvent e) {
}
}