jmarsiglio2 1 Posted July 8, 2016 Hi, here's a script I made for Waterbirth island Rock Crabs! - Supports a single rock crab spot - Resets aggression when rock crabs no longer attack - Picks up arrows / knives that you specify - Doesn't support eating (I never had to eat) Wasn't able to upload the .jar so here's the source. To compile it, save the code in with the file name specified above each code block and then compile to a JAR. RockCrab.java package RockCrab; import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.skills.Skill; import org.dreambot.api.script.AbstractScript; import org.dreambot.api.script.Category; import org.dreambot.api.script.ScriptManifest; import org.dreambot.api.utilities.Timer; import org.dreambot.api.wrappers.interactive.NPC; import org.dreambot.api.wrappers.items.GroundItem; import java.awt.*; @ScriptManifest(category = Category.COMBAT, name = "RockCrabs", author = "Josh", version = 1.0) public class RockCrab extends AbstractScript { private String WEAPON; private boolean outOfCombatFlag = false; private boolean started = false; private Tile SPOT = new Tile(2513, 3766, 0); private Tile RESET = new Tile(2553, 3744, 0); private String state = "walking back"; private Timer runningTimer; private Timer combatTimer; @Override public void onStart(){ new RockGUI(this); } private void pickupLoot() { if (!getLocalPlayer().isInCombat()) { GroundItem i = getGroundItems().closest(WEAPON); if (i != null && getLocalPlayer().distance(i) < 4) { int c = getInventory().count(i.getID()); if (i.interact("Take")) { sleepUntil(() -> getInventory().count(i.getID()) > c, 3000); } } } } public void onGuiClose() { log("Gui closed"); this.stop(); } public void onGuiStart(String pickup) { log("Gui start"); WEAPON = pickup; started = true; runningTimer = new Timer(); combatTimer = new Timer(); getSkillTracker().start(Skill.RANGED); } private void attack() { if (isResetting() || isWalkingBack()) { return; } if (getLocalPlayer().isInCombat()) { outOfCombatFlag = false; combatTimer.reset(); } else { if (outOfCombatFlag) { NPC crab = getNpcs().closest("Rock Crab"); if (crab != null && getLocalPlayer().distance(crab) < 3 && !crab.isInCombat()) { if (crab.interact("Attack")) { sleepUntil(() -> getLocalPlayer().isInCombat(), 3000); } } } else { outOfCombatFlag = true; combatTimer.reset(); } } } private void resetCombat() { if ((combatTimer.elapsed() > 20000 || isResetting()) && !isWalkingBack()) { state = "resetting"; getWalking().walk(RESET); sleep(1500); } if (getLocalPlayer().distance(RESET) < 5) { state = "walking back"; } } private boolean isResetting() { return state.equals("resetting"); } private boolean isWalkingBack() { return state.equals("walking back"); } private boolean isOnSpot() { return SPOT.getTile().equals(getLocalPlayer().getTile()); } // go to the rock crab spot (defined by the tile SPOT) private void gotoSpot() { if (isResetting()) { return; } if (isWalkingBack()) { combatTimer.reset(); } if (isOnSpot()) { state = "in spot"; } else { if (getLocalPlayer().distance(SPOT) < 5) { getWalking().walkOnScreen(SPOT); sleepUntil(this::isOnSpot, 3000); state = "in spot"; } else { getWalking().walk(SPOT); sleep(1500); } log("walking to spot..."); } } @Override public int onLoop() { if (!started || !getClient().isLoggedIn()) return 1000; if (getInventory().count(WEAPON) > 10) { getInventory().interact(WEAPON, "Wield"); } getDialogues().clickContinue(); gotoSpot(); attack(); pickupLoot(); resetCombat(); return Calculations.random(400, 800); } @Override public void onExit() { } @Override public void onPaint(Graphics g) { if (!started) return; Font font = new Font("Times new roman", Font.PLAIN, 15); Color bg = new Color(155, 155, 155, 127); // grey transparent g.setColor(bg); g.fillRect(5, 5, 510, 70); g.setFont(font); g.setColor(Color.BLUE); g.drawString("Time: ", 10, 25); g.setColor(Color.WHITE); g.drawString(runningTimer.formatTime(), 100, 25); g.setColor(Color.BLUE); g.drawString("Ranged xp: ", 10, 45); g.setColor(Color.WHITE); g.drawString(getSkillTracker().getGainedExperience(Skill.RANGED) + " (" + getSkillTracker().getGainedExperiencePerHour(Skill.RANGED) + ")", 100, 45); g.setColor(Color.BLUE); g.drawString("State: ", 10, 65); g.setColor(Color.WHITE); g.drawString(state, 100, 65); } } RockGUI.java package RockCrab; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class RockGUI extends JFrame { private RockCrab ctx; public RockGUI(RockCrab main){ this.ctx = main; initComponents(); this.setVisible(true); } private void button1ActionPerformed(ActionEvent e) { ctx.onGuiStart(this.getPickupItem()); this.setVisible(false); } private void initComponents() { button1 = new JButton(); textField1 = new JTextField(); label1 = new JLabel(); setTitle("RockCrab"); Container contentPane = getContentPane(); GridBagConstraints c = new GridBagConstraints(); contentPane.setLayout(new GridBagLayout()); c.weightx = 1.0; c.weighty = 1.0; c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.insets = new Insets(5, 5, 5, 20); label1.setText("Type your pickup item: "); contentPane.add(label1, c); c.gridx = 1; c.gridy = 0; c.insets = new Insets(5, 5, 5, 5); textField1.setText("Iron knife"); textField1.setPreferredSize(new Dimension(150, 20)); contentPane.add(textField1, c); c.gridx = 0; c.gridy = 1; c.weightx = 1; c.gridwidth = 2; c.insets = new Insets(20, 5, 5, 5); button1.setText("Start"); button1.addActionListener(e -> button1ActionPerformed(e)); contentPane.add(button1, c); pack(); setLocationRelativeTo(getOwner()); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { e.getWindow().dispose(); ctx.onGuiClose(); } }); } private String getPickupItem() { return textField1.getText(); } private JButton button1; private JTextField textField1; private JLabel label1; }
Theorems 23 Posted November 27, 2017 Wish I could use this idk how tf to create stupid jar file Open eclipse Create a new java project, name it anything Create new package called RockCrab Inside package create new java files called RockCrab.java and RockGUI.java paste code above into correct file right-click on project click properties. click "java build path" on menu that appeared when you clicked properties click "Add external jars" navigate to dreambot folder and select client.jar click "apply and close" then click file>export select java>jarfile put the location you want to export it to as your scripts folder (within the dreambot folder) done! you should now see it in your local scripts
Recommended Posts
Archived
This topic is now archived and is closed to further replies.