View difference between Paste ID: 2dvzbYzB and
SHOW: | | - or go back to the newest paste.
1-
1+
import java.awt.event.*;
2
import java.awt.*;
3
import java.util.*;
4
import java.io.*;
5
import java.net.*;
6
import java.lang.reflect.Method;
7
import javax.swing.*;
8
import org.rsbot.script.*;
9
import org.rsbot.script.methods.Game;
10
import org.rsbot.script.methods.Skills;
11
import org.rsbot.script.wrappers.*;
12
import org.rsbot.event.events.MessageEvent;
13
import org.rsbot.event.listeners.*;
14
import javax.imageio.ImageIO;
15
16
@ScriptManifest(authors = { "Conderoga" }, keywords = "Smithing", name = "Conderoga's Smither", version = 2.00,description = "Fast Edgeville Gold smelter/ Cannonball maker.")
17
/*UpdateLog:
18
   v1.00 - GUI, Paint, Edgeville only
19
   v2.00 - Revised for RSBot 2.0, added gold
20
21
 */
22
23
public class CSmith extends Script implements PaintListener, MessageListener {
24
25
private boolean guiWait = true;
26
private boolean guiExit = true;
27
private String type = "WAITING";
28
29
30
CSmithGui gui;
31
private int steelBarID = 2353;
32
private int goldBarID = 2357;
33
private int coalID = 453;
34
private int goldOreID = 444;
35
private int cannonballID = 2;
36
private int [] mouldID = {4};
37
38
private int steelBarValue = 0;
39
private int goldBarValue = 0;
40
private int goldOreValue = 0;
41
private int goldValue = 0;
42
private int cannonballValue = 0;
43
private int profitMargin = 0;
44
private int amntBalls = 0;
45
private int amntBars = 0;
46
private int numToMake = 1000000000;
47
48
private RSTile bankTile;
49
private RSTile furnaceTile;
50
private int furnaceID;
51
52
private int startLevel;
53
private int startExp;
54
private int expGained;
55
private int lvlsGained;
56
private long startTime;
57
private double startTimeDbl;
58
private long ExpHr;
59
private int safety = 0;
60
private String status;
61
private Point p;
62
private int tempNumSmithed = 0;
63
private int oneTimeOnly = 0;
64
65
66
67
68
 	public boolean onStart() {
69
 	//Credits to Zombieknight for this:-----------------
70
      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);
71
	  if (welcome == 0) {
72
		final String message = "<html>Thank you for your support!<br /></html>";
73
		JOptionPane.showMessageDialog(null, message);
74
		openURL("http://adf.ly/317631/agsn");
75
		}
76
	//=------------------------------------------------------*/
77
      gui = new CSmithGui();
78
      gui.setVisible(true);
79
      while(guiWait)
80
      {
81
        sleep(100);
82
      }
83
      startTime = System.currentTimeMillis();
84
      startTimeDbl = System.currentTimeMillis();
85
      log("Using "+numToMake+" bars.");
86
87
88
89
      return !guiExit;
90
    }
91
	public void startUpStuff()	{
92
		status = "Retrieving prices.";
93
		if(type.equals("Cannonballs")){
94
		steelBarValue = getGEValue("Steel Bar",2353);
95
		cannonballValue = getGEValue("Cannonball",2);
96
97
		profitMargin = (cannonballValue*4)-steelBarValue;
98
			}
99
		else if(type.equals("Gold")){
100
101
		goldBarValue = getGEValue("Gold bar",goldBarID);
102
		goldOreValue = getGEValue("Gold ore",goldOreID);
103
104
		profitMargin = goldBarValue-goldOreValue;
105
		}
106
107
108
			bankTile = new RSTile(3097,3495);
109
			furnaceTile = new RSTile(3110,3502);
110
			furnaceID = 26814;
111
112
		startTime = System.currentTimeMillis();
113
		status = "Starting.";
114
		camera.setAngle(0);
115
		camera.setPitch(true);
116
		if(walking.getEnergy()> 15)
117
		 	walking.setRun(true);
118
	}
119
	public void messageReceived(final MessageEvent e) {
120
		final String serverString = e.getMessage();
121
		if (serverString.toLowerCase().contains("remove the cannonballs from the"))
122
			amntBalls+=4;
123
		else if(serverString.toLowerCase().contains("you retrieve a bar"))
124
		{
125
			amntBars++;
126
		}
127
		else if(serverString.toLowerCase().contains("2"))
128
		{
129
			amntBars++;
130
		}
131
		else if(serverString.toLowerCase().contains("3"))
132
		{
133
			amntBars++;
134
			amntBars++;
135
		}
136
		else if(serverString.toLowerCase().contains("4"))
137
		{
138
			amntBars++;
139
			amntBars++;
140
			amntBars++;
141
		}
142
		else if(serverString.toLowerCase().contains("you've just advanced"))
143
		{
144
			smith();
145
		}
146
	}
147
	public boolean checkAnim()	{
148
		if(!hasBars())
149
			return false;
150
		for(int i = 0; i<5;i++){
151
152
		if(getMyPlayer().getAnimation()==827||getMyPlayer().getAnimation()==899||getMyPlayer().getAnimation()==3243)
153
		{ status = "Smithing.";
154
			return true;
155
		}
156
		sleep(500);
157
		}
158
			status = "Not Smithing.";
159
			return false;
160
	}
161
162
	public void walkToBank()
163
	{	status = "Walking to bank.";
164
	if(!walking.isRunEnabled()&&walking.getEnergy()>20){
165
 	 	 		walking.setRun(true);
166
 	 	 		sleep(random(600,800));
167
 	 	 		}
168
		walking.walkTileMM(bankTile);
169
		sleep(random(1500,2000));
170
		while(getMyPlayer().isMoving())
171
		sleep(random(100,200));
172
	}
173
	public boolean hasBars()
174
	{
175
		RSItem [] inv = inventory.getItems();
176
		for(int i = 0; i<inv.length;i++)
177
		{
178
			if(inv[i].getID()==steelBarID&&type.equals("Cannonballs"))
179
				return true;
180
			else if(inv[i].getID()==goldOreID&&type.equals("Gold"))
181
				return true;
182
		}
183
		return false;
184
	}
185
	public void bank()
186
	{
187
		mouse.setSpeed(random(6,8));
188
		camera.setPitch(true);
189
		do{
190
			mouse.move(calc.tileToScreen(bankTile),2,2);
191
			menu.doAction("Use-quickly Bank booth");
192
			sleep(random(1000,1200));
193
			}while(!bank.isOpen());
194
195
			status = "Depositing.";
196
			if(type.equals("Cannonballs"))
197
		 	bank.depositAllExcept(4);
198
		 	else
199
		 	bank.depositAll();
200
201
		 status = "Withdrawing.";
202
		 sleep(random(600,800));
203
		 mouse.move(55,109,5,5);
204
		 mouse.click(false);
205
                 sleep(random(600,800));
206
		 menu.doAction("Withdraw-All");
207
208
		 status = "Moving to furnace.";
209
		 walking.walkTileMM(new RSTile(3108,3501));
210
		 sleep(random(1500,2000));
211
		 while(getMyPlayer().isMoving())
212
			 sleep(random(100,200));
213
		 sleep(random(600,800));
214
215
	}
216
	public boolean isInRoom()
217
	{
218
		return getMyPlayer().getLocation().getX()>=3106&&getMyPlayer().getLocation().getX()<=3110&&getMyPlayer().getLocation().getY()>=3498&&getMyPlayer().getLocation().getY()<=3502;
219
220
	}
221
	public static int getGEValue(String name, int id){
222
    	try{
223
    		String [] temp = name.split(" ");
224
    		String newName = "";
225
    		for(int i = 0; i<temp.length; i++)
226
    			if(i==temp.length-1)
227
    				newName+=temp[i];
228
    			else
229
    				newName+="_"+temp[i];
230
    		URL url = new URL("http://services.runescape.com/m=itemdb_rs/"+newName+"/viewitem.ws?obj="+id);
231
    		InputStream is = url.openStream();
232
    		InputStreamReader isr = new InputStreamReader(is);
233
    		BufferedReader br = new BufferedReader(isr);
234
    		String line;
235
    		String num = "";
236
    		while((line=br.readLine())!=null){
237
    			if(line.contains("Current guide price:"))
238
    			 num = line;
239
    		}
240
    		System.out.println(num);
241
    		if(num.length()<29)
242
    			return -1;
243
    		else{
244
    			num = num.substring(28);
245
    			num = num.replaceAll(",", "");
246
    			return Integer.parseInt(num);
247
    		}
248
249
    		}catch(Exception e){
250
    			return -1;
251
    		}
252
    		}
253
	public void smith()
254
	{	status = "Starting to Smith";
255
		if(random(1,4)==2){
256
			camera.setAngle(0);
257
			camera.setPitch(true);
258
		}
259
		mouse.move(704,445,5,5);
260
		mouse.click(true);
261
		RSObject [] test = objects.getAllAt(furnaceTile);
262
 		RSObject furnace = null;
263
 		for(int i = 0; i<test.length;i++)
264
 		{
265
 			if(test[i].getID()==furnaceID){
266
 			furnace = test[i];
267
 			break;
268
 			}
269
 		}
270
 		RSModel m = furnace.getModel();
271
 		Point p = m.getPoint();
272
 		mouse.move(p,1,1);
273
 		mouse.click(true);
274
275
276
		sleep(random(1500,1600));
277
		int x = (type.equals("Cannonballs")) ? random(222,293) : random(235,284);
278
		int y = (type.equals("Cannonballs")) ? random(400,450) : random(398,449);
279
		mouse.move(x,y,0,0);
280
		mouse.click(true);
281
282
		sleep(random(600,800));
283
		checkAnim();
284
	}
285
	public Point midpoint(Point p1, Point p2)
286
	{
287
		Point temp = new Point((int)((p1.getX()+p2.getX())/2),(int)((p1.getY()+p2.getY())/2));
288
		return temp;
289
	}
290
    public int loop() {
291
        try{
292
293
        if(safety<1)
294
        {
295
        	startUpStuff();
296
   			safety=1;
297
        }
298
        boolean temp = checkAnim();
299
        boolean temp2 = hasBars();
300
        if(type.equals("Cannonballs")&&amntBalls/4 >= numToMake)
301
        {
302
        	log("Bar limit reached. Stopping script and logging out.");
303
        	game.logout(true);
304
        	stopScript();
305
        }
306
        else if(amntBars >= numToMake){
307
        	log("Bar limit reached. Stopping script and logging out.");
308
        	game.logout(true);
309
        	stopScript();
310
        }
311
		if(!temp&&temp2)
312
		{
313
			smith();
314
		}
315
		if(!temp&&!temp2&&isInRoom())
316
		{
317
			walkToBank();
318
			bank();
319
			smith();
320
		}
321
		if(!temp&&!temp2&&!isInRoom())
322
		{
323
			bank();
324
			smith();
325
		}
326
327
328
329
          antiBan(random(1,400));
330
        }
331
    catch (Exception e){}
332
    return random(600,800);
333
    }
334
   	public void antiBan(int rand){
335
	status += "(AB)";
336
	mouse.setSpeed(random(7,8));
337
	if(rand==1)
338
      if(random(1, 8) == 2)
339
            mouse.moveRandomly(900,1200);
340
   if(rand==2)
341
      if(random(1, 8) == 2)
342
            mouse.moveRandomly(400,800);
343
   if(rand==3)
344
      if(random(1, 8) == 2)
345
            mouse.moveRandomly(200,700);
346
347
   if(rand==4) //THIS CHECKS THE MINING STAT
348
      if(random(1, 6) == 2)
349
        {
350
            game.openTab(Game.TAB_STATS);
351
            sleep(random(600,800));
352
            skills.doHover(Skills.INTERFACE_SMITHING);
353
            sleep(random(1900,2000));
354
            game.openTab(Game.TAB_INVENTORY);
355
        }
356
   if(rand==5) //THIS CLICKS THE XP BUTTON UNDER THE COMPASS (Update thanks to Rawr =D)
357
   	  if(random(1, 24) == 2)
358
   	  {
359
   	  	 if (interfaces.get(548).getComponent(38).isValid()) {
360
                    return;
361
         } else {
362
         if (interfaces.get(548).getComponent(0).doClick()) {
363
            sleep(1500);
364
            }
365
            }
366
   	  }
367
   	  if(rand==7) //RANDOM SPIN
368
       if(random(1, 3) == 2)
369
       {int r = random(1,2);
370
       	camera.setAngle(random(1,359));
371
       	if(r!=1)
372
        camera.setPitch(random(1,99));}
373
374
     if(rand==8) //THIS CHECKS A RANDOM TAB
375
      if(random(1, 4) == 2)
376
        {
377
        	int[] tabs = {0,2,3,5,6,7,9,10,11,12,13,14,15};
378
            game.openTab(tabs[random(0,tabs.length-1)]);
379
            mouse.moveRandomly(175,200);
380
            sleep(random(1600,1800));
381
            sleep(random(900,1000));
382
383
        }
384
     if(rand==9)
385
     	if(random(1,10)==2)
386
     	mouse.moveOffScreen();
387
     status=status.substring(0,status.indexOf('('));
388
}
389
 	public void onRepaint(Graphics g)
390
    {
391
        if(game.isLoggedIn())
392
         {
393
          if(startExp==0)
394
          {
395
            startExp = skills.getCurrentExp(skills.getIndex("smithing"));
396
            startLevel = skills.getCurrentLevel(skills.getIndex("smithing"));
397
          }
398
399
           lvlsGained = skills.getCurrentLevel(skills.getIndex("smithing")) - startLevel;
400
           expGained =  skills.getCurrentExp(skills.getIndex("smithing")) - startExp;
401
402
        //setting up the time
403
          long ms = System.currentTimeMillis() - startTime;
404
          double ms2 = System.currentTimeMillis() - startTimeDbl;
405
          long hours = ms/3600000;
406
          ms = ms-(hours*3600000);
407
          long minutes = ms/60000;
408
          ms = ms-(minutes*60000);
409
          long seconds =  ms/1000;
410
                    //  		    |
411
        //Background                v transparency!
412
        g.setColor(new Color(0, 0, 0, 205));
413
		g.fillRoundRect(333, 175, 181, 164, 6, 6); //Background
414
		long expToLvl = skills.getExpToNextLevel(skills.getIndex("smithing"));
415
		long time2Lvl = 0;
416
		long time2LvlHrs = 0;
417
		long time2LvlMins = 0;
418
		long time2LvlSec = 0;
419
		if(ms2!=0&&expGained!=0){
420
		time2Lvl = (long)(expToLvl/(expGained/(ms2/3600000))*3600000);
421
		time2LvlHrs = time2Lvl/3600000;
422
		time2Lvl -= time2LvlHrs*3600000;
423
		time2LvlMins = time2Lvl/60000;
424
		time2Lvl -= time2LvlMins*60000;
425
		time2LvlSec = time2Lvl/1000;
426
		}
427
        //Text Color and Output
428
        g.setColor(new Color(255,0,0,255));
429
        g.setFont(new Font("Comic Sans MS", Font.PLAIN, 12));
430
        g.drawString("Conderoga's Smither v2.00",338,192);
431
		g.setFont(new Font("Comic Sans MS", Font.PLAIN, 11));
432
        g.drawString("Levels Gained: "+lvlsGained,344,207);
433
        if(type.equals("Cannonballs"))
434
        g.drawString("Money Gained: "+(amntBalls/4*profitMargin),344,222);
435
        else if(type.equals("Gold"))
436
        g.drawString("Money Gained: "+(amntBars*profitMargin),344,222);
437
438
439
440
        if(type.equals("Cannonballs"))
441
        g.drawString("Exp Gained: "+expGained+" ("+amntBalls+" balls)",344,237);
442
        else
443
        g.drawString("Exp Gained: "+expGained+" ("+amntBars+" bars)",344,237);
444
        g.drawString("Time Running: "+hours+":"+minutes+":"+seconds,344, 252);
445
446
        //Progress Bar
447
        g.fillRoundRect(344,256,150,20,8,8); //Bar background
448
        g.setColor(new Color(0,255,0,255)); //GREEN
449
        g.fillRoundRect(344,256,(int)(skills.getPercentToNextLevel(skills.getIndex("smithing"))*1.5),20,8,8);
450
        g.setColor(new Color(0,0,0,255));
451
        g.setColor(new Color(255,255,255,100));
452
        g.drawString(skills.getPercentToNextLevel(skills.getIndex("smithing"))+"% to: "+(skills.getCurrentLevel(skills.getIndex("smithing"))+1),348,271);
453
		g.fillRoundRect(345,266,148,10,8,8);
454
		g.setColor(new Color(0,0,0,255));
455
        g.drawString(skills.getPercentToNextLevel(skills.getIndex("smithing"))+"% to: "+(skills.getCurrentLevel(skills.getIndex("smithing"))+1)+" ("+expToLvl+" exp)",347,270);
456
        g.setColor(new Color(255,0,0,255));
457
        if(ms2!=0)
458
         g.drawString("Exp/Hr: "+(int)(expGained/(ms2/3600000)),344,289);
459
         if(type.equals("Cannonballs"))
460
         g.drawString("Balls/Hr: "+(int)(amntBalls/(ms2/3600000)),426,289);
461
         else
462
         g.drawString("Bars/Hr: "+(int)(amntBars/(ms2/3600000)),426,289);
463
464
		 g.drawString("Status: "+status,344,319);
465
		 if(type.equals("Cannonballs"))
466
		 g.drawString("Money/Hr: "+(int)(((amntBalls/4)*profitMargin)/(ms2/3600000)),344,304);
467
		 else
468
		 g.drawString("Money/Hr: "+(int)((amntBars*profitMargin)/(ms2/3600000)),344,304);
469
470
		 g.drawString("Est. Time to Lvl: "+time2LvlHrs+":"+time2LvlMins+":"+time2LvlSec,344,334);
471
        }
472
        //Mouse Stuff
473
        Point tempPoint = mouse.getLocation();
474
        int tempXCoordinate = (int)tempPoint.getX();
475
        int tempYCoordinate = (int)tempPoint.getY();
476
        g.setColor(new Color(0,255,0,100));
477
        	g.drawLine(tempXCoordinate,0,tempXCoordinate,501);
478
        	g.drawLine(0,tempYCoordinate,764,tempYCoordinate);
479
480
      }
481
    public void onFinish() {
482
        log("Exp gained: "+expGained);
483
        log("Levels gained: "+lvlsGained);
484
        log("Thanks for using Conderoga's Smither!");
485
    }
486
    public void openURL(final String url) { // Credits ZombieKnight
487
    //who gave credits to Dave who gave credits
488
    // to
489
    // some guy who made this.
490
    final String osName = System.getProperty("os.name");
491
    try {
492
      if (osName.startsWith("Mac OS")) {
493
        final Class<?> fileMgr = Class
494
            .forName("com.apple.eio.FileManager");
495
        final Method openURL = fileMgr.getDeclaredMethod("openURL",new Class[]{String.class});
496
        openURL.invoke(null, new Object[]{url});
497
      } else if (osName.startsWith("Windows")) {
498
        Runtime.getRuntime().exec(
499
            "rundll32 url.dll,FileProtocolHandler " + url);
500
      } else { // assume Unix or Linux
501
        final String[] browsers = {"firefox", "opera", "konqueror",
502
            "epiphany", "mozilla", "netscape"};
503
        String browser = null;
504
        for (int count = 0; count < browsers.length && browser == null; count++) {
505
          if (Runtime.getRuntime().exec(
506
              new String[]{"which", browsers[count]})
507
              .waitFor() == 0) {
508
            browser = browsers[count];
509
          }
510
        }
511
        if (browser == null) {
512
          throw new Exception("Could not find web browser");
513
        } else {
514
          Runtime.getRuntime().exec(new String[]{browser, url});
515
        }
516
      }
517
    }catch(Exception e){};
518
  }
519
    public class CSmithGui extends JFrame {
520
521
 		private static final long serialVersionUID = 1L;
522
  		public CSmithGui()
523
  			{
524
    	initComponents();
525
  			}
526
527
  		private void button2ActionPerformed(ActionEvent e) {
528
   		 guiWait = false;
529
    	 guiExit = true;
530
    	 dispose();
531
  			}
532
533
  		private void button1ActionPerformed(ActionEvent e) {
534
    		type = comboBox1.getSelectedItem().toString();
535
    		numToMake = Integer.parseInt(text.getText());
536
    		guiExit = false;
537
    		guiWait = false;
538
    		dispose();
539
  			}
540
541
  		private void initComponents() {
542
    		//GEN-BEGIN:initComponents
543
    		label1 = new JLabel();
544
    		label2 = new JLabel();
545
    		comboBox1 = new JComboBox();
546
    		label3 = new JLabel();
547
    		label4 = new JLabel();
548
    		button1 = new JButton();
549
    		button2 = new JButton();
550
    		text = new JTextField();
551
552
    //======== this ========
553
    setTitle("Conderoga's Smither");
554
    setResizable(false);
555
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
556
    Container contentPane = getContentPane();
557
    contentPane.setLayout(null);
558
559
    //---- label1 ----
560
    label1.setText("Conderoga's Smither Settings");
561
    label1.setFont(new Font("Comic Sans MS", Font.PLAIN, 16));
562
    contentPane.add(label1);
563
    label1.setBounds(10, -10, 380, 70);
564
565
    //---- label2 ----
566
    label2.setText("Select the thing to make: ");
567
    contentPane.add(label2);
568
    label2.setBounds(new Rectangle(new Point(15, 50), label2.getPreferredSize()));
569
570
    //---- comboBox1 ----
571
    comboBox1.setMaximumRowCount(2);
572
    comboBox1.setModel(new DefaultComboBoxModel(new String[] {
573
      "Cannonballs",
574
      "Gold"
575
576
577
    }));
578
    contentPane.add(comboBox1);
579
    comboBox1.setBounds(175, 45, 125, 25);
580
581
    //---- label3 ----
582
    label3.setText("v2.00 - Gold and Cannonballs");
583
    contentPane.add(label3);
584
    label3.setBounds(15, 80, label3.getPreferredSize().width, label3.getPreferredSize().height);
585
586
	//---- label4 ----
587
    label4.setText("How Many Bars?");
588
    contentPane.add(label4);
589
    label4.setBounds(170, 80, label4.getPreferredSize().width, label4.getPreferredSize().height);
590
591
592
	//---- textBox ----
593
	contentPane.add(text);
594
	text.setBounds(170,95,75,20);
595
596
    //---- button1 ----
597
    button1.setText("Start!");
598
    button1.addActionListener(new ActionListener() {
599
      public void actionPerformed(ActionEvent e) {
600
        button1ActionPerformed(e);
601
      }
602
    });
603
    contentPane.add(button1);
604
    button1.setBounds(40, 130, 75, 30);
605
606
    //---- button2 ----
607
    button2.setText("Exit");
608
    button2.addActionListener(new ActionListener() {
609
      public void actionPerformed(ActionEvent e) {
610
        button2ActionPerformed(e);
611
      }
612
    });
613
    contentPane.add(button2);
614
    button2.setBounds(200, 130, 75, 30);
615
616
    { // compute preferred size
617
      Dimension preferredSize = new Dimension();
618
      for(int i = 0; i < contentPane.getComponentCount(); i++) {
619
        Rectangle bounds = contentPane.getComponent(i).getBounds();
620
        preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
621
        preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
622
      }
623
      Insets insets = contentPane.getInsets();
624
      preferredSize.width += insets.right;
625
      preferredSize.height += insets.bottom;
626
      contentPane.setMinimumSize(preferredSize);
627
      contentPane.setPreferredSize(preferredSize);
628
    }
629
    setSize(325, 190);
630
    setLocationRelativeTo(getOwner());
631
    //GEN-END:initComponents
632
  }
633
634
  //GEN-BEGIN:variables
635
  private JLabel label1;
636
  private JLabel label2;
637
  private JComboBox comboBox1;
638
  private JLabel label3;
639
  private JLabel label4;
640
  private JButton button1;
641
  private JButton button2;
642
  private JTextField text;
643
  //GEN-END:variables
644
}
645
}