Thondar

sd

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