Thondar

sd

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