Thondar

TT Smelter 0.1

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