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
  • First very simple script, looking for some helpful advice. Thanks!


    draanz

    Recommended Posts

    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);
    	}
    }

     

    Link to comment
    Share on other sites

    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

    Link to comment
    Share on other sites

     

    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 :)

    Link to comment
    Share on other sites

    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!

     

    Link to comment
    Share on other sites

    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.