Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • GeYews --- [Open source]


    Diddy

    Feedback  

    50 members have voted

    1. 1. Was this helpfull for you?

      • yes
        47
      • no
        8
    2. 2. What's your opinion on open source scripts?

      • Why not? could come in handy
        34
      • omg, stop this nonsence!
        1
      • I love copy pasta
        6
      • Doens't benefit the reader as they have to script for there own
        3
      • What's the meaning of life?
        6
    3. 3. More of this?

      • get a life!
        5
      • yes please
        44
      • Only on ppls request
        4
      • no
        2


    Recommended Posts

    Hi fellow dreambotters!

     

    I would like to share the code of my GeYews in the hope you new scripters out there could learn a bit from it.

    Of course this isn't a top tier script and I made this as one of my first scripts.

    Nonetheless, I'm sure some ppl are curious about a few stuff.

     

    ---Let me know what you think about this---

     

    http://pastebin.com/jKh2dURN    script

    http://pastebin.com/6a062ZMi     gui

     

     

     

     

    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    import org.dreambot.api.methods.skills.Skill;
    import org.dreambot.api.methods.tabs.Tab;
    import org.dreambot.api.script.AbstractScript;
    import org.dreambot.api.script.Category;
    import org.dreambot.api.script.ScriptManifest;
    import org.dreambot.api.script.listener.MessageListener;
    import org.dreambot.api.utilities.Timer;
    import org.dreambot.api.wrappers.interactive.GameObject;
    import org.dreambot.api.wrappers.items.GroundItem;
    import org.dreambot.api.wrappers.widgets.message.Message;
    
    import java.awt.*;
    
    @ScriptManifest(category = Category.WOODCUTTING, name = "GE Yews", author = "Diddy", version = 1.5)
    public class Main extends AbstractScript implements MessageListener {
    
    private boolean startScript;
    private boolean newNest;
    private YewsGUI gui;
    
    private int logsgained;
    private int logsanhour;
    private int xnests;
    
    private Area treeArea = new Area(3201, 3506, 3224, 3501, 0);
    private Area startArea = new Area(3201, 3506, 3207, 3501, 0);
    
    Tile t1 = new Tile(3204, 3505, 0);
    Tile t2 = new Tile(3210, 3500, 0);
    Tile t3 = new Tile(3222, 3504, 0);
    
    String Status = " ";
    Timer timer;
    static String status = null;
    
    private GameObject tree;
    
    @Override
    public void onStart() { // making the GUI visable
    gui = new YewsGUI(this);
    gui.setVisible(true);
    sleepUntil(() -> startScript, 60000); // sleeping until logged in
    sleepUntil(() -> getClient().isLoggedIn(),
    Calculations.random(40000, 60000));
    getSkillTracker().start(Skill.WOODCUTTING); // tracking all woodcutting
    // exp gained
    }
    
    private enum State {
    CHOP, BANK, WAIT,
    
    }
    
    private State getState() { // we are seperating the script into pieces
    // making it more convenient
    tree = getGameObjects().closest(
    gameObject -> gameObject != null
    && gameObject.getName().equals("Yew")
    && gameObject.distance() < 17
    && treeArea.contains(gameObject));
    if (startScript) {
    if (!getInventory().isFull() && !getLocalPlayer().isAnimating()) {
    return State.CHOP;
    } else if (getInventory().isFull()) {
    return State.BANK;
    } else if (treeArea.contains(getLocalPlayer())
    && getLocalPlayer().isAnimating()) {
    return State.WAIT;
    }
    }
    return null;
    }
    
    @Override
    public int onLoop() {
    
    tree = getGameObjects().closest(
    gameObject -> gameObject != null
    && gameObject.getName().equals("Yew")
    && gameObject.distance() < 17
    && treeArea.contains(gameObject));
    
    switch (getState()) {
    
    case CHOP:
    if (treeArea.contains(getLocalPlayer())) {
    if (!newNest) { // checking if there isn't a birdsnest
    if (tree != null && treeArea.contains(tree)) {
    if (tree.isOnScreen()) {
    chop(); // chop the tree
    } else {
    move(); // move the camera a bit
    }
    } else {
    hopWorlds(); // hop worlds
    }
    } else {
    GroundItem nest = getGroundItems().closest("Bird nest");
    if (nest != null && nest.interact()) {
    sleepUntil(() -> nest == null
    || !getLocalPlayer().isMoving(),
    Calculations.random(2500, 3800));
    newNest = false;
    }
    
    }
    } else {
    if (getWalking().walk(startArea.getRandomTile())) {
    log("walking to yews");
    sleepUntil(
    () -> (getClient().getDestination().distance() < Calculations.random(
    6, 9))
    || getLocalPlayer().isStandingStill(),
    Calculations.random(4100, 5110));
    }
    }
    break;
    
    case BANK:
    
    bank();
    
    break;
    
    case WAIT:
    antiBan();
    sleepUntil(() -> !getLocalPlayer().isAnimating(),
    Calculations.random(7000, 12000));
    break;
    
    }
    
    return Calculations.random(250, 350);
    }
    
    private void move() {
    log("getting new tree.");
    if (tree.distance() < Calculations.random(5, 7)) {
    Status = "Moving camera";
    getCamera().rotateToEntity(tree);
    getCamera().rotateToPitch(Calculations.random(32, 39));
    } else {
    Status = "Walking to stuff";
    if (tree != null) {
    getWalking().walk(tree);
    sleepUntil(
    () -> (getClient().getDestination().distance() < Calculations.random(
    4, 6))
    || getLocalPlayer().isStandingStill(),
    Calculations.random(4100, 5110));
    }
    
    }
    }
    
    private int F2PWorld() { // Don't do this pls
    int random = Calculations.random(1, 12);
    // 1|8|16|26|35|81|82|83|84|85|93|94
    int world = 0;
    
    if (random == 1) {
    world = 1;
    } else if (random == 2) {
    world = 8;
    } else if (random == 3) {
    world = 16;
    } else if (random == 4) {
    world = 26;
    } else if (random == 5) {
    world = 35;
    } else if (random == 6) {
    world = 81;
    } else if (random == 7) {
    world = 82;
    } else if (random == 8) {
    world = 83;
    } else if (random == 9) {
    world = 84;
    } else if (random == 10) {
    world = 85;
    } else if (random == 11) {
    world = 93;
    } else if (random == 12) {
    world = 94;
    }
    
    if (world != getClient().getCurrentWorld()) {
    return world;
    } else {
    return F2PWorld();
    }
    }
    
    private int P2PWorld() { // this looks more legit
    
    int world = getWorlds().getRandomWorld(
    w -> w.isMembers() && w.getID() != (319) && w.getID() != (325)
    && w.getID() != (337) && w.getID() != (345)
    && w.getID() != (352) && w.getID() != (357)
    && w.getID() != (360) && w.getID() != (374)
    && w.getID() != (373) && w.getID() != (366)
    && w.getID() != (365) && w.getID() != (361)
    && w.getID() != (353)
    && w.getID() != getClient().getCurrentWorld()).getID();
    return world;
    }
    
    private void hopWorlds() {
    if (gui.getway() == "Free2Play") {
    if (getWorldHopper().hopWorld(F2PWorld())) {
    sleep(Calculations.random(1000, 2500));
    sleepUntil(() -> getLocalPlayer().exists()
    && getClient().isLoggedIn(),
    Calculations.random(5000, 8500));
    sleepUntil(() -> treeArea.contains(tree),
    Calculations.random(2000, 3500));
    }
    } else {
    if (getWorldHopper().hopWorld(P2PWorld())) {
    sleep(Calculations.random(1000, 2500));
    sleepUntil(() -> getLocalPlayer().exists()
    && getClient().isLoggedIn(),
    Calculations.random(5000, 8500));
    sleepUntil(() -> treeArea.contains(tree),
    Calculations.random(2000, 3500));
    }
    }
    }
    
    private void chop() {
    sleep(Calculations.random(50, 160));
    if (tree != null && tree.interact("Chop down")) {
    log("Chopping new tree.");
    sleep(Calculations.random(600, 1200));
    sleepUntil(() -> !getLocalPlayer().isMoving(),
    Calculations.random(3500, 5000));
    sleep(Calculations.random(150, 311));
    if (getLocalPlayer().isAnimating()) {
    antiBan();
    sleepUntil(() -> !getLocalPlayer().isAnimating(),
    Calculations.random(7000, 12000));
    }
    }
    }
    
    private void bank() {
    
    if (!getTabs().isOpen(Tab.INVENTORY)) {
    getTabs().open(Tab.INVENTORY);
    } else {
    if (getBank().isOpen()) {
    if (!getInventory().onlyContains("Bronze axe", "Iron axe",
    "Steel axe", "Black axe", "Mithril axe", "Adamant axe",
    "Rune axe", "Dragon axe", "Infernal axe")) {
    getBank().depositAllExcept("Bronze axe", "Iron axe",
    "Steel axe", "Black axe", "Mithril axe",
    "Adamant axe", "Rune axe", "Dragon axe",
    "Infernal axe");
    } else {
    if (getBank().close()) {
    sleepUntil(() -> !getBank().isOpen(),
    Calculations.random(6000, 8000));
    }
    }
    } else {
    if (getLocalPlayer().distance(
    getBank().getClosestBankLocation().getCenter()) > Calculations
    .random(6, 9)) {
    if (getWalking().walk(
    getBank().getClosestBankLocation().getCenter())) {
    sleepUntil(
    () -> !getLocalPlayer().isMoving()
    || getLocalPlayer().distance(
    getClient().getDestination()) < 8,
    Calculations.random(3450, 5800));
    }
    } else {
    getBank().open();
    sleepUntil(() -> getBank().isOpen(),
    Calculations.random(6000, 8000));
    }
    }
    }
    }
    
    private void antiBan() { // most simple 'antiban' to make
    int random = Calculations.random(1, 250);
    
    if (random == 1) {
    if (!getTabs().isOpen(Tab.STATS)) {
    getTabs().open(Tab.STATS);
    getSkills().hoverSkill(Skill.WOODCUTTING);
    sleep(Calculations.random(1000, 2000));
    getTabs().open(Tab.INVENTORY);
    }
    } else if (random <= 10) {
    if (!getTabs().isOpen(Tab.INVENTORY)) {
    getTabs().open(Tab.INVENTORY);
    }
    } else if (random <= 15) {
    getCamera().rotateToTile(treeArea.getRandomTile());
    } else if (random <= 20) {
    getCamera().rotateToEntity(getLocalPlayer());
    } else if (random <= 88) {
    if (getMouse().isMouseInScreen()) {
    if (getMouse().moveMouseOutsideScreen()) {
    sleep(Calculations.random(1500, 3000));
    }
    }
    } else {
    //
    }
    }
    
    /*
    * Paint
    */
    
    private final Color color1 = new Color(51, 51, 51, 147);
    private final Color color2 = new Color(35, 77, 19);
    private final Color color3 = new Color(255, 255, 255);
    private final BasicStroke stroke1 = new BasicStroke(5);
    private final Font font1 = new Font("Arial", Font.BOLD, 13);
    private final Font font2 = new Font("Arial", Font.BOLD, 0);
    private final Font font3 = new Font("Arial", 0, 13);
    private Timer t = new Timer();
    
    public void onPaint(Graphics g1) {
    logsgained = (int) Math.floor(getSkillTracker().getGainedExperience(
    Skill.WOODCUTTING) / 175); // Detects chopped logs
    logsanhour = t.getHourlyRate(logsgained);
    
    if (t == null) {
    t = new Timer(0);
    }
    Graphics2D g = (Graphics2D) g1;
    Stroke stroke = g.getStroke();
    g.setColor(color1);
    g.fillRect(3, 4, 175, 165);
    g.setColor(color2);
    g.setStroke(stroke1);
    g.drawRect(3, 4, 175, 165);
    g.setFont(font1);
    g.setColor(color3);
    g.drawString(getManifest().name() + "         " + "v"
    + getManifest().version(), 12, 29);
    g.setFont(font2);
    g.setFont(font3);
    g.drawString("Time running: " + Timer.formatTime(t.elapsed()), 12, 59);
    g.drawString(
    "Levels gained: " + getSkills().getRealLevel(Skill.WOODCUTTING)
    + "(+"
    + getSkillTracker().getGainedLevels(Skill.WOODCUTTING)
    + ")", 12, 79);
    g.drawString(
    "XP gained: "
    + getSkillTracker().getGainedExperience(
    Skill.WOODCUTTING)
    + "("
    + getSkillTracker().getGainedExperiencePerHour(
    Skill.WOODCUTTING) + ")", 12, 99);
    g.drawString(
    "XP to level: "
    + getSkills().getExperienceToLevel(Skill.WOODCUTTING),
    12, 121);
    g.drawString(
    "Chopped [P/H]: " + logsgained + " ["
    + t.getHourlyRate(logsgained) + "]", 12, 141);
    g.drawString("GP(/h): " + (int) Math.floor(logsgained * 400) + " ["
    + (int) Math.floor(logsanhour * 400) + "]", 12, 161);
    if (gui.getway() == "Member") {
    g.drawString("{" + xnests + "}", 150, 161);
    }
    g.setStroke(stroke);
    }
    
    public void setStartScript(boolean startScript) {
    this.startScript = startScript;
    }
    
    @Override
    public void onGameMessage(Message message) {
    if (message.getMessage().contains("A bird's nest falls")) {
    xnests++;
    newNest = true;
    }
    }
    
    @Override
    public void onPlayerMessage(Message arg0) {
    }
    
    @Override
    public void onPrivateInMessage(Message arg0) {
    }
    
    @Override
    public void onPrivateOutMessage(Message arg0) {
    }
    
    @Override
    public void onTradeMessage(Message arg0) {
    }
    }
    

     

     

     

     

     

     

    import java.awt.*;
    import java.awt.event.*;
    
    import javax.swing.*;
    
    @SuppressWarnings("serial")
    public class YewsGUI extends JFrame {
    	private Main ctx;
    
    	public YewsGUI(Main main) {
    		getContentPane().setBackground(Color.LIGHT_GRAY);
    		setForeground(Color.LIGHT_GRAY);
    		getContentPane().setBackground(SystemColor.activeCaption);
    		getContentPane().setForeground(Color.LIGHT_GRAY);
    		this.ctx = main;
    		initComponents();
    	}
    
    	private void button1ActionPerformed(ActionEvent e) {
    		// if button is clicked this will be activated
    		ctx.setStartScript(true);
    		this.setVisible(false);
    	}
    
    	private void initComponents() {
    		comboBox1 = new JComboBox<>();
    		comboBox1.setBounds(10, 46, 136, 75);
    
    		// ======== this ========
    		setTitle("GE Yews");
    
    		// ---- comboBox1 ----
    		comboBox1.setModel(new DefaultComboBoxModel<>(new String[] {
    				"Free2Play", "Member", }));
    
    		JLabel lblNewLabel = new JLabel("Member or Free2Play?");
    		lblNewLabel.setBounds(11, 13, 136, 34);
    		getContentPane().setPreferredSize(new Dimension(300, 200));
    		pack();
    		setLocationRelativeTo(getOwner());
    		getContentPane().setLayout(null);
    		getContentPane().add(comboBox1);
    		getContentPane().add(lblNewLabel);
    		button1 = new JButton();
    		button1.setBounds(159, 15, 81, 106);
    
    		// ---- button1 ----
    		button1.setText("Start");
    		button1.addActionListener(e -> button1ActionPerformed(e));
    		getContentPane().add(button1);
    	}
    
    	// a getter to acces this piece of information
    	public String getway() {
    		return comboBox1.getSelectedItem().toString();
    	}
    
    	private JButton button1;
    	private JComboBox<String> comboBox1;
    } 

     

     

     

     

    Link to comment
    Share on other sites

    I appreciate you releasing the source code! It's always cool to look at other peoples code and compare it to the way I write my own scripts. I don't use states, but I feel like  this is a good example of a state based script to use, should I want to write one.

    Link to comment
    Share on other sites

    I appreciate you releasing the source code! It's always cool to look at other peoples code and compare it to the way I write my own scripts. I don't use states, but I feel like  this is a good example of a state based script to use, should I want to write one.

    You should definitely try states/notes. It is awesome

    Link to comment
    Share on other sites

    I appreciate you releasing the source code! It's always cool to look at other peoples code and compare it to the way I write my own scripts. I don't use states, but I feel like  this is a good example of a state based script to use, should I want to write one.

     

    Thanks for releasing this, will definitely help scripters with figuring out logic and hownto use the API :)

     

    Thanks for the feedback, I really hope I can learn new scripters a better additute on how to script.

    Because most ppl don't think or understand how this stuff exactly works  :D

    Link to comment
    Share on other sites

    • 1 month later...

    Archived

    This topic is now archived and is closed to further replies.

    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.