SRL Archive - Outdated Tutorials

How to make a grid of boxes


Boreas

2007-08-10 23:18:25

Here's how to make a grid of boxes:

Let's say you want to write a function that looks for a DTM in an inventory slot, or want to hover over a skill. You need to know the x1,y1 x2,y2 of each box.

First off, we need a formula to get the x1,y1. From there, you can get the x2,y2 a couple of ways, more on that later.

x1:=Spot[1]X1+(((((i)+(Across-1))mod Across))*(Spot[2]X1-Spot[1]X1));
y1:=Spot[1]Y1+(((((i)-1)/Across))*(Spot[Across+1]Y1-Spot[1]Y1));

That's the formula for X1,Y1.

Spot[1] means the top left box. For example, with Skills, this is the Attack box. So Spot[1]X1 means the left side of the Attack box. To find this number, target SCAR on RS, move the mouse to the left of the Attack box, so that the uptext is not 'Attack', and slowly, one pixel at a time, move it right until the uptext does say 'Attack'. When it does, look at the X coord in SCAR. That's Spot[1]X1. Let's fill that in.

x1:=547+(((((i)+(Across-1))mod Across))*(Spot[2]X1-547));
y1:=Spot[1]Y1+(((((i)-1)/Across))*(Spot[Across+1]Y1-Spot[1]Y1));

Let's do the same except for the Y, finding the highest pixel where it says 'Attack'.

x1:=547+(((((i)+(Across-1))mod Across))*(Spot[2]X1-547));
y1:=207+(((((i)-1)/Across))*(Spot[Across+1]Y1-207));

Spot[2] is the box to the right of Spot[1]. In the Skills example, this is Hitpoints. So we find the very left most edge of the Hitpoints box, and fill that in for Spot[2]X1.

x1:=547+(((((i)+(Across-1))mod Across))*(611-547));
y1:=207+(((((i)-1)/Across))*(Spot[Across+1]Y1-207));
Across means how many boxes go across in a row. In this case, 3.

x1:=547+(((((i)+(3-1))mod 3))*(611-547));
y1:=207+(((((i)-1)/3))*(Spot[Across+1]Y1-207));

Spot[Across+1] means the box below the top left box. In this case, box 4, Strength. So Spot1[Across+1]Y1 is the top most edge of the Strength box.

x1:=547+(((((i)+(3-1))mod 3))*(611-547));
y1:=207+(((((i)-1)/3))*(238-207));
i is the box number, increasing from left to right, top to bottom.

You can combine the 3-1, 611-547, 238-207, if you want, but leaving it makes it easier to see what the numbers refer to, and it doesn't take a ms to compute.

To get the x2,y2, you get the x2,y2 of the first box. and put it in this formula.

x2:=x1+(Spot[1]X2-Spot[1]X1);
y2:=y1+(Spot[1]y2-Spot[1]y1);

Or you can do it this way:
MMouse(x1+random(63),y1+random(30),0,0);
Just do the formulas for x1,y2, and add a random of the height and width of the boxes. This way ensures clicking randomly within the box, regardless of how the mouse function deals with randomness (so leave the 0,0 on the end).

Tim0suprem0

2007-08-10 23:25:07

W00t first post! This is great! Thanks! I had to reread it a couple times hehe but I get it now.

lordsaturn

2007-08-11 00:53:24

Woah…confusing stuff. =P

Ruroken

2007-08-11 00:53:51

It has too much math for me to handle at 1am…(I got the general idea)

I'll get it tomorrow :)

But until then..Good job!

Boreas

2007-08-11 01:34:10

For the mathphobes, all you have to do is get 6 numbers from RS, and stick em in the formulas, and just trust it works :)

Ruroken

2007-08-12 20:54:27

i like math, not alot, but enough :)

I was just realllyyy tired :p

JuKKa

2007-08-14 12:05:23

From: Boreas
and just trust it works :)

You mean "Hope" :P?