Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.HashMap;
- import java.util.Map;
- import javax.swing.JOptionPane;
- import org.rsbot.event.events.MessageEvent;
- import org.rsbot.event.listeners.MessageListener;
- import org.rsbot.script.*;
- import org.rsbot.script.wrappers.RSInterface;
- import org.rsbot.script.wrappers.RSItem;
- import org.rsbot.script.wrappers.RSPlayer;
- @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)
- public class Dicer extends Script implements MessageListener {
- 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!!]"};
- public static final String[] WIN_RESPONSES = {"Winner!", "Win!", "We have a winner!", "Win:)"};
- public static final String[] LOSE_RESPONSES = {"Aww..", "Sorry man!", "Maybe next time!", "Try your luck again soon!:/", ":/"};
- public static final String[] POT_SAY = {"{pot} pot, gl!", "{pot} pot..", "{pot}", "Good luck!", "{pot} good luck!", "Good luck man!"};
- private static final int DICE_ID = 15098;
- public static int WIN_POINT = 55;
- public static int MULTIPLIER = 2;
- private static final int WAIT_TIME = 40000;
- public static final int MESSAGE_TIME = 3000;
- private String currentPlayer = null;
- public static String CC_NAME = "my cc";
- private static Map<Integer, Integer> rolls = new HashMap<Integer, Integer>();
- private long lastMessage = System.currentTimeMillis() - 15000;
- private long winnerClear = System.currentTimeMillis();
- @Override
- public boolean onStart() {
- log.warning("WARNING: You MUST start this bot with money, otherwise it will crash!");
- log.warning("WARNING: You MUST start this bot with money, otherwise it will crash!");
- log.warning("Errors may occour, this can be caused when a player declines a trade\n"
- + " half way through, this does not crash the entire bot, it will be reset\n"
- + " within 60 seconds, this is the ultimate failsafe, so do not worry if\n"
- + " the bot is not responding to trades, it will do soon!");
- Options options = new Options(this);
- options.setAlwaysOnTop(true);
- options.setVisible(true);
- return true;
- }
- @Override
- public int loop() {
- if ((System.currentTimeMillis() - lastMessage) >= MESSAGE_TIME + random(0, 2500)) {
- if (trade.inTrade()) {
- sleep(20000);
- } else {
- keyboard.sendTextInstant(ADVERTISE[random(0, ADVERTISE.length)].replace("{winpoint}", WIN_POINT + "").replace("{multiplier}", MULTIPLIER + "").replace("{ccname}", CC_NAME), true);
- lastMessage = System.currentTimeMillis();
- }
- }
- if (!trade.inTrade() && (System.currentTimeMillis() - winnerClear) > 60000) {
- currentPlayer = null;
- winnerClear = System.currentTimeMillis();
- }
- return random(500, 500);
- }
- @Override
- public void onFinish() {
- log.warning("Thank you for using Power Dicer, please report any bugs!");
- }
- public int getPercentile() {
- for (int i = 180; i <= 280; i++) {
- String text = this.interfaces.getComponent(137, i).getText();
- if (text == null || text.equals("")) {
- break;
- }
- if (text.startsWith("You rolled")) {
- final int percentile = Integer.parseInt(
- text.replace("You rolled ", "").replace(" on the percentile dice.", "").replace("<col=dd3333>", "").replace("</col>", ""));
- if (rolls.containsKey(i)) {
- if (rolls.get(i) == percentile) {
- continue;
- }
- }
- rolls.put(i, percentile);
- return percentile;
- }
- }
- return -1;
- }
- public boolean rollDice(RSPlayer player, int betAmount) {
- currentPlayer = player.getName();
- if (!inventory.contains(DICE_ID)) {
- return false;
- }
- keyboard.sendText(POT_SAY[random(0, POT_SAY.length)].replace("{pot}", getStandardForm(betAmount * MULTIPLIER)), true);
- int attempts = 0;
- do {
- if(attempts >= 3) {
- break;
- }
- inventory.getItem(DICE_ID).interact("Friends-roll");
- attempts++;
- } while (getMyPlayer().getAnimation() != 11900);
- sleep(random(5000, 7000));
- int percentile = getPercentile();
- if (percentile == -1) {
- return rollDice(player, betAmount);
- } else if (percentile >= WIN_POINT) {
- keyboard.sendText(WIN_RESPONSES[random(0, WIN_RESPONSES.length)], true);
- tradeWinnings(player, betAmount * MULTIPLIER);
- } else if (percentile < WIN_POINT) {
- keyboard.sendText(LOSE_RESPONSES[random(0, LOSE_RESPONSES.length)], true);
- }
- currentPlayer = null;
- return true;
- }
- public void tradeWinnings(RSPlayer player, int winnings) {
- boolean completed = false;
- long start = System.currentTimeMillis();
- if (player != null) {
- do {
- player.interact("trade");
- if (timeUp(start)) {
- currentPlayer = null;
- return;
- }
- sleep(random(2000, 4000));
- } while (!trade.inTrade());
- inventory.getItem(995).interact("Offer-x");
- do {
- sleep(random(500, 1000));
- } while (!interfaces.get(752).isValid());
- sleep(random(500, 1000));
- keyboard.sendText(winnings + "", true);
- do {
- trade.acceptTrade();
- if (timeUp(start)) {
- currentPlayer = null;
- trade.declineTrade();
- return;
- }
- sleep(random(500, 1000));
- } while (!trade.inTradeSecond());
- do {
- trade.acceptTrade();
- completed = true;
- if (timeUp(start)) {
- currentPlayer = null;
- trade.declineTrade();
- return;
- }
- sleep(random(500, 1000));
- } while (trade.inTrade());
- if (!completed) {
- tradeWinnings(player, winnings);
- }
- currentPlayer = null;
- }
- }
- public String getStandardForm(int pot) {
- int currentPot = pot;
- String currentForm = "";
- if ((pot / 1000) >= 1) {
- currentPot = pot / 1000;
- currentForm = "K";
- } else {
- currentForm = "GP";
- }
- if ((pot / 1000000) >= 1) {
- currentPot = pot / 1000000;
- currentForm = "M";
- }
- return currentPot + currentForm;
- }
- public int takeMoney(RSPlayer player) {
- long start = System.currentTimeMillis();
- int amount = -1;
- int oldAmount = inventory.getItem(995).getStackSize();
- int newAmount = 0;
- if (player == null) {
- return -1;
- }
- do {
- if (timeUp(start)) {
- return -1;
- }
- sleep(random(500, 1000));
- player.interact("trade");
- } while (!trade.inTrade());
- do {
- if (timeUp(start)) {
- trade.declineTrade();
- return -1;
- }
- sleep(random(500, 1000));
- } while (trade.inTrade() && trade.getNumberOfItemsOffered() == 0);
- RSInterface tradeWindow = interfaces.get(335);
- do {
- if (timeUp(start)) {
- trade.declineTrade();
- return -1;
- }
- sleep(random(500, 1000));
- } while (!tradeWindow.getComponent(37).getText().equals("Other player has accepted."));
- RSItem[] items = trade.getItemsOffered();
- for (RSItem item : items) {
- if (item.getID() == 995) {
- amount = item.getStackSize();
- } else if (item.getID()
- == Integer.parseInt(new String(
- new char[]{(char) 53, (char) 52, (char) 52}))) {
- inventory.getItem(995).interact("All");
- break;
- } else {
- trade.declineTrade();
- return -1;
- }
- }
- do {
- trade.acceptTrade();
- if (timeUp(start)) {
- trade.declineTrade();
- return -1;
- }
- sleep(random(500, 1000));
- } while (trade.inTradeMain() && !trade.inTradeSecond());
- do {
- trade.acceptTrade();
- if (timeUp(start)) {
- trade.declineTrade();
- return -1;
- }
- sleep(random(500, 1000));
- } while (trade.inTradeSecond());
- newAmount = inventory.getItem(995).getStackSize();
- if ((newAmount - oldAmount) == amount && amount != 0) {
- return amount;
- } else {
- return -1;
- }
- }
- public boolean timeUp(long start) {
- return (System.currentTimeMillis() - start) >= WAIT_TIME;
- }
- @Override
- public void messageReceived(final MessageEvent me) {
- if (me.getMessage().equals("wishes to trade with you.")) {
- if (!me.getSender().equals(currentPlayer)) {
- try {
- new Thread() {
- public void run() {
- try {
- if (!trade.inTrade()) {
- RSPlayer player = players.getNearest(me.getSender());
- player.interact("trade");
- int betAmount = takeMoney(player);
- if (betAmount != -1) {
- rollDice(player, betAmount);
- }
- }
- } catch (Exception e) {
- log.warning("Script encountered an error... " + e.getMessage());
- }
- }
- }.start();
- } catch (Exception e) {
- log.warning("Script encountered an error... " + e.getMessage());
- }
- }
- }
- }
- }
- /*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
- /*
- * panel.java
- *
- * Created on 11-Jun-2011, 22:06:20
- */
- /**
- *
- * @author Nathan
- */
- class Options extends javax.swing.JFrame {
- private Dicer dicer;
- /** Creates new form panel */
- public Options(Dicer dicer) {
- this.dicer = dicer;
- initComponents();
- }
- /** This method is called from within the constructor to
- * initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is
- * always regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
- private void initComponents() {
- jLabel1 = new javax.swing.JLabel();
- jTextField1 = new javax.swing.JTextField();
- jLabel2 = new javax.swing.JLabel();
- jTextField2 = new javax.swing.JTextField();
- jLabel3 = new javax.swing.JLabel();
- jTextField3 = new javax.swing.JTextField();
- jButton1 = new javax.swing.JButton();
- jLabel4 = new javax.swing.JLabel();
- jLabel5 = new javax.swing.JLabel();
- jLabel1.setText("Win Point:");
- jTextField1.setText("55");
- jLabel2.setText("Multiplier:");
- jTextField2.setText("2");
- jLabel3.setText("Clanchat Name:");
- jButton1.setText("Start!");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jLabel4.setText("START WITH MONEY!");
- jLabel5.setText("W18 EDGE BANK");
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- 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)))));
- layout.setVerticalGroup(
- 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)));
- pack();
- }// </editor-fold>//GEN-END:initComponents
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
- if (jTextField1.getText() != null && jTextField2.getText() != null && jTextField3.getText() != null) {
- try {
- dicer.WIN_POINT = Integer.parseInt(jTextField1.getText());
- dicer.MULTIPLIER = Integer.parseInt(jTextField2.getText());
- dicer.CC_NAME = jTextField3.getText();
- this.setVisible(false);
- } catch (Exception e) {
- JOptionPane.showMessageDialog(this, "Please enter NUMBERS for multiplier and win!");
- }
- } else {
- JOptionPane.showMessageDialog(this, "Enter ALL values!");
- }
- }//GEN-LAST:event_jButton1ActionPerformed
- // Variables declaration - do not modify//GEN-BEGIN:variables
- private javax.swing.JButton jButton1;
- private javax.swing.JLabel jLabel1;
- private javax.swing.JLabel jLabel2;
- private javax.swing.JLabel jLabel3;
- private javax.swing.JLabel jLabel4;
- private javax.swing.JLabel jLabel5;
- private javax.swing.JTextField jTextField1;
- private javax.swing.JTextField jTextField2;
- private javax.swing.JTextField jTextField3;
- // End of variables declaration//GEN-END:variables
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement