Thondar

s

Jun 11th, 2011
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.42 KB | None | 0 0
  1. import org.rsbot.event.listeners.PaintListener;
  2. import org.rsbot.script.*;
  3. import org.rsbot.script.methods.Skills;
  4. import org.rsbot.script.wrappers.*;
  5.  
  6. import javax.imageio.ImageIO;
  7. import javax.swing.*;
  8. import java.awt.*;
  9. import java.awt.event.ActionEvent;
  10. import java.awt.event.ActionListener;
  11. import java.io.IOException;
  12. import java.net.URL;
  13.  
  14.  
  15. @ScriptManifest(authors = {"TT Production"}, keywords = {"Al kharid", "Smelter"}, name = "TT Smelter", description = "Smelts ores in Al Kharid", version = 0.1)
  16.  
  17. public class TTSmelter extends Script implements PaintListener{
  18.  
  19. RSTile furnaceTile = new RSTile (3276,3186);
  20. RSTile bankTile = new RSTile (3270,3166);
  21.  
  22. int oreID1;
  23. int oreID2;
  24. int oreAmount1;
  25. int oreAmount2;
  26. int paintOre1;
  27. int paintOre2;
  28. int barID;
  29. int buttonID;
  30. int bankerID = 496;
  31. int furnaceID = 11666;
  32. int Inventory = 0;
  33. int ironOre = 440;
  34. int idle = -1;
  35. int smelting = 3243;
  36. int barsGot;
  37. int barPrice;
  38. int orePrice1;
  39. int orePrice2;
  40. int barcheck;
  41. int expGained = 0;
  42. int expStart = 0;
  43.  
  44. long starttime;
  45.  
  46. private boolean restCheck;
  47. private boolean antibanCheck;
  48.  
  49. gui g = new gui();
  50.  
  51. private boolean guiWait = true;
  52.  
  53. String optionBar;
  54.  
  55.  
  56. @Override
  57. public boolean onStart() {
  58. mouse.setSpeed(random(4, 6));
  59. starttime = System.currentTimeMillis();
  60. expStart = skills.getCurrentExp(Skills.SMITHING);
  61. g.setVisible(true);
  62. while(guiWait) sleep(500);
  63. barPrice = grandExchange.lookup(barID).getGuidePrice();
  64. orePrice1 = grandExchange.lookup(oreID1).getGuidePrice();
  65. orePrice2 = grandExchange.lookup(oreID2).getGuidePrice();
  66. walking.setRun(true);
  67. return true;
  68. }
  69.  
  70. public void bank() {
  71. RSNPC banker = npcs.getNearest(bankerID);
  72. camera.turnTo(banker);
  73. if(restCheck == true);
  74. if(walking.getEnergy() < 30)
  75. walking.rest(random(70,95));
  76. if (bank.isOpen() && !inventory.contains(oreID1)) {
  77. bank.depositAll();
  78. Inventory = inventory.getCount(barID);
  79. barsGot += Inventory;
  80. sleep(400, 650);
  81. bank.withdraw(oreID1, oreAmount1);
  82. sleep(500, 750);
  83. if (oreID1 == 436 | oreID1 == 440 | oreID1 == 447 | oreID1 == 449 | oreID1 == 451){
  84. bank.withdraw(oreID2, oreAmount2);
  85. }
  86. sleep(800, 1100);
  87. bank.close();
  88. } else {
  89. if(banker != null) {
  90. if(banker.isOnScreen())
  91. banker.doAction("Bank Banker");{
  92. } sleep(1800, 2100);
  93. } else {
  94. walking.getPath(bankTile).traverse();
  95. }
  96. }
  97. }
  98.  
  99. public void smeltOres(){
  100. barcheck = inventory.getCount(barID);
  101. RSObject furnace = objects.getNearest(furnaceID);
  102. if(restCheck == true);
  103. if(walking.getEnergy() < 30)
  104. walking.rest(random(70,95));
  105. if (furnace.isOnScreen()){
  106. if (barcheck < 1)
  107. furnace.doAction("Smelt");
  108. sleep (1500, 1800);
  109. mouse.click(280,424,true);
  110. sleep(1700, 1900);
  111. }
  112. }
  113.  
  114.  
  115. public boolean atBank(){
  116. RSArea BankArea = new RSArea(new RSTile(3265, 3160),
  117. new RSTile(3272, 3273));
  118. return BankArea.contains(getMyPlayer().getLocation());
  119. }
  120.  
  121. public boolean atAlKharid(){
  122. RSArea AlKharidArea = new RSArea(new RSTile(3264, 3160),
  123. new RSTile(3286, 3197));
  124. return AlKharidArea.contains(getMyPlayer().getLocation());
  125. }
  126.  
  127.  
  128. public boolean atFurnace(){
  129. RSArea FurnaceArea = new RSArea(new RSTile(3272, 3181),
  130. new RSTile(3279, 3188));
  131. return FurnaceArea.contains(getMyPlayer().getLocation());
  132. }
  133.  
  134. private void rest() {
  135. if(restCheck == true);
  136. if(walking.getEnergy() < 30)
  137. walking.rest(random(70,95));
  138. }
  139.  
  140. public int loop() {
  141. if(atBank() && !inventory.contains(oreID1)){
  142. bank();
  143. log ("1");
  144. }
  145. if(atBank() && inventory.contains(barID)){
  146. bank();
  147. log ("2");
  148. }
  149. if(atFurnace() && inventory.contains(oreID1)){
  150. smeltOres();
  151. log ("3");
  152. }
  153. if(!atFurnace() && inventory.contains(oreID1)){
  154. walking.walkTo(furnaceTile);
  155. log ("4");
  156. }
  157. if(!atBank() && !inventory.contains(oreID1)){
  158. walking.walkTo(bankTile);
  159. log ("5");
  160. }
  161.  
  162. if(antibanCheck == true) {
  163. antiBan();
  164. }
  165. if(restCheck == true) {
  166. rest();
  167. }
  168. return random(500, 1500);
  169. }
  170.  
  171. private void antiBan() {
  172. int t = random(0, 10);
  173. int r = random(0, 15);
  174. if (t == 7);
  175. if (r == 2) {
  176. mouse.moveSlightly();
  177. sleep(500, 800);
  178. }
  179.  
  180. if (r == 3) {
  181. mouse.moveRandomly(10, 50);
  182. }
  183.  
  184. if (r == 5) {
  185. camera.moveRandomly(random(350, 650));
  186. }
  187.  
  188. if (r == 6) {
  189. camera.moveRandomly(random(450, 750));
  190. }
  191.  
  192. if (r == 8) {
  193. camera.moveRandomly(random(150, 450));
  194. }
  195.  
  196. if (r == 10) {
  197. camera.moveRandomly(random(750, 1250));
  198. }
  199.  
  200. if (r == 12) {
  201. mouse.moveOffScreen();
  202. }
  203.  
  204. if (r == 14) {
  205. camera.moveRandomly(random(500, 900));
  206. }
  207. }
  208.  
  209.  
  210. public void onFinish() {
  211. }
  212.  
  213. //---------- PAINT -------------//
  214.  
  215. private Image getImage(String url) {
  216. try {
  217. return ImageIO.read(new URL(url));
  218. } catch(IOException e) {
  219. return null;
  220. }
  221. }
  222.  
  223. private final Color color1 = new Color(255, 255, 255);
  224.  
  225. private final Font font1 = new Font("Calibri", 0, 18);
  226.  
  227. private final Image img1 = getImage("http://i.imgur.com/Dtg7V.jpg");
  228. private final Image img2 = getImage("http://i.imgur.com/cYgmN.png");
  229. private final Image img3 = getImage("http://i.imgur.com/cwGcs.gif");
  230. private final Image img4 = getImage("http://i.imgur.com/DZYci.png");
  231. private final Image img5 = getImage("http://i.imgur.com/qpagD.png");
  232. private final Image img6 = getImage("http://i.imgur.com/1d2Ws.png");
  233. private final Image img9 = getImage("http://i.imgur.com/cayCD.png");
  234. private final Image img8 = getImage("http://i.imgur.com/AwBMJ.png");
  235. private final Image img10 = getImage("http://i.imgur.com/jUylh.png");
  236. private final Image img14 = getImage("http://i.imgur.com/0g8dI.png");
  237. private final Image img15 = getImage("http://i.imgur.com/e6Fw2.png");
  238. private final Image img16 = getImage("http://i.imgur.com/aUisg.png");
  239. private final Image img17 = getImage("http://i.imgur.com/2fxLu.png");
  240.  
  241.  
  242. public void onRepaint(Graphics g1) {
  243.  
  244. expGained = skills.getCurrentExp(Skills.SMITHING) - expStart;
  245.  
  246. long millis = System.currentTimeMillis() - starttime;
  247. long hours = millis / (1000 * 60 * 60);
  248. millis -= hours * (1000 * 60 * 60);
  249. long minutes = millis / (1000 * 60);
  250. millis -= minutes * (1000 * 60);
  251. long seconds = millis / 1000;
  252.  
  253. float barsec = 0;
  254. if ((minutes > 0 || hours > 0 || seconds > 0) && barsGot > 0) {
  255. barsec = ((float) barsGot)/(float)(seconds + (minutes*60) + (hours*60*60));
  256. }
  257.  
  258. float xpsec = 0;
  259. if ((minutes > 0 || hours > 0 || seconds > 0) && expGained > 0) {
  260. barsec = ((float) expGained)/(float)(seconds + (minutes*60) + (hours*60*60));
  261. }
  262.  
  263. float barmin = barsec * 60;
  264. float abarhour = barmin * 60;
  265. float xpmin = xpsec * 60;
  266. float axphour = xpmin * 60;
  267. int ore1spend = orePrice1 * paintOre1;
  268. int ore2spend = orePrice2 * paintOre2;
  269. int goldspend = ore1spend + ore2spend;
  270. int totalBarPrice = barPrice - goldspend;
  271. float agoldhour = abarhour * totalBarPrice;
  272. int goldearned = barsGot * totalBarPrice;
  273. int barhour = Math.round(abarhour);
  274. int goldhour = Math.round(agoldhour);
  275. int xphour = Math.round(axphour);
  276.  
  277.  
  278. Graphics2D g = (Graphics2D)g1;
  279. g.drawImage(img1, 7, 345, null);
  280. g.drawImage(img2, 11, 439, null);
  281. g.drawImage(img3, 9, 392, null);
  282. g.drawImage(img4, 8, 349, null);
  283. g.setFont(font1);
  284. g.setColor(color1);
  285. g.drawString(+ hours + ":" + minutes + ":" + seconds, 428, 469);
  286. g.drawString("" + goldearned, 70, 417);
  287. g.drawString("" + goldhour, 240, 417);
  288. g.drawString("" + barsGot, 70, 462);
  289. g.drawString("" + barhour, 240, 462);
  290. g.drawString("" + xphour, 240, 371);
  291. g.drawString("" + expGained, 70, 371);
  292. g.drawImage(img5, -4, 428, null);
  293. g.drawImage(img5, -4, 382, null);
  294. g.drawImage(img9, -11, 338, null);
  295. g.drawImage(img6, 510, 332, null);
  296. g.drawImage(img10, 39, 340, null);
  297. g.drawImage(img10, 39, 386, null);
  298. g.drawImage(img10, 378, 340, null);
  299. g.drawImage(img10, 203, 340, null);
  300. g.drawImage(img10, 378, 386, null);
  301. g.drawImage(img10, 203, 385, null);
  302. g.drawImage(img8, -2, 335, null);
  303. g.drawImage(img8, -2, 468, null);
  304. g.drawImage(img14, 150, 403, null);
  305. g.drawImage(img14, 150, 448, null);
  306. g.drawImage(img14, 150, 360, null);
  307. g.drawImage(img15, 325, 403, null);
  308. g.drawImage(img15, 325, 448, null);
  309. g.drawImage(img15, 325, 360, null);
  310. g.drawImage(img16, 398, 346, null);
  311. g.drawImage(img17, 75, 292, null);
  312.  
  313. }
  314.  
  315.  
  316. //------------ GUI -------------//
  317.  
  318. class gui extends JFrame {
  319. public gui() {
  320. initComponents();
  321. }
  322.  
  323. private void startButtonActionPerformed(ActionEvent e) {
  324. String optionBar = oresToSmelt.getSelectedItem().toString();
  325.  
  326. if(optionBar.equals("Bronze")) {
  327. barID = 2349;
  328. oreID1 = 436;
  329. oreID2 = 438;
  330. oreAmount1 = 14;
  331. oreAmount2 = 14;
  332. paintOre1 = 1;
  333. paintOre2 = 1;
  334. }
  335. else if(optionBar.equals("Iron")) {
  336. barID = 2351;
  337. oreID1 = ironOre;
  338. oreAmount1 = 28;
  339. paintOre1 = 1;
  340. paintOre2 = 0;
  341. }
  342. else if(optionBar.equals("Silver")) {
  343. barID = 2355;
  344. oreID1 = 442;
  345. oreAmount1 = 28;
  346. paintOre1 = 1;
  347. paintOre2 = 0;
  348. }
  349. else if(optionBar.equals("Steel")) {
  350. barID = 2353;
  351. oreID1 = 440;
  352. oreID2 = 453;
  353. oreAmount1 = 9;
  354. oreAmount2 = 18;
  355. paintOre1 = 1;
  356. paintOre2 = 2;
  357. }
  358. else if(optionBar.equals("Gold")) {
  359. barID = 2357;
  360. oreID1 = 444;
  361. oreAmount1 = 28;
  362. paintOre1 = 1;
  363. paintOre2 = 0;
  364. }
  365. else if(optionBar.equals("Mithril")) {
  366. barID = 2359;
  367. oreID1 = 447;
  368. oreID2 = 453;
  369. oreAmount1 = 5;
  370. oreAmount2 = 20;
  371. paintOre1 = 1;
  372. paintOre2 = 4;
  373. }
  374. else if(optionBar.equals("Adamantite")) {
  375. barID = 2361;
  376. oreID1 = 449;
  377. oreID2 = 453;
  378. oreAmount1 = 4;
  379. oreAmount2 = 24;
  380. paintOre1 = 1;
  381. paintOre2 = 6;
  382. }
  383. else {
  384. barID = 2363;
  385. oreID1 = 451;
  386. oreID2 = 453;
  387. oreAmount1 = 3;
  388. oreAmount2 = 24;
  389. paintOre1 = 1;
  390. paintOre2 = 8;
  391. }
  392. guiWait = false;
  393. g.dispose();
  394. }
  395.  
  396. private void initComponents() {
  397. // JFormDesigner - Component initialization - DO NOT MODIFY //GEN-BEGIN:initComponents
  398. // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
  399. label1 = new JLabel();
  400. label2 = new JLabel();
  401. checkBox1 = new JCheckBox();
  402. checkBox2 = new JCheckBox();
  403. startButton = new JButton();
  404. oresToSmelt = new JComboBox();
  405.  
  406. //======== this ========
  407. Container contentPane = getContentPane();
  408.  
  409. //---- label1 ----
  410. label1.setText("TT Smelter");
  411. label1.setFont(label1.getFont().deriveFont(label1.getFont().getSize() + 9f));
  412. label1.setHorizontalAlignment(SwingConstants.CENTER);
  413.  
  414. //---- label2 ----
  415. label2.setText("Ores to smelt:");
  416. label2.setFont(label2.getFont().deriveFont(label2.getFont().getSize() + 2f));
  417.  
  418. //---- checkBox1 ----
  419. checkBox1.setText("Rest");
  420.  
  421. //---- checkBox2 ----
  422. checkBox2.setText("Antiban");
  423.  
  424. //---- startButton ----
  425. startButton.setText("Start");
  426. startButton.setFont(startButton.getFont().deriveFont(startButton.getFont().getSize() + 2f));
  427. startButton.addActionListener(new ActionListener() {
  428. @Override
  429. public void actionPerformed(ActionEvent e) {
  430. startButtonActionPerformed(e);
  431. startButtonActionPerformed(e);
  432. }
  433. });
  434.  
  435. //---- oresToSmelt ----
  436. oresToSmelt.setModel(new DefaultComboBoxModel(new String[] {
  437. "Bronze",
  438. "Silver",
  439. "Gold",
  440. "Iron",
  441. "Steel",
  442. "Mithril",
  443. "Adamantite",
  444. "Runite"
  445. }));
  446.  
  447. GroupLayout contentPaneLayout = new GroupLayout(contentPane);
  448. contentPane.setLayout(contentPaneLayout);
  449. contentPaneLayout.setHorizontalGroup(
  450. contentPaneLayout.createParallelGroup()
  451. .addGroup(contentPaneLayout.createSequentialGroup()
  452. .addContainerGap()
  453. .addGroup(contentPaneLayout.createParallelGroup()
  454. .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
  455. .addGroup(contentPaneLayout.createParallelGroup()
  456. .addGroup(contentPaneLayout.createSequentialGroup()
  457. .addComponent(label2, GroupLayout.DEFAULT_SIZE, 85, Short.MAX_VALUE)
  458. .addGap(18, 18, 18)
  459. .addComponent(oresToSmelt, GroupLayout.PREFERRED_SIZE, 154, GroupLayout.PREFERRED_SIZE))
  460. .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
  461. .addComponent(checkBox1, GroupLayout.PREFERRED_SIZE, 81, GroupLayout.PREFERRED_SIZE)
  462. .addGap(34, 34, 34)
  463. .addComponent(checkBox2, GroupLayout.PREFERRED_SIZE, 88, GroupLayout.PREFERRED_SIZE)))
  464. .addGap(20, 20, 20))
  465. .addGroup(contentPaneLayout.createSequentialGroup()
  466. .addComponent(startButton, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
  467. .addContainerGap())
  468. .addGroup(contentPaneLayout.createSequentialGroup()
  469. .addComponent(label1, GroupLayout.DEFAULT_SIZE, 267, Short.MAX_VALUE)
  470. .addContainerGap())))
  471. );
  472. contentPaneLayout.setVerticalGroup(
  473. contentPaneLayout.createParallelGroup()
  474. .addGroup(contentPaneLayout.createSequentialGroup()
  475. .addGap(6, 6, 6)
  476. .addComponent(label1, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  477. .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
  478. .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  479. .addComponent(label2, GroupLayout.PREFERRED_SIZE, 25, GroupLayout.PREFERRED_SIZE)
  480. .addComponent(oresToSmelt, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE))
  481. .addGap(18, 18, 18)
  482. .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
  483. .addComponent(checkBox2)
  484. .addComponent(checkBox1))
  485. .addGap(12, 12, 12)
  486. .addComponent(startButton, GroupLayout.PREFERRED_SIZE, 36, GroupLayout.PREFERRED_SIZE)
  487. .addContainerGap())
  488. );
  489. pack();
  490. setLocationRelativeTo(getOwner());
  491. // JFormDesigner - End of component initialization //GEN-END:initComponents
  492. }
  493.  
  494. // JFormDesigner - Variables declaration - DO NOT MODIFY //GEN-BEGIN:variables
  495. // Generated using JFormDesigner Evaluation license - Jonas Bill Jensen
  496. private JLabel label1;
  497. private JLabel label2;
  498. private JCheckBox checkBox1;
  499. private JCheckBox checkBox2;
  500. private JButton startButton;
  501. private JComboBox oresToSmelt;
  502. // JFormDesigner - End of variables declaration //GEN-END:variables
  503. }
  504. }
Advertisement
Add Comment
Please, Sign In to add comment