brandon1000

my fishing script GUI NO WORK, banking still buggy

Jul 31st, 2012
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.53 KB | None | 0 0
  1. //paint
  2. import java.util.ArrayList;
  3. import java.awt.*;
  4. //GUI
  5. import java.awt.event.ActionEvent;
  6. import javax.swing.*;
  7. import com.jgoodies.forms.factories.*;
  8. import com.jgoodies.forms.layout.*;
  9. //script
  10. import org.powerbot.concurrent.Task;
  11. import org.powerbot.concurrent.strategy.Condition;
  12. import org.powerbot.concurrent.strategy.Strategy;
  13. import org.powerbot.game.api.ActiveScript;
  14. import org.powerbot.game.api.Manifest;
  15. import org.powerbot.game.api.methods.Game;
  16. import org.powerbot.game.api.methods.Tabs;
  17. import org.powerbot.game.api.methods.Widgets;
  18. import org.powerbot.game.api.methods.input.Mouse;
  19. import org.powerbot.game.api.methods.interactive.NPCs;
  20. import org.powerbot.game.api.methods.interactive.Players;
  21. import org.powerbot.game.api.methods.node.GroundItems;
  22. import org.powerbot.game.api.methods.tab.Inventory;
  23. import org.powerbot.game.api.util.Filter;
  24. import org.powerbot.game.api.util.Random;
  25. import org.powerbot.game.api.util.Time;
  26. import org.powerbot.game.api.util.Timer;
  27. import org.powerbot.game.api.wrappers.Area;
  28. import org.powerbot.game.api.wrappers.Tile;
  29. import org.powerbot.game.api.wrappers.interactive.NPC;
  30. import org.powerbot.game.api.wrappers.map.TilePath;
  31. import org.powerbot.game.api.wrappers.node.Item;
  32. import org.powerbot.game.api.wrappers.widget.WidgetChild;
  33. import org.powerbot.game.bot.event.listener.PaintListener;
  34.  
  35. @Manifest(name = "TEST FISHER", description = "TEST THIS ONE", version = 0.1, authors = {"brandon"})
  36. public class TEST extends ActiveScript implements PaintListener {
  37. //PAINT VARRIABLES
  38. String status;
  39. String Location;
  40. public Timer TIME;
  41. public Timer ERROR_TIMES;
  42. long runtime;
  43.  
  44. int runningFishCount = -1;
  45. int startCount = -1;
  46. int bankedfishCount = 0;
  47. int animation;
  48. int client_state;
  49.  
  50. int fish = 0;
  51.  
  52. int before;
  53. int after;
  54. int GAINED;
  55. int FISH = -1;
  56.  
  57. private final Color color1 = new Color(255, 255, 255);
  58. private final Color color2 = new Color(0, 0, 0);
  59. private final BasicStroke stroke1 = new BasicStroke(1);
  60. private final Font font1 = new Font("Arial", 0, 20);
  61. private final Font font2 = new Font("Arial", 0, 10);
  62. //paint variables
  63.  
  64. //GUI
  65. SuperSkillerGUI GUI;
  66.  
  67.  
  68.  
  69. //GUI
  70.  
  71. //script
  72. private boolean run;
  73. private boolean bank = true;
  74. private boolean drop = false;
  75.  
  76. private boolean fishing;
  77. private boolean fly;
  78.  
  79.  
  80. private boolean pickup;
  81. private boolean GP_priority = true;
  82. private boolean XP_priotiy = false;
  83.  
  84. private final int fishies[] = {335,331,349};
  85. private final int fishA1 = 335;// trout
  86. private final int fishA2 = 331;//salmon
  87. private final int fishA3 = 349;//pike
  88. private final int pools[] = {328};
  89. private final int items[] = {314,313};
  90. private final int banks = 553;
  91.  
  92.  
  93. //barbarian outpost
  94. private boolean barb;
  95. private final Area lebank = new Area(new Tile(3091, 3488, 0) , new Tile(3097, 3498, 0));
  96. private final Area lefish = new Area(new Tile(3099, 3423, 0) , new Tile(3112, 3440, 0));
  97. public final Tile[] Bankpath = {
  98. new Tile(3105, 3431, 0), new Tile(3100, 3440, 0),
  99. new Tile(3097, 3450, 0), new Tile(3096, 3460, 0),
  100. new Tile(3098, 3470, 0), new Tile(3101, 3481, 0),
  101. new Tile(3093, 3491, 0)
  102. };
  103. private final TilePath pathToBank = new TilePath(Bankpath);
  104. public final Tile[] Fishpath = {
  105. new Tile(3093, 3491, 0) , new Tile(3101, 3481, 0),
  106. new Tile(3098, 3470, 0), new Tile(3096, 3460, 0),
  107. new Tile(3097, 3450, 0), new Tile(3100, 3440, 0),
  108. new Tile(3105, 3431, 0)
  109. };
  110. public final TilePath pathToFish = new TilePath(Fishpath);
  111. //script
  112.  
  113. public void setup(){
  114.  
  115. SwingUtilities.invokeLater(new Runnable() {
  116. public void run() {
  117. final SuperSkillerGUI GUI = new SuperSkillerGUI();
  118. GUI.setVisible(true);
  119. }
  120. });
  121.  
  122. provide(new Strategy(new Fish_1(), new Fish_1()));
  123. provide(new Strategy(new Fish_2(), new Fish_2()));
  124. provide(new Strategy(new Pick_up_1(), new Pick_up_1()));
  125. provide(new Strategy(new Pick_up_2(), new Pick_up_2()));
  126. provide(new Strategy(new Drop(),new Drop()));
  127. provide(new Strategy(new Walk_to_bank(), new Walk_to_bank()));
  128. provide(new Strategy(new Bank(), new Bank()));
  129. provide(new Strategy(new Walk_to_fish(), new Walk_to_fish()));
  130. provide(new Strategy(new Record_error(), new Record_error()));
  131. provide(new Strategy(new Anti_Ban(), new Anti_Ban()));
  132. }
  133.  
  134.  
  135. public class Fish_1 implements Task, Condition{
  136. public void run(){
  137. status = "fishing";
  138. if(lefish.contains(Players.getLocal().getLocation()))
  139. InteractFlyFishing(pools);
  140. }
  141.  
  142. public boolean validate() {
  143. return fishing
  144. && GP_priority
  145. && pickup
  146. && fly
  147. && Players.getLocal().getAnimation() == -1
  148. && !Inventory.isFull()
  149. && GroundItems.getLoaded(fishA1) == null
  150. && GroundItems.getLoaded(fishA2) == null
  151. && GroundItems.getLoaded(fishA3) == null;
  152. }
  153.  
  154. }
  155.  
  156. public class Fish_2 implements Task, Condition{
  157. public void run(){
  158. status = "fishing";
  159. if(lefish.contains(Players.getLocal().getLocation()))
  160. InteractFlyFishing(pools);
  161. }
  162.  
  163. public boolean validate(){
  164. return fishing
  165. && fly
  166. && pickup
  167. && XP_priotiy
  168. && -1 == Players.getLocal().getAnimation()
  169. && !Inventory.isFull();
  170. }
  171. }
  172.  
  173. public class Pick_up_1 implements Task, Condition{
  174.  
  175. public void run(){
  176. status = "picking up fish";
  177. before = Inventory.getCount(fishies);
  178. if(lefish.contains(Players.getLocal().getLocation())){
  179. PickUp(fishies);
  180. after = Inventory.getCount(fishies);
  181. Time.sleep(Random.nextInt(300, 500));
  182. if(after - before == 1){
  183. ++fish;
  184. }
  185.  
  186. }
  187.  
  188. }
  189.  
  190. public boolean validate(){
  191. return pickup == true
  192. && fly == true
  193. && Players.getLocal().getAnimation() == -1
  194. && !Inventory.isFull()
  195. && GP_priority == true;
  196. }
  197. }
  198.  
  199. public class Pick_up_2 implements Task, Condition{
  200. public void run(){
  201. status = "picking up fish";
  202. before = Inventory.getCount(fishies);
  203. if(lefish.contains(Players.getLocal().getLocation())){
  204. PickUp(fishies);
  205. after = Inventory.getCount(fishies);
  206. if(after - before == 1){
  207. ++fish;
  208. }
  209. }
  210. }
  211.  
  212. public boolean validate(){
  213. return XP_priotiy
  214. && NPCs.getLoaded(pools) == null;
  215. }
  216. }
  217.  
  218. public class Drop implements Task, Condition{
  219. public void run(){
  220. status = "droping";
  221. dropAllExcept(items);
  222. Time.sleep(Random.nextInt(300, 500));
  223. }
  224.  
  225. public boolean validate(){
  226. return !bank
  227. && drop
  228. && !pickup
  229. && Players.getLocal().getAnimation() == -1
  230. && Inventory.isFull();
  231. }
  232. }
  233.  
  234. public class Walk_to_bank implements Task, Condition{
  235. public void run(){
  236. status = "walking to bank";
  237. traverse(pathToBank);
  238. Time.sleep(Random.nextInt(100, 300));
  239. }
  240.  
  241. public boolean validate(){
  242. return fly
  243. && fishing
  244. && Players.getLocal().getAnimation() == -1
  245. && Inventory.isFull()
  246. && bank;
  247. }
  248.  
  249. }
  250.  
  251. public class Bank implements Task, Condition{
  252. public void run(){
  253. status = "banking";
  254. NPC bank = NPCs.getNearest(new Filter<NPC>(){
  255. public boolean accept(NPC npc){
  256. return npc.getId() == banks;
  257. }
  258. });
  259. if( lebank.contains(Players.getLocal().getLocation())){
  260.  
  261. status = "selecting bank";
  262. if (bank != null){
  263. if (bank.isOnScreen()){
  264. bank.interact("bank");
  265. Time.sleep(Random.nextInt(300, 500));
  266. status = "interacting";
  267. }}
  268. status = "storing";
  269. Time.sleep(Random.nextInt(100,150 ));
  270. depositAllExcept(items);
  271. Time.sleep(Random.nextInt(250,300));
  272. Widgets.get(11, 15).interact("Close");
  273. }
  274.  
  275. }
  276.  
  277. public boolean validate(){
  278. return bank
  279. && Inventory.isFull()
  280. && Players.getLocal().getAnimation() == -1;
  281. }
  282. }
  283.  
  284. public class Walk_to_fish implements Task, Condition{
  285. public void run(){
  286. status = "walking to fish";
  287. if(!lefish.contains(Players.getLocal().getLocation()))
  288. {traverse(pathToFish);
  289. Time.sleep(Random.nextInt(400, 600));
  290. }
  291. }
  292.  
  293. public boolean validate(){
  294. return !Inventory.isFull()
  295. && Players.getLocal().getAnimation() == -1;
  296. }
  297. }
  298.  
  299. public class Record_error implements Task, Condition{
  300. public void run(){
  301.  
  302. if(Game.getClientState() == 3){
  303. runtime = TIME.getElapsed();
  304. log.info("what was it doing ?"+status);
  305. log.info("how long did it run?"+ runtime);
  306. log.info("Start again?");
  307. stop();
  308. }else if (run == false){
  309. runtime = TIME.getElapsed();
  310. log.info("what was it doing ?"+status);
  311. log.info("how long did it run?"+ runtime);
  312. log.info("Start again?");
  313. stop();
  314. }
  315. }
  316.  
  317.  
  318. public boolean validate(){
  319. return true;
  320. }
  321. }
  322.  
  323. public class Get_paint_info implements Task, Condition{
  324. public void run(){
  325. animation = Players.getLocal().getAnimation();
  326. client_state = Game.getClientState();
  327. }
  328.  
  329. public boolean validate(){
  330. return true;
  331. }
  332. }
  333.  
  334. public class Anti_Ban implements Task, Condition{
  335. public void run(){
  336.  
  337. }
  338.  
  339. public boolean validate(){
  340. return true;
  341. }
  342. }
  343.  
  344. public void traverse(TilePath path) {
  345. if (Tabs.INVENTORY.isOpen()) {
  346. if (Players.getLocal().getSpeed() == 0) {
  347. for (int i=0; i<10 && (Players.getLocal().getSpeed() == 0); i++) {
  348. path.getNext().clickOnMap();
  349. Time.sleep(500);
  350. }
  351. if (Players.getLocal().getSpeed() == 0) { //used as a failsafe when mouse keeps trying to traverse but just clicks edge of minimap
  352. Mouse.click(Random.nextInt(627-30, 627 + 30), Random.nextInt(85-30, 85+30), true); // x:627 & y:85 = exact center of minimap
  353. }
  354. } else {
  355. path.traverse();
  356. }
  357. } else {
  358. Tabs.INVENTORY.open();
  359. }
  360. }
  361. public void depositAllExcept(int... item) {
  362. ArrayList<Integer> ids = new ArrayList<Integer>();
  363. int ninvCount = -1;
  364. int invCount = Inventory.getCount();
  365. for (int id : item) {
  366. ids.add(id);
  367. }
  368. for (int i = 0; i < 28; i++) {
  369. WidgetChild slot = Widgets.get(679, 0).getChild(i);
  370. int slotId = slot.getChildId();
  371. if (slot.validate() && Inventory.getCount(slotId) > 0) {
  372. if (!ids.contains(slotId)) {
  373. for (int tries = 0; tries < 5; tries++) {
  374. if (Inventory.getCount(slotId) > 1) {
  375. if (slot.interact("Deposit-All"));
  376. else
  377. tries = 5;
  378. } else {
  379. if (slot.interact("Deposit"));
  380. else
  381. tries = 5;
  382. }
  383. Time.sleep(625, 902);
  384. ninvCount = Inventory.getCount();
  385. if (invCount > ninvCount) {
  386. invCount = ninvCount;
  387. tries = 5;
  388. }
  389. }
  390. }
  391. }
  392. }
  393. }
  394. public void dropAllExcept(final int... nodrop) {
  395. for(Item item : Inventory.getItems(new Filter<Item>() {
  396. @Override
  397. public boolean accept(Item arg0) {
  398. for(int i : nodrop) {
  399. if(arg0.getId() == i)
  400. return false;
  401. }
  402. return true;
  403. }
  404. })) {
  405. item.getWidgetChild().interact("Drop");
  406. Time.sleep(150, 300);
  407. }
  408. }
  409. public void InteractFlyFishing(int... Spot){
  410. NPC pool = NPCs.getNearest(Spot);
  411. pool.interact("lure");
  412. Time.sleep(Random.nextInt(6000, 12000));
  413. }
  414. public void PickUp(int... item){
  415. Mouse.click(GroundItems.getNearest(item).getLocation().getCentralPoint(), true);
  416. Time.sleep(Random.nextInt(100, 150));
  417. }
  418. public void InteractBank(int... teller){
  419. NPC bank = NPCs.getNearest(teller);
  420. bank.interact("bank");
  421. }
  422.  
  423.  
  424.  
  425.  
  426. public void onRepaint(Graphics g1) {
  427. Graphics2D g = (Graphics2D)g1;
  428. g.setColor(color1);
  429. g.fillRect(22, 357, 468, 87);
  430. g.setColor(color2);
  431. g.setStroke(stroke1);
  432. g.drawRect(22, 357, 468, 87);
  433. g.setFont(font1);
  434. g.drawString("FISHER", 223, 378);
  435. g.setFont(font2);
  436. g.drawString("status" + status, 26, 395);
  437. g.drawString("client state" + client_state, 27, 414);
  438. g.drawString("time:" + TIME, 29, 434);
  439. g.drawString("fish cought:" + fish, 295, 393);
  440. }
  441. //END: Code generated using Enfilade's Easel
  442.  
  443. public class SuperSkillerGUI extends JFrame{
  444. public SuperSkillerGUI() {
  445. initComponents();
  446. }
  447.  
  448. private void initComponents() {
  449. script_name = new JTextField();
  450. version = new JTextField();
  451. start_button = new JButton();
  452. set_skill = new JComboBox<>();
  453. set_location_to_fish = new JComboBox<>();
  454. set_fishing_type = new JComboBox<>();
  455. pick_up_button = new JRadioButton();
  456. Max_GP = new JRadioButton();
  457. radioButton2 = new JRadioButton();
  458. info = new JTextField();
  459. bank_button = new JRadioButton();
  460. scrollPane1 = new JScrollPane();
  461. info_1 = new JTextPane();
  462. drop_button = new JRadioButton();
  463. Info_2 = new JTextField();
  464.  
  465. //======== this ========
  466. Container contentPane = getContentPane();
  467. contentPane.setLayout(new FormLayout(
  468. "5*(default, $lcgap), 74dlu",
  469. "10*(default, $lgap), default"));
  470.  
  471. //---- script_name ----
  472. script_name.setText("Super Skiller");
  473. contentPane.add(script_name, CC.xy(1, 1));
  474.  
  475. //---- version ----
  476. version.setText("version: BETA");
  477. contentPane.add(version, CC.xy(5, 1));
  478.  
  479. //---- start_button ----
  480. start_button.setText("RUN SCRIPT");
  481. contentPane.add(start_button, CC.xywh(9, 1, 3, 1));
  482. start_button.addActionListener(new java.awt.event.ActionListener() {
  483.  
  484. public void actionPerformed(java.awt.event.ActionEvent evt) {
  485. start_buttonActionPerformed(evt);
  486. }
  487.  
  488. private void start_buttonActionPerformed(ActionEvent evt) {
  489. if("Fishing" == set_skill.getSelectedItem()){
  490. fishing = true;
  491. if("barbarian outpost" == set_location_to_fish.getSelectedItem()){
  492. barb = true;
  493. if("fly fishing" == set_fishing_type.getSelectedItem()){
  494. fly = true;
  495. }else{
  496. run = false;
  497. }
  498. }else{
  499. run = false;
  500. }
  501. }else{
  502. run = false;
  503. }
  504. }
  505.  
  506. });
  507.  
  508. //---- set_skill ----
  509. set_skill.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] {
  510. "skill to train",
  511. "Fishing"
  512. }));
  513. contentPane.add(set_skill, CC.xy(1, 5));
  514.  
  515. //---- set_location ----
  516. set_location_to_fish.setModel(new DefaultComboBoxModel<>(new String[] {
  517. "location",
  518. "barbarian outpost"
  519. }));
  520. contentPane.add(set_location_to_fish, CC.xy(5, 5));
  521.  
  522. //---- set_fishing_type ----
  523. set_fishing_type.setModel(new DefaultComboBoxModel<>(new String[] {
  524. "fishing method",
  525. "fly fishing"
  526. }));
  527. contentPane.add(set_fishing_type, CC.xy(9, 5));
  528.  
  529. //---- pick_up_button ----
  530. pick_up_button.setText("pick up");
  531. contentPane.add(pick_up_button, CC.xy(1, 11));
  532. if(pick_up_button.isSelected()){
  533. pickup = true;
  534. }else{
  535. pickup = false;
  536. }
  537.  
  538.  
  539. //---- Max_GP ----
  540. Max_GP.setText("Maximize Profit");
  541. contentPane.add(Max_GP, CC.xy(5, 11));
  542. if(Max_GP.isSelected()){
  543. GP_priority = true;
  544. }else{
  545. GP_priority = false;
  546. }
  547.  
  548. //---- radioButton2 ----
  549. radioButton2.setText("Maximize exp");
  550. contentPane.add(radioButton2, CC.xy(5, 13));
  551. if(radioButton2.isSelected()){
  552. XP_priotiy = true;
  553. }else{
  554. XP_priotiy = false;
  555. }
  556.  
  557. //---- info ----
  558. info.setText("go here to thank me, i get paid per click so click away :)");
  559. contentPane.add(info, CC.xywh(5, 17, 7, 1));
  560.  
  561. //---- bank_button ----
  562. bank_button.setText("bank");
  563. contentPane.add(bank_button, CC.xy(1, 19));
  564. if(bank_button.isSelected()){
  565. bank = true;
  566. }else{
  567. bank = false;
  568. }
  569.  
  570. //======== scrollPane1 ========
  571. {
  572.  
  573. //---- info_1 ----
  574. info_1.setText("http://c8e3c151.linkbucks.com");
  575. scrollPane1.setViewportView(info_1);
  576. }
  577. contentPane.add(scrollPane1, CC.xywh(5, 19, 7, 1));
  578.  
  579. //---- drop_button ----
  580. drop_button.setText("drop");
  581. contentPane.add(drop_button, CC.xy(1, 21));
  582. if(drop_button.isSelected()){
  583. drop = true;
  584. }else{
  585. drop = false;
  586. }
  587. //---- Info_2 ----
  588. Info_2.setText("redirects you to google (must click \"skip add\" for it to count) thankyou");
  589. contentPane.add(Info_2, CC.xywh(5, 21, 7, 1));
  590. pack();
  591. setLocationRelativeTo(getOwner());
  592. }
  593.  
  594.  
  595. private JTextField script_name;
  596. private JTextField version;
  597. private JButton start_button;
  598. private JComboBox<String> set_skill;
  599. private JComboBox<String> set_location_to_fish;
  600. private JComboBox<String> set_fishing_type;
  601. private JRadioButton pick_up_button;
  602. private JRadioButton Max_GP;
  603. private JRadioButton radioButton2;
  604. private JTextField info;
  605. private JRadioButton bank_button;
  606. private JScrollPane scrollPane1;
  607. private JTextPane info_1;
  608. private JRadioButton drop_button;
  609. private JTextField Info_2;
  610. }
  611. }
Add Comment
Please, Sign In to add comment