Thondar

sd

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