Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.event.*;
- import java.awt.*;
- import java.util.*;
- import java.io.*;
- import java.net.*;
- import java.lang.reflect.Method;
- import javax.swing.*;
- import org.rsbot.script.*;
- import org.rsbot.script.methods.Game;
- import org.rsbot.script.methods.Skills;
- import org.rsbot.script.wrappers.*;
- import org.rsbot.event.events.MessageEvent;
- import org.rsbot.event.listeners.*;
- import javax.imageio.ImageIO;
- @ScriptManifest(authors = { "Conderoga" }, keywords = "Smithing", name = "Conderoga's Smither", version = 2.00,description = "Fast Edgeville Gold smelter/ Cannonball maker.")
- /*UpdateLog:
- v1.00 - GUI, Paint, Edgeville only
- v2.00 - Revised for RSBot 2.0, added gold
- */
- public class CSmith extends Script implements PaintListener, MessageListener {
- private boolean guiWait = true;
- private boolean guiExit = true;
- private String type = "WAITING";
- CSmithGui gui;
- private int steelBarID = 2353;
- private int goldBarID = 2357;
- private int coalID = 453;
- private int goldOreID = 444;
- private int cannonballID = 2;
- private int [] mouldID = {4};
- private int steelBarValue = 0;
- private int goldBarValue = 0;
- private int goldOreValue = 0;
- private int goldValue = 0;
- private int cannonballValue = 0;
- private int profitMargin = 0;
- private int amntBalls = 0;
- private int amntBars = 0;
- private int numToMake = 1000000000;
- private RSTile bankTile;
- private RSTile furnaceTile;
- private int furnaceID;
- private int startLevel;
- private int startExp;
- private int expGained;
- private int lvlsGained;
- private long startTime;
- private double startTimeDbl;
- private long ExpHr;
- private int safety = 0;
- private String status;
- private Point p;
- private int tempNumSmithed = 0;
- private int oneTimeOnly = 0;
- public boolean onStart() {
- //Credits to Zombieknight for this:-----------------
- final int welcome = JOptionPane.showConfirmDialog(null,"Before using my script, would you like to thank me\nby clicking some adverts?","Welcome", JOptionPane.YES_NO_OPTION);
- if (welcome == 0) {
- final String message = "<html>Thank you for your support!<br /></html>";
- JOptionPane.showMessageDialog(null, message);
- openURL("http://adf.ly/317631/agsn");
- }
- //=------------------------------------------------------*/
- gui = new CSmithGui();
- gui.setVisible(true);
- while(guiWait)
- {
- sleep(100);
- }
- startTime = System.currentTimeMillis();
- startTimeDbl = System.currentTimeMillis();
- log("Using "+numToMake+" bars.");
- return !guiExit;
- }
- public void startUpStuff() {
- status = "Retrieving prices.";
- if(type.equals("Cannonballs")){
- steelBarValue = getGEValue("Steel Bar",2353);
- cannonballValue = getGEValue("Cannonball",2);
- profitMargin = (cannonballValue*4)-steelBarValue;
- }
- else if(type.equals("Gold")){
- goldBarValue = getGEValue("Gold bar",goldBarID);
- goldOreValue = getGEValue("Gold ore",goldOreID);
- profitMargin = goldBarValue-goldOreValue;
- }
- bankTile = new RSTile(3097,3495);
- furnaceTile = new RSTile(3110,3502);
- furnaceID = 26814;
- startTime = System.currentTimeMillis();
- status = "Starting.";
- camera.setAngle(0);
- camera.setPitch(true);
- if(walking.getEnergy()> 15)
- walking.setRun(true);
- }
- public void messageReceived(final MessageEvent e) {
- final String serverString = e.getMessage();
- if (serverString.toLowerCase().contains("remove the cannonballs from the"))
- amntBalls+=4;
- else if(serverString.toLowerCase().contains("you retrieve a bar"))
- {
- amntBars++;
- }
- else if(serverString.toLowerCase().contains("2"))
- {
- amntBars++;
- }
- else if(serverString.toLowerCase().contains("3"))
- {
- amntBars++;
- amntBars++;
- }
- else if(serverString.toLowerCase().contains("4"))
- {
- amntBars++;
- amntBars++;
- amntBars++;
- }
- else if(serverString.toLowerCase().contains("you've just advanced"))
- {
- smith();
- }
- }
- public boolean checkAnim() {
- if(!hasBars())
- return false;
- for(int i = 0; i<5;i++){
- if(getMyPlayer().getAnimation()==827||getMyPlayer().getAnimation()==899||getMyPlayer().getAnimation()==3243)
- { status = "Smithing.";
- return true;
- }
- sleep(500);
- }
- status = "Not Smithing.";
- return false;
- }
- public void walkToBank()
- { status = "Walking to bank.";
- if(!walking.isRunEnabled()&&walking.getEnergy()>20){
- walking.setRun(true);
- sleep(random(600,800));
- }
- walking.walkTileMM(bankTile);
- sleep(random(1500,2000));
- while(getMyPlayer().isMoving())
- sleep(random(100,200));
- }
- public boolean hasBars()
- {
- RSItem [] inv = inventory.getItems();
- for(int i = 0; i<inv.length;i++)
- {
- if(inv[i].getID()==steelBarID&&type.equals("Cannonballs"))
- return true;
- else if(inv[i].getID()==goldOreID&&type.equals("Gold"))
- return true;
- }
- return false;
- }
- public void bank()
- {
- mouse.setSpeed(random(6,8));
- camera.setPitch(true);
- do{
- mouse.move(calc.tileToScreen(bankTile),2,2);
- menu.doAction("Use-quickly Bank booth");
- sleep(random(1000,1200));
- }while(!bank.isOpen());
- status = "Depositing.";
- if(type.equals("Cannonballs"))
- bank.depositAllExcept(4);
- else
- bank.depositAll();
- status = "Withdrawing.";
- sleep(random(600,800));
- mouse.move(55,109,5,5);
- mouse.click(false);
- sleep(random(600,800));
- menu.doAction("Withdraw-All");
- status = "Moving to furnace.";
- walking.walkTileMM(new RSTile(3108,3501));
- sleep(random(1500,2000));
- while(getMyPlayer().isMoving())
- sleep(random(100,200));
- sleep(random(600,800));
- }
- public boolean isInRoom()
- {
- return getMyPlayer().getLocation().getX()>=3106&&getMyPlayer().getLocation().getX()<=3110&&getMyPlayer().getLocation().getY()>=3498&&getMyPlayer().getLocation().getY()<=3502;
- }
- public static int getGEValue(String name, int id){
- try{
- String [] temp = name.split(" ");
- String newName = "";
- for(int i = 0; i<temp.length; i++)
- if(i==temp.length-1)
- newName+=temp[i];
- else
- newName+="_"+temp[i];
- URL url = new URL("http://services.runescape.com/m=itemdb_rs/"+newName+"/viewitem.ws?obj="+id);
- InputStream is = url.openStream();
- InputStreamReader isr = new InputStreamReader(is);
- BufferedReader br = new BufferedReader(isr);
- String line;
- String num = "";
- while((line=br.readLine())!=null){
- if(line.contains("Current guide price:"))
- num = line;
- }
- System.out.println(num);
- if(num.length()<29)
- return -1;
- else{
- num = num.substring(28);
- num = num.replaceAll(",", "");
- return Integer.parseInt(num);
- }
- }catch(Exception e){
- return -1;
- }
- }
- public void smith()
- { status = "Starting to Smith";
- if(random(1,4)==2){
- camera.setAngle(0);
- camera.setPitch(true);
- }
- mouse.move(704,445,5,5);
- mouse.click(true);
- RSObject [] test = objects.getAllAt(furnaceTile);
- RSObject furnace = null;
- for(int i = 0; i<test.length;i++)
- {
- if(test[i].getID()==furnaceID){
- furnace = test[i];
- break;
- }
- }
- RSModel m = furnace.getModel();
- Point p = m.getPoint();
- mouse.move(p,1,1);
- mouse.click(true);
- sleep(random(1500,1600));
- int x = (type.equals("Cannonballs")) ? random(222,293) : random(235,284);
- int y = (type.equals("Cannonballs")) ? random(400,450) : random(398,449);
- mouse.move(x,y,0,0);
- mouse.click(true);
- sleep(random(600,800));
- checkAnim();
- }
- public Point midpoint(Point p1, Point p2)
- {
- Point temp = new Point((int)((p1.getX()+p2.getX())/2),(int)((p1.getY()+p2.getY())/2));
- return temp;
- }
- public int loop() {
- try{
- if(safety<1)
- {
- startUpStuff();
- safety=1;
- }
- boolean temp = checkAnim();
- boolean temp2 = hasBars();
- if(type.equals("Cannonballs")&&amntBalls/4 >= numToMake)
- {
- log("Bar limit reached. Stopping script and logging out.");
- game.logout(true);
- stopScript();
- }
- else if(amntBars >= numToMake){
- log("Bar limit reached. Stopping script and logging out.");
- game.logout(true);
- stopScript();
- }
- if(!temp&&temp2)
- {
- smith();
- }
- if(!temp&&!temp2&&isInRoom())
- {
- walkToBank();
- bank();
- smith();
- }
- if(!temp&&!temp2&&!isInRoom())
- {
- bank();
- smith();
- }
- antiBan(random(1,400));
- }
- catch (Exception e){}
- return random(600,800);
- }
- public void antiBan(int rand){
- status += "(AB)";
- mouse.setSpeed(random(7,8));
- if(rand==1)
- if(random(1, 8) == 2)
- mouse.moveRandomly(900,1200);
- if(rand==2)
- if(random(1, 8) == 2)
- mouse.moveRandomly(400,800);
- if(rand==3)
- if(random(1, 8) == 2)
- mouse.moveRandomly(200,700);
- if(rand==4) //THIS CHECKS THE MINING STAT
- if(random(1, 6) == 2)
- {
- game.openTab(Game.TAB_STATS);
- sleep(random(600,800));
- skills.doHover(Skills.INTERFACE_SMITHING);
- sleep(random(1900,2000));
- game.openTab(Game.TAB_INVENTORY);
- }
- if(rand==5) //THIS CLICKS THE XP BUTTON UNDER THE COMPASS (Update thanks to Rawr =D)
- if(random(1, 24) == 2)
- {
- if (interfaces.get(548).getComponent(38).isValid()) {
- return;
- } else {
- if (interfaces.get(548).getComponent(0).doClick()) {
- sleep(1500);
- }
- }
- }
- if(rand==7) //RANDOM SPIN
- if(random(1, 3) == 2)
- {int r = random(1,2);
- camera.setAngle(random(1,359));
- if(r!=1)
- camera.setPitch(random(1,99));}
- if(rand==8) //THIS CHECKS A RANDOM TAB
- if(random(1, 4) == 2)
- {
- int[] tabs = {0,2,3,5,6,7,9,10,11,12,13,14,15};
- game.openTab(tabs[random(0,tabs.length-1)]);
- mouse.moveRandomly(175,200);
- sleep(random(1600,1800));
- sleep(random(900,1000));
- }
- if(rand==9)
- if(random(1,10)==2)
- mouse.moveOffScreen();
- status=status.substring(0,status.indexOf('('));
- }
- public void onRepaint(Graphics g)
- {
- if(game.isLoggedIn())
- {
- if(startExp==0)
- {
- startExp = skills.getCurrentExp(skills.getIndex("smithing"));
- startLevel = skills.getCurrentLevel(skills.getIndex("smithing"));
- }
- lvlsGained = skills.getCurrentLevel(skills.getIndex("smithing")) - startLevel;
- expGained = skills.getCurrentExp(skills.getIndex("smithing")) - startExp;
- //setting up the time
- long ms = System.currentTimeMillis() - startTime;
- double ms2 = System.currentTimeMillis() - startTimeDbl;
- long hours = ms/3600000;
- ms = ms-(hours*3600000);
- long minutes = ms/60000;
- ms = ms-(minutes*60000);
- long seconds = ms/1000;
- // |
- //Background v transparency!
- g.setColor(new Color(0, 0, 0, 205));
- g.fillRoundRect(333, 175, 181, 164, 6, 6); //Background
- long expToLvl = skills.getExpToNextLevel(skills.getIndex("smithing"));
- long time2Lvl = 0;
- long time2LvlHrs = 0;
- long time2LvlMins = 0;
- long time2LvlSec = 0;
- if(ms2!=0&&expGained!=0){
- time2Lvl = (long)(expToLvl/(expGained/(ms2/3600000))*3600000);
- time2LvlHrs = time2Lvl/3600000;
- time2Lvl -= time2LvlHrs*3600000;
- time2LvlMins = time2Lvl/60000;
- time2Lvl -= time2LvlMins*60000;
- time2LvlSec = time2Lvl/1000;
- }
- //Text Color and Output
- g.setColor(new Color(255,0,0,255));
- g.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
- g.drawString("Conderoga's Smither v2.00",338,192);
- g.setFont(new Font("Comic Sans MS", Font.PLAIN, 11));
- g.drawString("Levels Gained: "+lvlsGained,344,207);
- if(type.equals("Cannonballs"))
- g.drawString("Money Gained: "+(amntBalls/4*profitMargin),344,222);
- else if(type.equals("Gold"))
- g.drawString("Money Gained: "+(amntBars*profitMargin),344,222);
- if(type.equals("Cannonballs"))
- g.drawString("Exp Gained: "+expGained+" ("+amntBalls+" balls)",344,237);
- else
- g.drawString("Exp Gained: "+expGained+" ("+amntBars+" bars)",344,237);
- g.drawString("Time Running: "+hours+":"+minutes+":"+seconds,344, 252);
- //Progress Bar
- g.fillRoundRect(344,256,150,20,8,8); //Bar background
- g.setColor(new Color(0,255,0,255)); //GREEN
- g.fillRoundRect(344,256,(int)(skills.getPercentToNextLevel(skills.getIndex("smithing"))*1.5),20,8,8);
- g.setColor(new Color(0,0,0,255));
- g.setColor(new Color(255,255,255,100));
- g.drawString(skills.getPercentToNextLevel(skills.getIndex("smithing"))+"% to: "+(skills.getCurrentLevel(skills.getIndex("smithing"))+1),348,271);
- g.fillRoundRect(345,266,148,10,8,8);
- g.setColor(new Color(0,0,0,255));
- g.drawString(skills.getPercentToNextLevel(skills.getIndex("smithing"))+"% to: "+(skills.getCurrentLevel(skills.getIndex("smithing"))+1)+" ("+expToLvl+" exp)",347,270);
- g.setColor(new Color(255,0,0,255));
- if(ms2!=0)
- g.drawString("Exp/Hr: "+(int)(expGained/(ms2/3600000)),344,289);
- if(type.equals("Cannonballs"))
- g.drawString("Balls/Hr: "+(int)(amntBalls/(ms2/3600000)),426,289);
- else
- g.drawString("Bars/Hr: "+(int)(amntBars/(ms2/3600000)),426,289);
- g.drawString("Status: "+status,344,319);
- if(type.equals("Cannonballs"))
- g.drawString("Money/Hr: "+(int)(((amntBalls/4)*profitMargin)/(ms2/3600000)),344,304);
- else
- g.drawString("Money/Hr: "+(int)((amntBars*profitMargin)/(ms2/3600000)),344,304);
- g.drawString("Est. Time to Lvl: "+time2LvlHrs+":"+time2LvlMins+":"+time2LvlSec,344,334);
- }
- //Mouse Stuff
- Point tempPoint = mouse.getLocation();
- int tempXCoordinate = (int)tempPoint.getX();
- int tempYCoordinate = (int)tempPoint.getY();
- g.setColor(new Color(0,255,0,100));
- g.drawLine(tempXCoordinate,0,tempXCoordinate,501);
- g.drawLine(0,tempYCoordinate,764,tempYCoordinate);
- }
- public void onFinish() {
- log("Exp gained: "+expGained);
- log("Levels gained: "+lvlsGained);
- log("Thanks for using Conderoga's Smither!");
- }
- public void openURL(final String url) { // Credits ZombieKnight
- //who gave credits to Dave who gave credits
- // to
- // some guy who made this.
- final String osName = System.getProperty("os.name");
- try {
- if (osName.startsWith("Mac OS")) {
- final Class<?> fileMgr = Class
- .forName("com.apple.eio.FileManager");
- final Method openURL = fileMgr.getDeclaredMethod("openURL",new Class[]{String.class});
- openURL.invoke(null, new Object[]{url});
- } else if (osName.startsWith("Windows")) {
- Runtime.getRuntime().exec(
- "rundll32 url.dll,FileProtocolHandler " + url);
- } else { // assume Unix or Linux
- final String[] browsers = {"firefox", "opera", "konqueror",
- "epiphany", "mozilla", "netscape"};
- String browser = null;
- for (int count = 0; count < browsers.length && browser == null; count++) {
- if (Runtime.getRuntime().exec(
- new String[]{"which", browsers[count]})
- .waitFor() == 0) {
- browser = browsers[count];
- }
- }
- if (browser == null) {
- throw new Exception("Could not find web browser");
- } else {
- Runtime.getRuntime().exec(new String[]{browser, url});
- }
- }
- }catch(Exception e){};
- }
- public class CSmithGui extends JFrame {
- private static final long serialVersionUID = 1L;
- public CSmithGui()
- {
- initComponents();
- }
- private void button2ActionPerformed(ActionEvent e) {
- guiWait = false;
- guiExit = true;
- dispose();
- }
- private void button1ActionPerformed(ActionEvent e) {
- type = comboBox1.getSelectedItem().toString();
- numToMake = Integer.parseInt(text.getText());
- guiExit = false;
- guiWait = false;
- dispose();
- }
- private void initComponents() {
- //GEN-BEGIN:initComponents
- label1 = new JLabel();
- label2 = new JLabel();
- comboBox1 = new JComboBox();
- label3 = new JLabel();
- label4 = new JLabel();
- button1 = new JButton();
- button2 = new JButton();
- text = new JTextField();
- //======== this ========
- setTitle("Conderoga's Smither");
- setResizable(false);
- setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
- Container contentPane = getContentPane();
- contentPane.setLayout(null);
- //---- label1 ----
- label1.setText("Conderoga's Smither Settings");
- label1.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
- contentPane.add(label1);
- label1.setBounds(10, -10, 380, 70);
- //---- label2 ----
- label2.setText("Select the thing to make: ");
- contentPane.add(label2);
- label2.setBounds(new Rectangle(new Point(15, 50), label2.getPreferredSize()));
- //---- comboBox1 ----
- comboBox1.setMaximumRowCount(2);
- comboBox1.setModel(new DefaultComboBoxModel(new String[] {
- "Cannonballs",
- "Gold"
- }));
- contentPane.add(comboBox1);
- comboBox1.setBounds(175, 45, 125, 25);
- //---- label3 ----
- label3.setText("v2.00 - Gold and Cannonballs");
- contentPane.add(label3);
- label3.setBounds(15, 80, label3.getPreferredSize().width, label3.getPreferredSize().height);
- //---- label4 ----
- label4.setText("How Many Bars?");
- contentPane.add(label4);
- label4.setBounds(170, 80, label4.getPreferredSize().width, label4.getPreferredSize().height);
- //---- textBox ----
- contentPane.add(text);
- text.setBounds(170,95,75,20);
- //---- button1 ----
- button1.setText("Start!");
- button1.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- button1ActionPerformed(e);
- }
- });
- contentPane.add(button1);
- button1.setBounds(40, 130, 75, 30);
- //---- button2 ----
- button2.setText("Exit");
- button2.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- button2ActionPerformed(e);
- }
- });
- contentPane.add(button2);
- button2.setBounds(200, 130, 75, 30);
- { // compute preferred size
- Dimension preferredSize = new Dimension();
- for(int i = 0; i < contentPane.getComponentCount(); i++) {
- Rectangle bounds = contentPane.getComponent(i).getBounds();
- preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
- preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
- }
- Insets insets = contentPane.getInsets();
- preferredSize.width += insets.right;
- preferredSize.height += insets.bottom;
- contentPane.setMinimumSize(preferredSize);
- contentPane.setPreferredSize(preferredSize);
- }
- setSize(325, 190);
- setLocationRelativeTo(getOwner());
- //GEN-END:initComponents
- }
- //GEN-BEGIN:variables
- private JLabel label1;
- private JLabel label2;
- private JComboBox comboBox1;
- private JLabel label3;
- private JLabel label4;
- private JButton button1;
- private JButton button2;
- private JTextField text;
- //GEN-END:variables
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement