Advanced Use Of TPAs:
- FindColorsTolerance
- FindColorsSpiralTolerance
- MiddleTPA
FindColorsTolerance:
- Now that you have all that basic knowledge under your belt, take a deep breath, stand up, stretch, and get ready to learn how you can really put this stuff to use. If at this point you do not know basic color finding, please go look at some other tutorials in the basic section. Glad to have covered that minor detail, moving on… The first function we will take a look at is FindColorsTolerance. This is not the same as FindColorTolerance. The difference is that it is Colors with an s on the end because we will be finding all locations of said color within a certain tolerance. To the extent of my knowledge, there is no FindColors function to compete with FindColor, mainly because you could always set the tolerance to 0.
SCAR Code:
function FindColorsTolerance(var Points: TPointArray; Color, xs, ys, xe, ye, Tolerance: Integer): Boolean;
- Here is a little explanation:
var Points: TPointArray – the TPA where the function will store all the points it finds within the color’s tolerance.
Color: Integer – the color that the function will look for
xs, ys, xe, ye: Integer – The coordinates of the box in which the function will look. (xs, ys) should be the upper left-hand corner and (xe, ye) should be the coordinates of the lower right-hand corner. Oftentimes people use built in coordinates such as MSx1, MSy1, MSx2, MSy2 (the main screen coordinates), MMx1, MMy2, MMx2, MMy2 (the mini map coordinates), MCx1, MCy2, MCx1, MCy2 (the main chat box coordinates), or MIx1, MIy1, MIx2, MIy2 (the main inventory coordinates).
Tolerance: Integer - Value can be from 0-255. How close the set color must be to the one the script finds.
FindColorsTolerance: Boolean – the function itself will return True if it finds any (one or more) occurences of the color or false if it does not find any occurences or has problems during its execution.
SCAR Code:
program TPATutorial;
{.include SRL/SRL.scar}
var
MyTPA : TPointArray;
MyPoint : TPoint;
x, y, i : Integer;
begin
FindColorsTolerance(MyTPA, 2961456, MSx1, MSy1, MSx2, MSy2, 10);
if Length(MyTPA) = 0 then FindColorsTolerance(MyTPA, 8160390, MSX1, MSY1, MSX2, MSY2, 10);
for i := 0 to High(MyTPA)do
begin
MyPoint := MyTPA[i]
MMouse (MyPoint.x, MyPoint.y, 3, 3);
if (IsUpTextMultiCustom(['tair', 'case'])) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, False);
ChooseOption('limb');
Wait(500+random(250));
Exit;
end;
Wait(350+random(350));
end;
end.
- Okay this make pretty complicated at first, but I will break it down, and you should be able to do this yourself very soon. This is a severely modified and cut down section from a script of mine and the colors are used to find the stairs in Lumbridge Castle (in case you care). The first thing I do, of course, is name the program and then include SRL. Then I declare variables, I usually have my TPointArray, a TPoint, and an integer for use in my for-to-do statement. I also have the variables x and y that I use in all scripts for clicking coordinates. I gave them simple names so it is easy to understand in the script. Now things get interesting.
SCAR Code:
FindColorsTolerance(MyTPA, 2961456, MSx1, MSy1, MSx2, MSy2, 10);
- This is where we are looking for the color 2961456 with a tolerance of 10. We are looking in the mainscreen (MSx1, MSy1, MSx2, MSy2). We are storing all the points we find in MyTPA.
SCAR Code:
if Length(MyTPA) = 0 then FindColorsTolerance(MyTPA, 8160390, MSX1, MSY1, MSX2, MSY2, 10);
- Here I add a little failsafe that I have use ever time I use TPAs and I usually do more than once. This is if the length of MyTPA is 0 after the first color search (meaning it did not find that color) it will try again with a different color. You could also do this with and if statement around the first FindColorsTolerance and if it is false use the next color, but I prefer this method because the next procedure we will talk about is, as I just mentioned, a procedure and not a function. Therefore, it does not return a value and cannot be used in an if statement. I use this method to maintain the same style and to make it simpler. Again, it does the same thing as before but with a different color, this time 8160390.
SCAR Code:
for i := 0 to High(MyTPA) do
- This line is perhaps the essence of using TPAs. What we do here is we run through every single point within our TPA (remember if our TPA has a length of 10, 0 would be the start, and 9 would be the end – which is returned by the function High). So we are able to look at any number of points simply with this easy line of code.
SCAR Code:
MyPoint := MyTPA[i]
MMouse (MyPoint.x, MyPoint.y, 3, 3);
- Here we take whichever point in the TPA we happen to be on, and we set it to our TPoint. We then move our mouse to the TPoint. (Note: we could also do this with MyTPA[i].x and MyTPAP[i].y, but this is how I learned it and how I always do it ).
SCAR Code:
if (IsUpTextMultiCustom(['tair', 'case'])) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, False);
ChooseOption('limb');
Wait(500+random(250));
Exit;
end;
- After we move our mouse to where we found the color, we check the uptext to see if it is what we wanted to find. In this case I am looking for the staircase in Lumbridge Castle. If I do find it, I click climb. I first use GetMousePos and then Mouse because you are moving with a bit of random to the point where the color is, but a real person doesn’t move with a tiny bit of random and then click that spot with a different tiny bit of random. GetMousePos allows me to move, check the uptext, and then right click in the exact same spot where my mouse is already. It is a method that keeps people from getting banned. Then I wait a little while and exit the loop so I don’t run through the other points in the TPA, after all, we already found what we wanted.
- This is outside of the if statement because we do not want the mouse to move, check the uptext, and then instantly move to the next point. If you do not have a wait then the mouse will go crazy and look like it is having a seizure across your screen because it is checking all the points in rapid succession. The wait allows the mouse to move at a speed and frequency that more closely simulates human movements.
FindColorsSpiralTolerance:
- FindColorsSpiralTolerance is like FindColorSpiralTolerance much the same way as the previous function. Again make sure to have the s on Colors. The difference between FindColorsSpiralTolerance and FindColorsTolerance is that while FindColorsTolerance begins searching from the upper left corner of the box you specify and goes to the bottom right, FindColorsSpiralTolernace starts the search from coordinates that you specify (Most people start the search from the center of the screen). It then proceeds to spiral outward in its search for the color. This allows the colors closest to the starting point to be earlier in your TPA, and therefore checked first when going through our for-to-do statement.
- FindColorsSpiralTolerance is used almost 100% of the time over FindColorsTolerance because it keeps you from accidently clicking strange colors on the edge of your screen and it makes it easier to find objects closer to your character, which is generally the point.
SCAR Code:
procedure FindColorsSpiralTolerance(x, y: Integer; var Points: TPointArray; color, xs, ys, xe, ye: Integer; Tolerance: Integer);
- Here is an explanation, I will copy the duplicate stuff from above so you do not have to scroll up and down so much:
x, y: Integer – the coordinates for the starting point of the search. Oftentimes people use built in coordinates such as MSCx and MSCy (main screen center coordinates) or MMCx and MMCy (mini map center coordinates).
var Points: TPointArray – the TPA where the function will store all the points it finds within the color’s tolerance.
Color: Integer – the color that the function will look for
xs, ys, xe, ye: Integer – The coordinates of the box in which the function will look. (xs, ys) should be the upper left-hand corner and (xe, ye) should be the coordinates of the lower right-hand corner. Oftentimes people use built in coordinates such as MSx1, MSy1, MSx2, MSy2 (the main screen coordinates), MMx1, MMy2, MMx2, MMy2 (the mini map coordinates), MCx1, MCy2, MCx1, MCy2 (the main chat box coordinates), or MIx1, MIy1, MIx2, MIy2 (the main inventory coordinates).
Tolerance: Integer - Value can be from 0-255. How close the set color must be to the one the script finds.
Note: This is a procedure and it isnot a function. This means that it will not return True if it finds the color. Hence, why I showed you that “if Length(MyTPA) = 0” trick.
SCAR Code:
program TPATutorial;
{.include SRL/SRL.scar}
var
MyTPA : TPointArray;
MyPoint : TPoint;
x, y, i : Integer;
begin
x := MSCx;
y := MSCy;
FindColorsSpiralTolerance(x, y, MyTPA, 2961456, MSx1, MSy1, MSx2, MSy2, 10);
if Length(MyTPA) = 0 then FindColorsSpiralTolerance(x, y, MyTPA, 8160390, MSX1, MSY1, MSX2, MSY2, 10);
for i := 0 to High(MyTPA) do
begin
MyPoint := MyTPA[i]
MMouse (MyPoint.x, MyPoint.y, 3, 3);
if (IsUpTextMultiCustom(['tair', 'case'])) then
begin
GetMousePos(x, y);
Mouse(x, y, 0, 0, False);
ChooseOption('limb');
Wait(500+random(250));
Exit;
end;
Wait(350+random(350));
end;
end.
- I am going to attempt to keep this explanation marginally shorter by not re-explaining the parts that I went over before. Here is the new stuff:
- Okay, as I stated before, x and y are where we begin the search. These two lines set them equal to built in coordinates for the center of the mainscreen. So now our search shall begin at the exact center of the main screen.
SCAR Code:
FindColorsSpiralTolerance(x, y, MyTPA, 2961456, MSx1, MSy1, MSx2, MSy2, 10);
if Length(MyTPA) = 0 then FindColorsSpiralTolerance(x, y, MyTPA, 8160390, MSX1, MSY1, MSX2, MSY2, 10);
- Here I changed FindColorsTolerance to FindColorsSpiralTolerance and added the parameters x and y. That’s it.
MiddleTPA:
- The function MiddleTPA is used to find the center of all of your points. Do not get confused here. This function does not take the middle point of your TPA. If you have a TPA with index 0 to 2, it does not return the point at index 1. What this function does do, is it takes all the points in your TPA, and finds the center of them. For example, if you have a square and four TPoints in your TPA, one for each corner, MiddleTPA will find the center of the square.
SCAR Code:
function MiddleTPA(tpa: TPointArray): TPoint;
- tpa is the TPointArray that you want the middle of and it will return it as a TPoint.
SCAR Code:
program TPATutorial;
{.include SRL/SRL.scar}
var
MyTPA : TPointArray;
MyTPoint : TPoint;
begin
SetLength(MyTPA, 4);
MyTPA[0] := inttopoint(0, 0);
MyTPA[1] := inttopoint(0, 10);
MyTPA[2] := inttopoint(10, 0);
MyTPA[3] := inttopoint(10, 10);
MyTPoint := MiddleTPA(MyTPA);
Writeln(inttostr(MyTPoint.x));
Writeln(inttostr(MyTPoint.y));
end.
Okay here is my attempt at an example so that if you didn’t understand it before, you do now. We have a TPA of length 4 (index 0 to 3). I made a little picture with where each of these points goes on our square. The x is the point that MiddleTPA would give you and should have the coordinates (5, 5) from the example.