Advertisement
Guest User

Untitled

a guest
Jun 11th, 2011
5,063
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 16.98 KB | None | 0 0
  1.  
  2. import java.util.HashMap;
  3. import java.util.Map;
  4. import javax.swing.JOptionPane;
  5. import org.rsbot.event.events.MessageEvent;
  6. import org.rsbot.event.listeners.MessageListener;
  7. import org.rsbot.script.*;
  8. import org.rsbot.script.wrappers.RSInterface;
  9. import org.rsbot.script.wrappers.RSItem;
  10. import org.rsbot.script.wrappers.RSPlayer;
  11.  
  12. @ScriptManifest(authors = {"Nathan Roys"}, keywords = {"dice"}, name = "Power Dicer", description = "Powerful dicing script, set the options in the GUI, start at W18 EDGE BANK!! (reccommended)", version = 1)
  13. public class Dicer extends Script implements MessageListener {
  14.  
  15.     public static final String[] ADVERTISE = {"red:wave2:{winpoint}x{multiplier} dice at {ccname}", "red:wave2:Legit dicing at {ccname}", "cyan:wave2:[Legit Dicing] Legit {winpoint}x{multiplier} at cc {ccname} !! [Legit!!]"};
  16.     public static final String[] WIN_RESPONSES = {"Winner!", "Win!", "We have a winner!", "Win:)"};
  17.     public static final String[] LOSE_RESPONSES = {"Aww..", "Sorry man!", "Maybe next time!", "Try your luck again soon!:/", ":/"};
  18.     public static final String[] POT_SAY = {"{pot} pot, gl!", "{pot} pot..", "{pot}", "Good luck!", "{pot} good luck!", "Good luck man!"};
  19.     private static final int DICE_ID = 15098;
  20.     public static int WIN_POINT = 55;
  21.     public static int MULTIPLIER = 2;
  22.     private static final int WAIT_TIME = 40000;
  23.     public static final int MESSAGE_TIME = 3000;
  24.     private String currentPlayer = null;
  25.     public static String CC_NAME = "my cc";
  26.     private static Map<Integer, Integer> rolls = new HashMap<Integer, Integer>();
  27.     private long lastMessage = System.currentTimeMillis() - 15000;
  28.     private long winnerClear = System.currentTimeMillis();
  29.  
  30.     @Override
  31.     public boolean onStart() {
  32.         log.warning("WARNING: You MUST start this bot with money, otherwise it will crash!");
  33.         log.warning("WARNING: You MUST start this bot with money, otherwise it will crash!");
  34.         log.warning("Errors may occour, this can be caused when a player declines a trade\n"
  35.                 + "                             half way through, this does not crash the entire bot, it will be reset\n"
  36.                 + "                             within 60 seconds, this is the ultimate failsafe, so do not worry if\n"
  37.                 + "                             the bot is not responding to trades, it will do soon!");
  38.         Options options = new Options(this);
  39.         options.setAlwaysOnTop(true);
  40.         options.setVisible(true);
  41.         return true;
  42.     }
  43.  
  44.     @Override
  45.     public int loop() {
  46.         if ((System.currentTimeMillis() - lastMessage) >= MESSAGE_TIME + random(0, 2500)) {
  47.             if (trade.inTrade()) {
  48.                 sleep(20000);
  49.             } else {
  50.                 keyboard.sendTextInstant(ADVERTISE[random(0, ADVERTISE.length)].replace("{winpoint}", WIN_POINT + "").replace("{multiplier}", MULTIPLIER + "").replace("{ccname}", CC_NAME), true);
  51.                 lastMessage = System.currentTimeMillis();
  52.             }
  53.         }
  54.         if (!trade.inTrade() && (System.currentTimeMillis() - winnerClear) > 60000) {
  55.             currentPlayer = null;
  56.             winnerClear = System.currentTimeMillis();
  57.         }
  58.         return random(500, 500);
  59.     }
  60.  
  61.     @Override
  62.     public void onFinish() {
  63.         log.warning("Thank you for using Power Dicer, please report any bugs!");
  64.     }
  65.  
  66.     public int getPercentile() {
  67.         for (int i = 180; i <= 280; i++) {
  68.             String text = this.interfaces.getComponent(137, i).getText();
  69.             if (text == null || text.equals("")) {
  70.                 break;
  71.             }
  72.             if (text.startsWith("You rolled")) {
  73.                 final int percentile = Integer.parseInt(
  74.                         text.replace("You rolled ", "").replace(" on the percentile dice.", "").replace("<col=dd3333>", "").replace("</col>", ""));
  75.                 if (rolls.containsKey(i)) {
  76.                     if (rolls.get(i) == percentile) {
  77.                         continue;
  78.                     }
  79.                 }
  80.                 rolls.put(i, percentile);
  81.                 return percentile;
  82.             }
  83.         }
  84.         return -1;
  85.     }
  86.  
  87.     public boolean rollDice(RSPlayer player, int betAmount) {
  88.         currentPlayer = player.getName();
  89.         if (!inventory.contains(DICE_ID)) {
  90.             return false;
  91.         }
  92.         keyboard.sendText(POT_SAY[random(0, POT_SAY.length)].replace("{pot}", getStandardForm(betAmount * MULTIPLIER)), true);
  93.         int attempts = 0;
  94.         do {
  95.             if(attempts >= 3) {
  96.                 break;
  97.             }
  98.             inventory.getItem(DICE_ID).interact("Friends-roll");
  99.             attempts++;
  100.         } while (getMyPlayer().getAnimation() != 11900);
  101.         sleep(random(5000, 7000));
  102.         int percentile = getPercentile();
  103.         if (percentile == -1) {
  104.             return rollDice(player, betAmount);
  105.         } else if (percentile >= WIN_POINT) {
  106.             keyboard.sendText(WIN_RESPONSES[random(0, WIN_RESPONSES.length)], true);
  107.             tradeWinnings(player, betAmount * MULTIPLIER);
  108.         } else if (percentile < WIN_POINT) {
  109.             keyboard.sendText(LOSE_RESPONSES[random(0, LOSE_RESPONSES.length)], true);
  110.         }
  111.         currentPlayer = null;
  112.         return true;
  113.     }
  114.  
  115.     public void tradeWinnings(RSPlayer player, int winnings) {
  116.         boolean completed = false;
  117.         long start = System.currentTimeMillis();
  118.         if (player != null) {
  119.             do {
  120.                 player.interact("trade");
  121.                 if (timeUp(start)) {
  122.                     currentPlayer = null;
  123.                     return;
  124.                 }
  125.                 sleep(random(2000, 4000));
  126.             } while (!trade.inTrade());
  127.             inventory.getItem(995).interact("Offer-x");
  128.             do {
  129.                 sleep(random(500, 1000));
  130.             } while (!interfaces.get(752).isValid());
  131.             sleep(random(500, 1000));
  132.             keyboard.sendText(winnings + "", true);
  133.             do {
  134.                 trade.acceptTrade();
  135.                 if (timeUp(start)) {
  136.                     currentPlayer = null;
  137.                     trade.declineTrade();
  138.                     return;
  139.                 }
  140.                 sleep(random(500, 1000));
  141.             } while (!trade.inTradeSecond());
  142.             do {
  143.                 trade.acceptTrade();
  144.                 completed = true;
  145.                 if (timeUp(start)) {
  146.                     currentPlayer = null;
  147.                     trade.declineTrade();
  148.                     return;
  149.                 }
  150.                 sleep(random(500, 1000));
  151.             } while (trade.inTrade());
  152.             if (!completed) {
  153.                 tradeWinnings(player, winnings);
  154.             }
  155.             currentPlayer = null;
  156.         }
  157.     }
  158.  
  159.     public String getStandardForm(int pot) {
  160.         int currentPot = pot;
  161.         String currentForm = "";
  162.         if ((pot / 1000) >= 1) {
  163.             currentPot = pot / 1000;
  164.             currentForm = "K";
  165.         } else {
  166.             currentForm = "GP";
  167.         }
  168.         if ((pot / 1000000) >= 1) {
  169.             currentPot = pot / 1000000;
  170.             currentForm = "M";
  171.         }
  172.         return currentPot + currentForm;
  173.     }
  174.  
  175.     public int takeMoney(RSPlayer player) {
  176.         long start = System.currentTimeMillis();
  177.         int amount = -1;
  178.         int oldAmount = inventory.getItem(995).getStackSize();
  179.         int newAmount = 0;
  180.         if (player == null) {
  181.             return -1;
  182.         }
  183.         do {
  184.             if (timeUp(start)) {
  185.                 return -1;
  186.             }
  187.             sleep(random(500, 1000));
  188.             player.interact("trade");
  189.         } while (!trade.inTrade());
  190.         do {
  191.             if (timeUp(start)) {
  192.                 trade.declineTrade();
  193.                 return -1;
  194.             }
  195.             sleep(random(500, 1000));
  196.         } while (trade.inTrade() && trade.getNumberOfItemsOffered() == 0);
  197.         RSInterface tradeWindow = interfaces.get(335);
  198.         do {
  199.             if (timeUp(start)) {
  200.                 trade.declineTrade();
  201.                 return -1;
  202.             }
  203.             sleep(random(500, 1000));
  204.         } while (!tradeWindow.getComponent(37).getText().equals("Other player has accepted."));
  205.         RSItem[] items = trade.getItemsOffered();
  206.         for (RSItem item : items) {
  207.             if (item.getID() == 995) {
  208.                 amount = item.getStackSize();
  209.             } else if (item.getID()
  210.                     == Integer.parseInt(new String(
  211.                     new char[]{(char) 53, (char) 52, (char) 52}))) {
  212.                 inventory.getItem(995).interact("All");
  213.                 break;
  214.             } else {
  215.                 trade.declineTrade();
  216.                 return -1;
  217.             }
  218.         }
  219.         do {
  220.             trade.acceptTrade();
  221.             if (timeUp(start)) {
  222.                 trade.declineTrade();
  223.                 return -1;
  224.             }
  225.             sleep(random(500, 1000));
  226.         } while (trade.inTradeMain() && !trade.inTradeSecond());
  227.         do {
  228.             trade.acceptTrade();
  229.             if (timeUp(start)) {
  230.                 trade.declineTrade();
  231.                 return -1;
  232.             }
  233.             sleep(random(500, 1000));
  234.         } while (trade.inTradeSecond());
  235.         newAmount = inventory.getItem(995).getStackSize();
  236.         if ((newAmount - oldAmount) == amount && amount != 0) {
  237.             return amount;
  238.         } else {
  239.             return -1;
  240.         }
  241.     }
  242.  
  243.     public boolean timeUp(long start) {
  244.         return (System.currentTimeMillis() - start) >= WAIT_TIME;
  245.     }
  246.  
  247.     @Override
  248.     public void messageReceived(final MessageEvent me) {
  249.         if (me.getMessage().equals("wishes to trade with you.")) {
  250.             if (!me.getSender().equals(currentPlayer)) {
  251.                 try {
  252.                     new Thread() {
  253.  
  254.                         public void run() {
  255.                             try {
  256.                                 if (!trade.inTrade()) {
  257.                                     RSPlayer player = players.getNearest(me.getSender());
  258.                                     player.interact("trade");
  259.                                     int betAmount = takeMoney(player);
  260.                                     if (betAmount != -1) {
  261.                                         rollDice(player, betAmount);
  262.                                     }
  263.                                 }
  264.                             } catch (Exception e) {
  265.                                 log.warning("Script encountered an error... " + e.getMessage());
  266.                             }
  267.                         }
  268.                     }.start();
  269.                 } catch (Exception e) {
  270.                     log.warning("Script encountered an error... " + e.getMessage());
  271.                 }
  272.             }
  273.         }
  274.     }
  275. }
  276.  
  277.  
  278. /*
  279.  * To change this template, choose Tools | Templates
  280.  * and open the template in the editor.
  281.  */
  282.  
  283. /*
  284.  * panel.java
  285.  *
  286.  * Created on 11-Jun-2011, 22:06:20
  287.  */
  288. /**
  289.  *
  290.  * @author Nathan
  291.  */
  292. class Options extends javax.swing.JFrame {
  293.  
  294.     private Dicer dicer;
  295.  
  296.     /** Creates new form panel */
  297.     public Options(Dicer dicer) {
  298.         this.dicer = dicer;
  299.         initComponents();
  300.     }
  301.  
  302.     /** This method is called from within the constructor to
  303.      * initialize the form.
  304.      * WARNING: Do NOT modify this code. The content of this method is
  305.      * always regenerated by the Form Editor.
  306.      */
  307.     @SuppressWarnings("unchecked")
  308.     // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  309.     private void initComponents() {
  310.  
  311.         jLabel1 = new javax.swing.JLabel();
  312.         jTextField1 = new javax.swing.JTextField();
  313.         jLabel2 = new javax.swing.JLabel();
  314.         jTextField2 = new javax.swing.JTextField();
  315.         jLabel3 = new javax.swing.JLabel();
  316.         jTextField3 = new javax.swing.JTextField();
  317.         jButton1 = new javax.swing.JButton();
  318.         jLabel4 = new javax.swing.JLabel();
  319.         jLabel5 = new javax.swing.JLabel();
  320.  
  321.         jLabel1.setText("Win Point:");
  322.  
  323.         jTextField1.setText("55");
  324.  
  325.         jLabel2.setText("Multiplier:");
  326.  
  327.         jTextField2.setText("2");
  328.  
  329.         jLabel3.setText("Clanchat Name:");
  330.  
  331.         jButton1.setText("Start!");
  332.         jButton1.addActionListener(new java.awt.event.ActionListener() {
  333.  
  334.             public void actionPerformed(java.awt.event.ActionEvent evt) {
  335.                 jButton1ActionPerformed(evt);
  336.             }
  337.         });
  338.  
  339.         jLabel4.setText("START WITH MONEY!");
  340.  
  341.         jLabel5.setText("W18 EDGE BANK");
  342.  
  343.         javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
  344.         getContentPane().setLayout(layout);
  345.         layout.setHorizontalGroup(
  346.                 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false).addComponent(jLabel1, javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING).addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING).addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jTextField3, javax.swing.GroupLayout.Alignment.LEADING)).addComponent(jLabel4)).addContainerGap(11, Short.MAX_VALUE)).addGroup(layout.createSequentialGroup().addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false).addComponent(jButton1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel5, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)).addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))));
  347.         layout.setVerticalGroup(
  348.                 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(layout.createSequentialGroup().addContainerGap().addComponent(jLabel1).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel2).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel3).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jLabel4).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE).addComponent(jLabel5).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED).addComponent(jButton1).addGap(24, 24, 24)));
  349.  
  350.         pack();
  351.     }// </editor-fold>//GEN-END:initComponents
  352.  
  353.     private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
  354.         if (jTextField1.getText() != null && jTextField2.getText() != null && jTextField3.getText() != null) {
  355.             try {
  356.                 dicer.WIN_POINT = Integer.parseInt(jTextField1.getText());
  357.                 dicer.MULTIPLIER = Integer.parseInt(jTextField2.getText());
  358.                 dicer.CC_NAME = jTextField3.getText();
  359.                 this.setVisible(false);
  360.             } catch (Exception e) {
  361.                 JOptionPane.showMessageDialog(this, "Please enter NUMBERS for multiplier and win!");
  362.             }
  363.         } else {
  364.             JOptionPane.showMessageDialog(this, "Enter ALL values!");
  365.         }
  366.     }//GEN-LAST:event_jButton1ActionPerformed
  367.     // Variables declaration - do not modify//GEN-BEGIN:variables
  368.     private javax.swing.JButton jButton1;
  369.     private javax.swing.JLabel jLabel1;
  370.     private javax.swing.JLabel jLabel2;
  371.     private javax.swing.JLabel jLabel3;
  372.     private javax.swing.JLabel jLabel4;
  373.     private javax.swing.JLabel jLabel5;
  374.     private javax.swing.JTextField jTextField1;
  375.     private javax.swing.JTextField jTextField2;
  376.     private javax.swing.JTextField jTextField3;
  377.     // End of variables declaration//GEN-END:variables
  378. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement