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.

Generating an area next to an RS2Object with variable size

Featured Replies

What does this code do? It generates an area with specified dimensions spread outward.

Why is it useful? can be used to generate locations to walk to near an object.

 

Code:

public enum Direction {
	NORTH, EAST, SOUTH, WEST;
}
	public Area generateAreaRelativeToObject(RS2Object origin_object, Direction direction, int width_outwards, int height_outwards) {

		ArrayList<Position> area_tiles = new ArrayList<Position>();
		Position origin_object_position = origin_object.getPosition();

		int x_min = 0;
		int x_max = 0;

		int y_min = 0;
		int y_max = 0;

		switch (direction) {

		case NORTH:
			x_min = origin_object_position.getX() - width_outwards;
			x_max = origin_object_position.getX() + origin_object.getSizeX() - 1 + width_outwards;
			y_min = origin_object_position.getY() + origin_object.getSizeY();
			y_max = y_min + height_outwards - 1;
			break;

		case EAST:
			x_min = origin_object_position.getX() + origin_object.getSizeX();
			x_max = x_min + width_outwards - 1;
			y_min = origin_object_position.getY() - height_outwards - 1;
			y_max = origin_object_position.getY() + origin_object.getSizeY() - 1 + height_outwards;
			break;

		case SOUTH:
			x_min = origin_object_position.getX() - width_outwards;
			x_max = origin_object_position.getX() + origin_object.getSizeX() - 1 + width_outwards;
			y_min = origin_object_position.getY() - height_outwards;
			y_max = origin_object_position.getY() - 1;
			break;

		case WEST:
			x_min = origin_object_position.getX() - width_outwards;
			x_max = origin_object_position.getX() - 1;
			y_min = origin_object_position.getY() - height_outwards;
			y_max = origin_object_position.getY() + origin_object.getSizeY() - 1 + height_outwards;
			break;

		}

		for (int x = x_min; x <= x_max; x++) {
			for (int y = y_min; y <= y_max; y++) {
				area_tiles.add(new Position(x, y, origin_object_position.getZ()));
			}
		}

		Position top_left_position = null;
		Position bottom_right_position = null;

		for (Position p : area_tiles) {

			if (top_left_position == null) {
				top_left_position = p;
			} else {
				if (p.getX() < top_left_position.getX())
					top_left_position = p;
				if (p.getY() > top_left_position.getY())
					top_left_position = p;

				if (bottom_right_position == null) {
					bottom_right_position = p;
				}

				if (p.getX() > bottom_right_position.getX())
					bottom_right_position = p;
				if (p.getY() < bottom_right_position.getY())
					bottom_right_position = p;
			}
		}

		return new Area(top_left_position, bottom_right_position);
	}

 

Examples:

area = generateAreaRelativeToObject(altar, Direction.SOUTH, 0, 1); 

d703028cce7f604e11b59bcaf2282a40.png

area = generateAreaRelativeToObject(altar, Direction.EAST, 1, 0);

7adbc2d5b3d9206e251263be19ea086f.png

area = generateAreaRelativeToObject(altar, Direction.SOUTH, 2, 2);

e19c2aaa68c592b4c0768764e51dc917.png

area = generateAreaRelativeToObject(cart, Direction.EAST, 1, 0); 

[Works with any size object]

32f54eae6f857073825fcf945ebd20e8.png

 

 

Edited by House

  • 5 weeks later...

How do you implement this into a constants class? or without having to add the code to a node.

What does this code do? It generates an area with specified dimensions spread outward.

Why is it useful? can be used to generate locations to walk to near an object.

 

Code:

public enum Direction {
	NORTH, EAST, SOUTH, WEST;
}
	public Area generateAreaRelativeToObject(RS2Object origin_object, Direction direction, int width_outwards, int height_outwards) {

		ArrayList<Position> area_tiles = new ArrayList<Position>();
		Position origin_object_position = origin_object.getPosition();

		int x_min = 0;
		int x_max = 0;

		int y_min = 0;
		int y_max = 0;

		switch (direction) {

		case NORTH:
			x_min = origin_object_position.getX() - width_outwards;
			x_max = origin_object_position.getX() + origin_object.getSizeX() - 1 + width_outwards;
			y_min = origin_object_position.getY() + origin_object.getSizeY();
			y_max = y_min + height_outwards - 1;
			break;

		case EAST:
			x_min = origin_object_position.getX() + origin_object.getSizeX();
			x_max = x_min + width_outwards - 1;
			y_min = origin_object_position.getY() - height_outwards - 1;
			y_max = origin_object_position.getY() + origin_object.getSizeY() - 1 + height_outwards;
			break;

		case SOUTH:
			x_min = origin_object_position.getX() - width_outwards;
			x_max = origin_object_position.getX() + origin_object.getSizeX() - 1 + width_outwards;
			y_min = origin_object_position.getY() - height_outwards;
			y_max = origin_object_position.getY() - 1;
			break;

		case WEST:
			x_min = origin_object_position.getX() - width_outwards;
			x_max = origin_object_position.getX() - 1;
			y_min = origin_object_position.getY() - height_outwards;
			y_max = origin_object_position.getY() + origin_object.getSizeY() - 1 + height_outwards;
			break;

		}

		for (int x = x_min; x <= x_max; x++) {
			for (int y = y_min; y <= y_max; y++) {
				area_tiles.add(new Position(x, y, origin_object_position.getZ()));
			}
		}

		Position top_left_position = null;
		Position bottom_right_position = null;

		for (Position p : area_tiles) {

			if (top_left_position == null) {
				top_left_position = p;
			} else {
				if (p.getX() < top_left_position.getX())
					top_left_position = p;
				if (p.getY() > top_left_position.getY())
					top_left_position = p;

				if (bottom_right_position == null) {
					bottom_right_position = p;
				}

				if (p.getX() > bottom_right_position.getX())
					bottom_right_position = p;
				if (p.getY() < bottom_right_position.getY())
					bottom_right_position = p;
			}
		}

		return new Area(top_left_position, bottom_right_position);
	}

 

Examples:

area = generateAreaRelativeToObject(altar, Direction.SOUTH, 0, 1); 

d703028cce7f604e11b59bcaf2282a40.png

area = generateAreaRelativeToObject(altar, Direction.EAST, 1, 0);

7adbc2d5b3d9206e251263be19ea086f.png

area = generateAreaRelativeToObject(altar, Direction.SOUTH, 2, 2);

e19c2aaa68c592b4c0768764e51dc917.png

area = generateAreaRelativeToObject(cart, Direction.EAST, 1, 0); 

[Works with any size object]

32f54eae6f857073825fcf945ebd20e8.png

 

 

 

Can you tell me how to implement it without having to have the code in the class itself?

 

Can you tell me how to implement it without having to have the code in the class itself?

 

If you can't figure that out, your going to need to learn more about Java before you start working on scripts. Not meaning that in a harsh way whatsoever but things like that are very basic and you have to walk before you can run.

If you can't figure that out, your going to need to learn more about Java before you start working on scripts. Not meaning that in a harsh way whatsoever but things like that are very basic and you have to walk before you can run.

 

Ya weird thing is ive made several scripts already. Willing to tutor me alittle, i'll pay ya! :)

How do I call this class into another class though. its a Enum?

Ya weird thing is ive made several scripts already. Willing to tutor me alittle, i'll pay ya! smile.png

How do I call this class into another class though. its a Enum?

 

Read through this,

https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html

It explains what an Enum is and how to use it in basic and more advanced ways.

Currently in the middle of studying for exams which are coming up in a week or two so couldn't tutor you atm, wouldn't need any payment if I did either. Mr Pro Pop has a thread regarding him tutoring people for free so check him out.

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.