draanz 1 Posted September 26, 2021 Here is my easy script, just buys bronze axes from bob in lumbridge and banks them, hopping worlds to find more axes in stock. Just getting my toes wet with something easy to learn the api a bit, it is by no means perfect and I am leaving my debugging stuff in the code because I plan on adding some different features. thanks guys! import org.dreambot.api.methods.Calculations; import org.dreambot.api.methods.container.impl.Shop; import org.dreambot.api.methods.container.impl.bank.Bank; import org.dreambot.api.methods.map.Area; import org.dreambot.api.methods.map.Tile; import org.dreambot.api.methods.world.World; import org.dreambot.api.methods.world.Worlds; 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 java.awt.*; @ScriptManifest(name = "Axe buyer", author = "Dran", description = "Buys bronze axe", version = 1.0, category = Category.MISC) public class axeBuyer extends AbstractScript { private Timer t = new Timer(); //Area area = new Area(new TIle(x,y,z), new Tile(x,y,z)); private final Area lumbridgeCastleFl0 = new Area ( new Tile(3205, 3229 , 0), new Tile(3216, 3209, 0)); private final Area lumbridgeCastleFl1 = new Area ( new Tile(3205, 3229 , 1), new Tile(3216, 3209, 1)); private final Area lumbridgeCastleFl2 = new Area ( new Tile(3205, 3229 , 2), new Tile(3216, 3209, 2)); private final Area axeShop = new Area (new Tile (3233, 3201, 0), new Tile (3228, 3205, 0)); enum Location {GROUND_FLOOR, FIRST_FLOOR, SECOND_FLOOR, AXE_SHOP, NOT_IN_LOCATION ;} Location loc; enum State {BUYING, CHECK_SHOP, BANKING, WALK_BANK, WALK_SHOP, HOPPING, STOP_SCRIPT;} State state; enum shopState {FULL, EMPTY, UNCHECKED;} shopState ss; World potentialWorld = Worlds.getRandomWorld(w -> w.isF2P() && !w.isPVP() && w.getMinimumLevel() == 0); @Override public void onStart() { ss = shopState.UNCHECKED; log(loc); } public void ABLE_TO_BUY() { if(Shop.count("Bronze axe") > 4 && Shop.isOpen()) ss = shopState.FULL; else if (Shop.isOpen()) ss = shopState.EMPTY; } public void location() { if(lumbridgeCastleFl0.contains(getLocalPlayer())) loc = Location.GROUND_FLOOR; else if(lumbridgeCastleFl1.contains(getLocalPlayer())) loc = Location.FIRST_FLOOR; else if(lumbridgeCastleFl2.contains(getLocalPlayer())) loc = Location.SECOND_FLOOR; else if (axeShop.contains(getLocalPlayer())) loc = Location.AXE_SHOP; else loc = Location.NOT_IN_LOCATION; } public void state() { if(loc == Location.AXE_SHOP && getInventory().contains("coins") && !getInventory().isFull() && ss == shopState.FULL) { state = State.BUYING; log(state); } else if (loc == Location.AXE_SHOP && getInventory().contains("coins") && !getInventory().isFull() && ss == shopState.UNCHECKED && !Shop.isOpen()) { state = State.CHECK_SHOP; log(state); } else if (loc == Location.AXE_SHOP && getInventory().contains("coins") && !getInventory().isFull() && ss == shopState.EMPTY) { state = State.HOPPING; log(state); } else if(getInventory().contains("coins") && !getInventory().isFull() && loc != Location.AXE_SHOP) { state = State.WALK_SHOP; log(state); } else if(getInventory().contains("coins") && loc != Location.SECOND_FLOOR && getInventory().isFull()) { state = State.WALK_BANK; log(state); } else if(!getInventory().contains("coins")) { state = State.STOP_SCRIPT; log(state); } else if (loc == Location.SECOND_FLOOR && getInventory().isFull()) { state = State.BANKING; log(state); } } public void doTask() { if (state == State.HOPPING) { Shop.close(); getWorldHopper().hopWorld(potentialWorld); potentialWorld = Worlds.getRandomWorld(w -> w.isF2P() && !w.isPVP() && w.getMinimumLevel() == 0); ss = shopState.UNCHECKED; } else if(state == State.CHECK_SHOP) { Shop.open(); //ss = shopState.CHECKING; sleep(500); state(); }else if (state == State.BUYING) { Shop.purchaseTen("Bronze axe"); sleep(660); }else if(state == State.WALK_BANK) { getWalking().walk(lumbridgeCastleFl2); } else if(state == State.BANKING) { Bank.open(); sleep(1200,2800); Bank.depositAll("Bronze axe"); sleep(550); Bank.close(); } else if(state == State.WALK_SHOP) { getWalking().walk(axeShop); } } @Override public int onLoop() { location(); ABLE_TO_BUY(); state(); log(ss); log(state); doTask(); sleep(400); log(potentialWorld); sleep(300,700); return Calculations.random(300, 600); } @Override public void onExit() { } public void onPaint(Graphics2D g) { g.setColor(Color.WHITE); g.setFont(new Font("Arial", 1, 11)); g.drawString("Time Running: " + t.formatTime(), 25, 50); } }
draanz 1 Author Posted September 26, 2021 Also I realize my naming schemes are all over the place lol.
Eclipseop 194 Posted September 26, 2021 https://docs.oracle.com/javase/tutorial/java/javaOO/returnvalue.html https://www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html World potentialWorld = Worlds.getRandomWorld(w -> w.isF2P() && !w.isPVP() && w.getMinimumLevel() == 0); Instead of initing this variable and then resetting it, you could do Supplier<World> potentialWorld = () -> Worlds.getRand... potentialWorld.get(); or you know, just dont store it as a variable and just call the method 2 begin w/ 6 hours ago, draanz said: Bank.open(); sleep(1200,2800); Bank.depositAll("Bronze axe"); sleep(550); Bank.close(); What if bank.open fails???? bank.depositall/close is still going to be called
Eclipseop 194 Posted September 26, 2021 Quote if(loc == Location.AXE_SHOP && getInventory().contains("coins") && !getInventory().isFull() && ss == shopState.FULL) { state = State.BUYING; log(state); } else if (loc == Location.AXE_SHOP && getInventory().contains("coins") && !getInventory().isFull() && ss == shopState.UNCHECKED && !Shop.isOpen()) { state = State.CHECK_SHOP; log(state); } else if (loc == Location.AXE_SHOP && getInventory().contains("coins") && !getInventory().isFull() && ss == shopState.EMPTY) { state = State.HOPPING; log(state); } else if(getInventory().contains("coins") && !getInventory().isFull() && loc != Location.AXE_SHOP) { state = State.WALK_SHOP; log(state); } else if(getInventory().contains("coins") && loc != Location.SECOND_FLOOR && getInventory().isFull()) { state = State.WALK_BANK; log(state); } else if(!getInventory().contains("coins")) { state = State.STOP_SCRIPT; log(state); } else if (loc == Location.SECOND_FLOOR && getInventory().isFull()) { state = State.BANKING; log(state); } what if u call inventory.contains(coins) in a parent if statement, then u wont have to check it 5 times! can do this w/ the isfull methods 2
draanz 1 Author Posted September 26, 2021 3 hours ago, Eclipseop said: what if u call inventory.contains(coins) in a parent if statement, then u wont have to check it 5 times! can do this w/ the isfull methods 2 Thanks for your advise, I am implementing these suggestions now!
Recommended Posts
Archived
This topic is now archived and is closed to further replies.