Jump to content
×
×
  • Create New...

Tiles and Areas


Recommended Posts

The Basics

to properly understand tiles and areas and how they work it's crucial you understand the basics of grids and coordinates.

A grid is, as you can see in the picture below, multiple lines in two directions (axis) named x (west to east in runescape) and y (south to north in runescape) that form squares of equal sizes.

These squares is what a Tile is.

runescape is a three dimensional game, so the game consists of multiple of these grids which is identified by a third axis named z (from bottom to top),
so each Tile is therefore defined by a three dimensional coordinate like so (x, y, z)

195893423_XY-gridwithgreensquare.thumb.png.e662df541c8dcf7344a0fa022326d528.png

lets imagine this grid represents the base floor (z = 0) and the green square is the current location of the player. his location would be (3, 6, 0)

Hopefully this gives you a good understanding of the basics

 

Area

an area is defined as any closed two dimensional shape of any size. 

lets say you want to kill goblins in the goblin house next to lumbridge, and you only want to attack goblins if you're inside the house.
So you put on View>Location to see the tile coordinates you're on and run to the corners closest to negative and positive infinity and write them down, you create an Area and define it as the house and start running the script.
You quickly notice the bot just standing still so you create a function to draw the area you made to see what happened:

example1.png.f91a233265a23b549f46bb129c7312df.png

 

Turns out the outer edge towards positive infinity isn't included in our area.

This is because an area creates a line between the coordinates of all tiles in it's constructor, which is the base of the tile.

The area does not include the tile you were standing on when writing down the coordinates for your area.
If you want to create an area by using your in game character you have to add +1 to the edges pointing towards positive infinity.

Area defined by multiple tiles

An area can also be constructed with multiple tiles, forming any closed shape. If you want to do this it's important you remember where the area constructor considers a tile to be and what tiles will be included in your area

example2.thumb.png.d2424ea4a5ca3ff0a6cea839391c83e4.png

In this example we have defined three tiles to make an area with a triangle shape: t1(2, 6, 0) t2(2, 2, 0) t3(5, 2, 0).

red indicates the squares you would occupy should you stand on the tiles defined in the constructor, the green tiles are the tiles actually included in the area object.

Looking at this figure you can see that in order for a tile to be included in an area, only the base of the tile has to be inside the shape.
It's not enough for the base to be along the edge of the shape

 

The Area class has a method Area.containsOrIntersects(Locatable... locatables), which would return true if the player was on either on t1 or t3, because the tile the player occupies is along the edge of the shape.
Using this method would make the bot in the goblin house example work, because it would return true for the entire house. However I recommend making sure the area actually contains all the tiles you want it to, in case you 
want to add looting and want to only loot items inside your defined area.

 

TileMatrix

The Tile class is defining the coordinate of the tile, while the TileMatrix is the actual square which can be interacted with.

If you want to walk somewhere by clicking on the game instead of the minimap you'll have to convert your tile into  a tilematrix using Tile.matrix(ctx).
The matrix is also used for when you want to draw the tile on screen

 

Drawing tiles

using the Paintlistener interface you can draw tiles on screen like so:

example3.png.4d7f28e270c02bf03831dcb53b0585c1.png

please do not actually initialize anything inside the repaint method, it's called 10s of times a second eating up your cpu.

Tiles and Areas in debugging

When you're new you might run to multiple problems where the bot doesn't behave you want it to, this is often due to faulty queries and  misinterpreting what's going on. One of the best debugging tools  is to 
simply draw or print out the tile of the object you're trying to interact with. if the tile is (-1, -1, -1) it means  your object isn't set at all and you have to reevaluate your query. Other times it turns out you've queried an object with the same id but outside of the bot's view, causing the bot to stand still, this one is particularly tricky to detect without printing/drawing tiles.

Hopefully this makes it easier to understand what a tile and area actually is and reduces headaches when developing 🙂 if you have any questions regarding tiles/areas I know a lot more than is covered in this post.

all feedback is appreciated, it's my first time making a guide/tutorial/informational post

 

Note

the z axis is the only axis which can have a negative value (basements). All valid tiles have positive values on the  x and y axis

 

  • Like 3
  • Thanks 1
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.