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
  • Try asking for help in the chatbox
  • extremely simplistic cabbage picker


    darkjack7
     Share

    Recommended Posts

    hey you guys. here is a cabbage picker i wrote trying to use the most simply logic that even a non scripter could understand.

     

    c3fdae631f492befb346dbecf465be17.png

    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics2D;
    
    import org.dreambot.api.methods.Calculations;
    import org.dreambot.api.methods.map.Area;
    import org.dreambot.api.methods.map.Tile;
    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.GameObject;
    
    
    
    @ScriptManifest(name = "cabbage picker", description = "", author = "", version = 0, category = Category.CRAFTING)
    public class main extends AbstractScript {   
    
    	Area cabbagefield = new Area(3044, 3283, 3067, 3297); // defining an area called cabbagearea
    	Tile depositboxtile = new Tile(3045, 3234); // tile of the depositbox 
    	GameObject cabbage; // cabbage
    	GameObject depositbox; // depositbox
    
    	public int onLoop() 
    	{	
    		if(!getInventory().isFull()) { 
    			if(cabbagefield.contains(getLocalPlayer())) {
    				cabbage = getGameObjects().closest(c -> c != null && c.getName().equals("Cabbage") && c.hasAction("Pick")); // defining cabbage by using a filter
    				cabbage.interact("Pick");
    				sleepUntil(() -> getLocalPlayer().getAnimation() == 827, Calculations.random(1429, 2845)); // example of conditional sleep, very helpful and should be saved
    				sleep(Calculations.random(312, 624));
    			} else {
    				getWalking().walk(cabbagefield.getRandomTile());
    				sleep(Calculations.random(1827,2482));
    			}
    		} else {
    			if(depositboxtile.distance(getLocalPlayer()) <= 4) {
    				if(getDepositBox().isOpen()) {
    					getDepositBox().depositAllItems();
    				} else {
    					depositbox = getGameObjects().closest(d -> d != null && d.getName().equals("Bank deposit box") && d.hasAction("Deposit"));
    					depositbox.interact("Deposit");
    					sleepUntil(() -> getDepositBox().isOpen(), Calculations.random(929, 1845));
    				}
    			} else {
    				getWalking().walk(depositboxtile);
    				sleep(Calculations.random(1827,2482));
    			}
    		}
    		
    		return Calculations.random(362, 625);
    	}
    
    }
    
    
    
    Link to comment
    Share on other sites

    Really cool what you did with this. By the way you can just do getDepositBox().open(); to click the deposit box and open the menu.

     

    Otherwise I really like your fancy picture :P

    Link to comment
    Share on other sites

    gratz on release :doge:

     

    No but this is a really nice learning tool for newer scripters; It really shows how to use logic to assemble an actual working script.

     

    Good job jack!

    Link to comment
    Share on other sites

    what does the c. mean here? when i try the c -> c != null line it says c needs to be something, but i don't know what it should identify as

     

    Thanks in advance!

    C -> C is being used as a filter. You can only use those in specific places.

    Link to comment
    Share on other sites

    You should prob not check for != null inside the filter, since this code could throw an NPE

    cabbage = getGameObjects().closest(c -> c != null && c.getName().equals("Cabbage") && c.hasAction("Pick"));
    cabbage.interact("Pick");
    
    Link to comment
    Share on other sites

     

    You should prob not check for != null inside the filter, since this code could throw an NPE

    cabbage = getGameObjects().closest(c -> c != null && c.getName().equals("Cabbage") && c.hasAction("Pick"));
    cabbage.interact("Pick");
    

     

    The first line couldn't throw an NPE and the null check might be necessary pending on how the getGameObjects() list is generated and how the Filter class is implemented. The second line could throw an NPE if there is nothing around that matches that filter though.

     

    Not sure if that's what you meant but I don't think (save execution time, even though that doesn't really matter) the null check really makes a difference.

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
     Share

    ×
    ×
    • 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.