Jump to content
View in the app

A better way to browse. Learn more.

OSBot :: 2007 OSRS Botting

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Condition

Featured Replies

public abstract interface Condition {
	
	public abstract boolean active();

	public abstract void run() throws InterruptedException;
}

Example of usage: (shit script wrote it fast for the sake of this tutorial.)

public int onLoop() throws InterruptedException {
		if(canMine.active()){
			canMine.run();
		}
		if(canDrop.active()){
			canDrop.run();
		}
		return 10;
	}
	


public Condition canMine = new Condition() {
		@Override
		public boolean active() {
			Global.status = "Searching for ore";
			Global.rock = closestObject(Global.ROCK_ID_1, Global.ROCK_ID_2,Global.ROCK_ID_3);
			return Global.rock != null && !client.getInventory().isFull() && Global.rock.getPosition().distance(client.getMyPlayer().getPosition()) <= 5;
		}
		@Override
		public void run() throws InterruptedException {
			if(Global.rock != null){
				Global.rock.interact("Mine");
				Global.status = "Mining";
				sleep(random(1000,1800));
				while(client.getMyPlayer().isMoving() || client.getMyPlayer().isAnimating() || client.getMyPlayer().isUnderAttack()){
					sleep(10);
				}
			}
		}
	};
	
	public Condition canDrop = new Condition(){
		@Override
		public boolean active() {
			return client.getInventory().getTotalItemsAmount() >= 28;
		}
		@Override
		public void run() throws InterruptedException {
			Global.status = "Dropping ore";
			client.getInventory().dropAllExcept(Global.PICK_IDS);
		}
	};

Edited by PurpleKush

I see you're going for an abstract state model, I took a similar approach when writing my first script yesterday smile.png

 

Declaring fields to hold the states is bad design, you should try something like this:

public enum State {
 
     MINING_ORE(new AbstractState() {
         ...
     }),
 
     DROPPING_ORE(new AbstractState() {
         ...
     });
 
     private State(AbstractState abstractState) {
          ...
     }
 
     ...
}

then you can just loop through all of the states

for(State s : State.values()) {
     if(s.getAbstractState().force(...)) {
          s.getAbstractState().run();
     }
}

a lot more maintainable and it looks nicer too. also your naming is a bit off tongue.png

Edited by lare96

Guest
This topic is now closed to further replies.

Recently Browsing 0

  • No registered users viewing this page.

Account

Navigation

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.