darkjack7 4 Share Posted May 29, 2016 hey you guys. here is a cabbage picker i wrote trying to use the most simply logic that even a non scripter could understand. 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 More sharing options...
lily 490 Share Posted May 29, 2016 Hooray for picker scripts! =D Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted May 29, 2016 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 Link to comment Share on other sites More sharing options...
regicide3342 0 Share Posted May 30, 2016 gratz on release 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 More sharing options...
maxwell22 0 Share Posted May 31, 2016 how can i get this script ? Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted June 2, 2016 Psst dark build the jar and post a link to download it for people. Or throw this on SDN Link to comment Share on other sites More sharing options...
Studentcoder 0 Share Posted June 8, 2016 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! Link to comment Share on other sites More sharing options...
Hopewelljnj 46 Share Posted June 8, 2016 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 More sharing options...
Mad 86 Share Posted June 8, 2016 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 More sharing options...
deathsgrasp 0 Share Posted June 8, 2016 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.