SRL Archive - OSR Help

TBox


P1ng

2012-05-07 18:20:13

I've checked through the tutorials section and haven't found a great deal written on how to define a TBox or really use it..

Would anyone please be able to explain how or whether it can be defined with a DTM or even just a set of colors?

Essentially, I'd like to use it for when my script either finds and item or a spell to create a box around it and save that position for later use (so my script remembers where to withdraw from or cast the spell from).

Also, is it possible to make it click in the centre of the TBox or anywhere within it's bounds?

If this is written somewhere in the tutorials, my apologies I wasn't able to find it myself.

Kyle Undefined

2012-05-07 19:40:25

To click in the center of the TBox, you can do:


Mouse((TBox.X1 + TBox.X2) / 2, (TBox.Y1, TBox.Y2) / 2, 0, 0, mouse_Left);

You can also set TBox's with the IntToBox method.

Abu

2012-05-07 19:45:19

procedure LetMeExplain
var
TpaOne: TPointArray;
OneBox: TBox;
begin
OneBox := IntToBox(238, 251, 312, 321); // the four co-ordinates of your box
TpaOne := TPAFromBox(OneBox); // turns box into TPA (kind of)
for i := 0 to High(TpaOne) do
begin
MiddleTPAEx(TpaOne, x, y); // gets the middle point
Mouse(x, y, 0, 0, True); // clicks the middle point
Break;
end;
end;

Awesome procedure no? :)

Cazax

2012-05-07 20:13:15

A TBox is basically a rectangle, with the X1, Y1, X2, Y2 coordinates:
X1,Y1+++++++
+—————-+
+—————-+
+—————-+
+—————-+
++++++++++X2,Y2

When you find a DTM you tell the function where to search for, using the two points (x1,y1 and x2,y2).
Finding the middle of the box is calculated like this:
xmiddle: (x1+x2)/2
ymiddle: (y1+y2)/2

P1ng

2012-05-08 00:54:59

Great! Thanks for the help, but with regards to using the DTM to set the TPoints of the TBox how would this work, given that functions like -
begin
if (FindDTM(HighAlch,x,y,MIX1,MIY1,MIX2,MIY2)) then
end;
Only return two values x and y..

should i perhaps use
IntToBox(x - 5, y - 5, x + 5, y + 5);

procedure LetMeAttempt;
var
MyTPA: TPointArray;
B: TBox;
M: TPoint;
begin
if (FindDTM(HighAlch,x,y,MIX1,MIY1,MIX2,MIY2)) then
begin
B := IntToBox(x-5, y-5, x+5, y+5);
MyTPA := TPAFromBox(B);
for i := 0 to High(MyTPA) do
begin
M:= MiddleTPA(MyTPA)
MMouse(M.x,M.y,0,0);
ClickMouse2(True);
Break;
end;
end;

bg5

2012-05-08 01:01:45

just



if (FindDTM(HighAlch,x,y,MIX1,MIY1,MIX2,MIY2)) then
begin
MMouse(x,y,0,0);
ClickMouse2(true);
endl
Basically you find DTM ,and coords of this DTM are assigned to x,y. You don't need to create TPoint to click on it. But if you really want you can convert it to TPOint this way:


var
P : TPoint;

if (FindDTM(HighAlch,x,y,MIX1,MIY1,MIX2,MIY2)) then
begin
P := Point(x,y);
MMouse(P.x,P.y,0,0);
ClickMouse2(true);
endl

Abu

2012-05-08 01:04:58

Yeh all you really need to do is what beginner said :p

Just ignore everything I wrote!



EDIT: As a side-note, FindDTMs will return TPA's

P1ng

2012-05-08 01:19:27

Was kind of just trying to find a way to click in the centre of the DTM rather than over to the side where it seems to be clicking quite regularly..

Along with trying to grasp a better understanding of both TBoxes and TPAs :)

Already had a similar method to beginner prior to this thread. But, never the less thank-you to everyone for all of your help.

bg5

2012-05-08 01:26:24

Was kind of just trying to find a way to click in the centre of the DTM

x,y are coords of Main(First) point of DTM. So if you want to click in the center ,then make DTM with first point on the center. For randomization you can make this one inbuilt in MMouse(x,y,Random_x,Random_y);

P1ng

2012-05-08 01:40:20

So when I make the DTM use a point close to the centre of it as the first point and the others outlying on the black line and it will click roughly in the centre?

Abu

2012-05-08 01:46:08

It will click wherever your first point is - because that is the is the x and y it will return.

P1ng

2012-05-08 01:51:33

Fantastic! Thanks heaps, I wasn't aware that where I chose the centre point when making a DTM was really relevant at all after it's creation.