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.

First scripts made, How to use more than one class?

Featured Replies

So I've made my first few scripts, basically just simple tasks all inside a main class.
How can I now call that main class inside another class?

For example:

main class - fills jugs, banks, repeat.

new class - timer class
If time < 1 hour
    main class
else
    end program

Code snippet if it helps.

import org.osbot.rs07.api.model.Character;
import org.osbot.rs07.api.model.Entity;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
import org.osbot.rs07.api.map.Position;
import org.osbot.rs07.api.model.NPC;

import java.util.Arrays;
import java.util.List;
import java.awt.*;

@ScriptManifest(author = "Lexhanatin", info = "My first script", name = "Jug Filler", version = 0, logo = "")
public class main extends Script {
		private Position[] path = {
			new Position(3253, 3426, 0), // Outside bank.
			new Position(3246, 3429, 0),
			new Position(3239, 3433, 0) // Fountain
		};
		
		private Position[] path2 = {
				new Position(3239, 3433, 0), // Fountain
				new Position(3246, 3429, 0),
				new Position(3253, 3426, 0) // Outside bank.
			};
		
		List toFill = Arrays.asList(path);
		List toBank = Arrays.asList(path2);
	
		@Override
		public void onStart() {
			log("Welcome to Jug Filler by Lexhanatin.");
			log("If you experience any issues while running this script please report them to me on the forums.");
			log("Enjoy the script!");
		}
	
		private enum State {
			FILL, BANK, WAIT
		};
	
		private State getState() {
			Entity fountain = objects.closest("Fountain");
			NPC banker = npcs.closest("Banker");
			
			if (inventory.getAmount("Jug") == 28 && fountain != null)
				return State.FILL;
			if ((banker != null) && inventory.getAmount("Jug of water") == 28 ||
				(banker != null) && inventory.isEmpty())
				return State.BANK;
			return State.WAIT;
		}
	
		@Override
		public int onLoop() throws InterruptedException {
			switch (getState()) {
			case FILL:
				getWalking().walkPath(toFill);
				sleep(500);
				
				Entity fountain = objects.closest("Fountain");
				if (inventory.getAmount("Jug") == 28 && fountain != null) {
					inventory.interact("Use", "Jug");
					sleep(random(80, 100));
					if (inventory.isItemSelected()) {
						fountain.interact("Use", "Jug -> Fountain");
						sleep(random(80, 100));
						
						Character me = myPlayer();
						if(myPlayer().isAnimating()) {
							sleep(5000);
						}
					}
				}
				sleep(random(5000, 10000));
				break;
			case BANK:
				if (!getBank().isOpen()){
				    getBank().open();
				} 
				if(inventory.isEmpty()){
					getBank().withdraw("Jug", 28);
					sleep(random(500, 800));
					getBank().close();
				 } else if (inventory.isFull()) {
				        getBank().depositAll();
				        sleep(random(500, 800));
				        getBank().withdraw("Jug", 28);
				        sleep(random(500, 800));
				        getBank().close();
				} else {
		        	getBank().close();
		        }
				break;
			case WAIT:
				sleep(random(500, 700));
				break;
			}
			return random(200, 300);
		}

	@Override
	public void onExit() {
		log("Thanks for running my Jug Filler!");
	}

	@Override
	public void onPaint(Graphics2D g) {

	}
} 

 

I think you should take a look at task/node based scripts, here is a good example

 

What is it that you want to do, stop the script after 1 hour?

 

Like Sumo said, task based scripts is probably what you're looking for here.

//init somewhere in your main class
long startTime;
long playTime;
long breakTime;

public void onStart(){
    startTime = System.currentTimeMillis();
    playTime = TimeUnit.MINUTES.toMillis(60);
    breakTime = startTime + playTime;
}

public int loop(){ //your main loop
  if(breakTime < System.currentTimeMillis()){ //should break?
    log("It's been 60 minutes now, lets stop the script :)");
    stop();
  }else{ //if we shouldnt break
    //run the script as usual
  }
}

If you just want to stop the script after 1 hour you can do this.

 

I just wrote it out of my head right now (on my phone) so might be typos. Keep in mind that there are probably better ways of doing this, but it works.

Edited by Sumo

To be honest, people suggest using this "task/node" based design but really it offers little to no benefit over a simple switch statement, apart from perhaps non-blocking checks. At least for the script that you've written here, it would just complicate things. For a script such as this one, there's no problem keeping things in one place. (Also i'm not really sure why people call it a 'node' structure in the first place?)

Instead I would focus on more important things like trying to understand exactly what you've written, for example:

					if (inventory.isItemSelected()) {
						fountain.interact("Use", "Jug -> Fountain");
						sleep(random(80, 100));
						
						Character me = myPlayer(); // <-- ??
						if(myPlayer().isAnimating()) {
							sleep(5000);
						}
					}

And also making your script as bullet-proof as possible. For example, what happens if you're standing by the fountain with 28 noted jugs in your inventory, or if both the fountain and banker in your getState() function are null? - Your script should always be in a situation where it can and will do something!

Cheers

-Apa

Create an account or sign in to comment

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.