Infantry001
03-25-2007, 09:16 PM
Fun with TPoints, TBoxes, and More!
So, im guessing you came here knowing nothing about tpoints? Well, today im here to teach you about TPoints, TPointArrays, TBoxes, and TBoxArrays. Make sure you understand the basics of SCAR before attempting this tutorial.
First off, open up scar.
Set these global variables:
var
i : integer;
MyTpoint : tpoint;
MyTpointArray : TPointArray;
MyTBox : tbox;
MyTBoxArray : TBoxArray;
And include SRL (you need this for TBox).
Alright, now let me describe each variable type.
TPoint - Used to store an x and y coordinate within one variable. Lets say you are using MyTpoint as your tpoint. The "x" coordinate would be MyTpoint.x, and the "y" coordinate would be MyTpoint.y.
TPointArray - Store multiple TPoints within an array. Using the first TPoint would be, say, MyTPointArray[0].x and MyTPointArray[0].y. Don't forget to set the array length!
TBox - Pretty much the same as TPoint, except uses x1,y1,x2, and y2 as arguments. x1,y1 would be the top left corner of the box made, and x2,y2 would be bottom right corner.
TBoxArray - Stores multiple TBoxes in an array.
To use these, lets start off with a midpoint function:
TPoint
//Fx,fy - first coords
//sx,sy - second coords
function Midpoint(fx,fy,sx,sy : integer) : tpoint;
begin
result.x := Round((fx + sx) / 2);
result.y := Round((fy + sy) / 2);
end;
Now, try this in your main loop:
begin
SetupSRL;
MyTPoint := MidPoint(0,0,500,500);
MMouse(MyTPoint.x,MyTPoint.y,0,0);
end.
As you can see, midpoint will result in a TPoint, and MyTPoint is set as the MidPoint of 0,0 and 500,500. Run the script and watch the mouse move to 250,250.
Next, lets look at a TPoint Array!
TPointArray
Now, you should know a bit about arrays, but if not, let me take a small detour...
Arrays are a way of making one variable have many different values. Each value of the array is shown by the
number. The format is this: Array[0]. Say you want array to hold 3 different colors. First, you would need to
set the array length (setarraylength(Array,3)). This would result in an array of 0-2, not 1-3. Then, do this:
Array[0] := 0;
Array[1] := 65336;
Array[2] := 1667438;
Then, you could find the color Array[0] by FindColor(x,y,Array[0],MSX1,MSY1,MSX2,MSY2). This has been a quick
detour on arrays.
Within the same script, add this procedure:
procedure SetMidpointArray;
var i : integer;
begin
setarraylength(MyTPointArray,4);
for i := 0 to 3 do
MyTPointArray := MidPoint(0,0,i * 100,i * 100);
end;
This will set each TPoint to a midpoint using a for..to..do statement. If you do not understand, check out some
other tutorials!
Now, add to your main loop:
SetMidpointArray;
for i := 0 to 3 do
MMouse(MyTPointArray[i].x,MyTPointArray[i].y,0,0);
This will set the midpoint array, and then move the mouse to each midpoint!
TBox
Time to move onto TBoxes!
So, TBoxes are pretty much a set of 2 TPoints, with the parameters being x1,y1,x2, and y2. They are useful for many things, but TBoxArrays are mor commonly used.
Lets say you want to look for a color around a certain point. First, you would use FindColor, right? From there, what do you do? That's right! Make a TBox.
Put this into scar:
function FindColorInBox(x,y,color : integer) : boolean;
begin
MyTBox.x1 := x - 30;
MyTBox.y1 := y - 30;
MyTBox.x2 := x + 30;
MyTBox.y2 := y + 30;
if FindColor(x,y,color,MyTBox.x1,MyTBox.y1,MyTBox.x2, MyTBox.y2) then
result := true;
end;
First off, this creates a box around the x,y coordinate that is 30 pixels by 30 pixels. Then, if it finds "color" inside that box, it will result true. Used in conjunction with FindColorSkipBox, you can do some cool things.
function FindDifferentColor : boolean;
begin
if FindColor(x,y,9724949,MSX1,MSY1,MSX2,MSY2) then
if FindColorInBox(x,y,65366) then
if FindColorSkipBox(x,y,65366,MSX1,MSY1,MSX2,MSY2,MyT Box) then
result := true;
end;
Combining this procedure with the last one, check out what it does. If it finds the color 9724949, then it looks in a box around that for the color 65366. If it is found, then FindColorSkipBox will look for the color 65366
again, but without looking into MyTBox. Using this concept, you could determine whether an object is what you are looking for, or just something with a similar color.
For example, maybe a script wants to mine a rock but someone has an ores. It could use FindDIfferentColor, except it substitutes the first FindColor with the rock color, the second with the outer
parts of the ore, and the last one with the rock color. If it finds the rock color (which could either be the actual rock, or an ore) it looks in a TBox around the color to see if it finds the color that makes it an
ore. If it does, it will look again for the rock color, but skipping the box it found the dropped ore in! Useful, huh?
And... this leads me into TBoxArrays!
TBoxArrays
If you haven't read the last section, READ IT! Only then will you understand this part.
Lets say there is more than one ore dropped, and it is in many different locations. Now what? We can make the script skip every location the dropped ores are in.
We are basically using the same function as before, except looped and modified a bit.
function FindAllBoxes : boolean;
var
a : integer;
begin
SetArrayLength(MyTBoxArray,0)
repeat
if FindColorSkipBoxArray(x,y,RockColor,MSX1,MSY1,MSX2 ,MSY2,MyTBoxArray) then
begin
if FindColorInBox(x,y,OreColor) then
begin
SetArrayLength(MyTBoxArray,a + 1)
MyTBoxArray[a].x1 := MyTBox.x1;
MyTBoxArray[a].y1 := MyTBox.y1;
MyTBoxArray[a].x2 := MyTBox.x2;
MyTBoxArray[a].y2 := MyTBox.y2;
a := a + 1;
end else
break;
end;
until(false)
if FindColorSkipBoxArray(x,y,RockColor,MSX1,MSY1,MSX2 ,MSY2,MyTBoxArray) then
begin
MMouse(x,y,3,3);
Writeln('This should be our rock!');
end;
end;
So...let's go over this step by step.
First of all, we must Set our arraylength so we dont get a runtime error.
Second, We have FindColorSkipBoxArray to look for a color everywhere in the mainscreen except the TBoxes we told it to skip. We need TBoxArray to make it look for other instances of the color outside the ore. If we just put
FindColorSkipBox, We would constantly find the same 2 boxes.
Third, the FindColor is there to see if the orecolor if found. If it isnt, then we know our boxes are all made, therefore, we break from the loop.
Fourth, we find the middle of the function. You must add 1 to the arraylength if we are going to add a box to skip. Next, we declare the points of the tboxarray as the points we found our color inside of. Then, we add 1 so
the array increases next time we find the ore color. (and normally, that repeat loop would have a failsafe, but for demonstration purposes, i wont add one.
Finally, We look at the whole screen, skipping the boxes where the orecolor was found. We move our mouse there, and TADA! Our rock should be right under!
This is just one method of applying a TBoxArray. You can use them for looking for items in the inventory, in the bank, and on the floor. There are tons of uses for TBoxArrays!
So in conclusion, thank you for reading this tutorial. I appreciate the time you have spent. And make me happy by leaving a comment on this tut! Feel free to correct it or offer suggestions.
:D[i]Infantry001
So, im guessing you came here knowing nothing about tpoints? Well, today im here to teach you about TPoints, TPointArrays, TBoxes, and TBoxArrays. Make sure you understand the basics of SCAR before attempting this tutorial.
First off, open up scar.
Set these global variables:
var
i : integer;
MyTpoint : tpoint;
MyTpointArray : TPointArray;
MyTBox : tbox;
MyTBoxArray : TBoxArray;
And include SRL (you need this for TBox).
Alright, now let me describe each variable type.
TPoint - Used to store an x and y coordinate within one variable. Lets say you are using MyTpoint as your tpoint. The "x" coordinate would be MyTpoint.x, and the "y" coordinate would be MyTpoint.y.
TPointArray - Store multiple TPoints within an array. Using the first TPoint would be, say, MyTPointArray[0].x and MyTPointArray[0].y. Don't forget to set the array length!
TBox - Pretty much the same as TPoint, except uses x1,y1,x2, and y2 as arguments. x1,y1 would be the top left corner of the box made, and x2,y2 would be bottom right corner.
TBoxArray - Stores multiple TBoxes in an array.
To use these, lets start off with a midpoint function:
TPoint
//Fx,fy - first coords
//sx,sy - second coords
function Midpoint(fx,fy,sx,sy : integer) : tpoint;
begin
result.x := Round((fx + sx) / 2);
result.y := Round((fy + sy) / 2);
end;
Now, try this in your main loop:
begin
SetupSRL;
MyTPoint := MidPoint(0,0,500,500);
MMouse(MyTPoint.x,MyTPoint.y,0,0);
end.
As you can see, midpoint will result in a TPoint, and MyTPoint is set as the MidPoint of 0,0 and 500,500. Run the script and watch the mouse move to 250,250.
Next, lets look at a TPoint Array!
TPointArray
Now, you should know a bit about arrays, but if not, let me take a small detour...
Arrays are a way of making one variable have many different values. Each value of the array is shown by the
number. The format is this: Array[0]. Say you want array to hold 3 different colors. First, you would need to
set the array length (setarraylength(Array,3)). This would result in an array of 0-2, not 1-3. Then, do this:
Array[0] := 0;
Array[1] := 65336;
Array[2] := 1667438;
Then, you could find the color Array[0] by FindColor(x,y,Array[0],MSX1,MSY1,MSX2,MSY2). This has been a quick
detour on arrays.
Within the same script, add this procedure:
procedure SetMidpointArray;
var i : integer;
begin
setarraylength(MyTPointArray,4);
for i := 0 to 3 do
MyTPointArray := MidPoint(0,0,i * 100,i * 100);
end;
This will set each TPoint to a midpoint using a for..to..do statement. If you do not understand, check out some
other tutorials!
Now, add to your main loop:
SetMidpointArray;
for i := 0 to 3 do
MMouse(MyTPointArray[i].x,MyTPointArray[i].y,0,0);
This will set the midpoint array, and then move the mouse to each midpoint!
TBox
Time to move onto TBoxes!
So, TBoxes are pretty much a set of 2 TPoints, with the parameters being x1,y1,x2, and y2. They are useful for many things, but TBoxArrays are mor commonly used.
Lets say you want to look for a color around a certain point. First, you would use FindColor, right? From there, what do you do? That's right! Make a TBox.
Put this into scar:
function FindColorInBox(x,y,color : integer) : boolean;
begin
MyTBox.x1 := x - 30;
MyTBox.y1 := y - 30;
MyTBox.x2 := x + 30;
MyTBox.y2 := y + 30;
if FindColor(x,y,color,MyTBox.x1,MyTBox.y1,MyTBox.x2, MyTBox.y2) then
result := true;
end;
First off, this creates a box around the x,y coordinate that is 30 pixels by 30 pixels. Then, if it finds "color" inside that box, it will result true. Used in conjunction with FindColorSkipBox, you can do some cool things.
function FindDifferentColor : boolean;
begin
if FindColor(x,y,9724949,MSX1,MSY1,MSX2,MSY2) then
if FindColorInBox(x,y,65366) then
if FindColorSkipBox(x,y,65366,MSX1,MSY1,MSX2,MSY2,MyT Box) then
result := true;
end;
Combining this procedure with the last one, check out what it does. If it finds the color 9724949, then it looks in a box around that for the color 65366. If it is found, then FindColorSkipBox will look for the color 65366
again, but without looking into MyTBox. Using this concept, you could determine whether an object is what you are looking for, or just something with a similar color.
For example, maybe a script wants to mine a rock but someone has an ores. It could use FindDIfferentColor, except it substitutes the first FindColor with the rock color, the second with the outer
parts of the ore, and the last one with the rock color. If it finds the rock color (which could either be the actual rock, or an ore) it looks in a TBox around the color to see if it finds the color that makes it an
ore. If it does, it will look again for the rock color, but skipping the box it found the dropped ore in! Useful, huh?
And... this leads me into TBoxArrays!
TBoxArrays
If you haven't read the last section, READ IT! Only then will you understand this part.
Lets say there is more than one ore dropped, and it is in many different locations. Now what? We can make the script skip every location the dropped ores are in.
We are basically using the same function as before, except looped and modified a bit.
function FindAllBoxes : boolean;
var
a : integer;
begin
SetArrayLength(MyTBoxArray,0)
repeat
if FindColorSkipBoxArray(x,y,RockColor,MSX1,MSY1,MSX2 ,MSY2,MyTBoxArray) then
begin
if FindColorInBox(x,y,OreColor) then
begin
SetArrayLength(MyTBoxArray,a + 1)
MyTBoxArray[a].x1 := MyTBox.x1;
MyTBoxArray[a].y1 := MyTBox.y1;
MyTBoxArray[a].x2 := MyTBox.x2;
MyTBoxArray[a].y2 := MyTBox.y2;
a := a + 1;
end else
break;
end;
until(false)
if FindColorSkipBoxArray(x,y,RockColor,MSX1,MSY1,MSX2 ,MSY2,MyTBoxArray) then
begin
MMouse(x,y,3,3);
Writeln('This should be our rock!');
end;
end;
So...let's go over this step by step.
First of all, we must Set our arraylength so we dont get a runtime error.
Second, We have FindColorSkipBoxArray to look for a color everywhere in the mainscreen except the TBoxes we told it to skip. We need TBoxArray to make it look for other instances of the color outside the ore. If we just put
FindColorSkipBox, We would constantly find the same 2 boxes.
Third, the FindColor is there to see if the orecolor if found. If it isnt, then we know our boxes are all made, therefore, we break from the loop.
Fourth, we find the middle of the function. You must add 1 to the arraylength if we are going to add a box to skip. Next, we declare the points of the tboxarray as the points we found our color inside of. Then, we add 1 so
the array increases next time we find the ore color. (and normally, that repeat loop would have a failsafe, but for demonstration purposes, i wont add one.
Finally, We look at the whole screen, skipping the boxes where the orecolor was found. We move our mouse there, and TADA! Our rock should be right under!
This is just one method of applying a TBoxArray. You can use them for looking for items in the inventory, in the bank, and on the floor. There are tons of uses for TBoxArrays!
So in conclusion, thank you for reading this tutorial. I appreciate the time you have spent. And make me happy by leaving a comment on this tut! Feel free to correct it or offer suggestions.
:D[i]Infantry001