How To Pick Proper Colors to Find Certain Objects Using TPAs
**Note this requires some fundamental knowledge of TPAs and some knowledge of the WizzyPlugin functions!
This tutorial might not be extremely necessary, but it helps for those new to TPAs and how to exactly pick colors when finding certain objects.
Introduction
Have you ever wondered how to find a certain object when there is just a butt load of that same color? This tutorial will give you some advice on how to accomplish just that
.
Say for example that we are trying to find the spinning wheel in the Lumbridge Castle (boxed "red" in the picture below) based on the color 3293519, which is brown. You decide that since the wheel has the most of that color it would be the most likely option, right?
WRONG! Take a look at this screenshot. The places marked in blue are areas in which that color recurs.

Poory boxed but conveys the message
.
Color Counting Helper
Before we continue however to find out how many recurring instances of the color found use this procedure to find the length of the TPA.
SCAR Code:
program New;
const
Color = {color};
Tolerance = {tolerance};
procedure ColorCounter;
Var TPA: TPointArray;
begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Color, MSX1, MSY1, MSX2, MSY2, Tolerance);
Writeln('Length of TPA is ' +inttostr(length(TPA)));
end;
begin
ColorCounter;
end.
This is a basic procedure that will count the TPA number. This is handy to see if you really need to spiral from a certain location.
Finding Colors with FindColorsSpiralToleracne
Anyway back to our major dilema
So how do we find that bloody spinning wheel then?
That's why we have this function here.
SCAR Code:
FindColorsSpiralTolerance(x, y: Integer; var Points: TPointArray; color, xs, ys, xe: Integer; Tolerance: Integer);
The key part in here is the "x and y". This denotes where to starts searching for TPoints to add your TPointArray spirally outward. You guys might have seen that people often use MSCX and MSCY for these points, which in essense starts searching for points with the denoted colors from the middle of the main screen (MSC = Main Screen Center btw
).
Finding Colors with FindColorsSpiralTolerance with a Fixed TPoint
Look back at the picture shown above and you might notice that when you spiral from the center there are still four different objects that have added to your TPA! (the god damn chair, door, the chest, and the spinning wheel)
Luckily we have another solution. It's this procedure...
SCAR Code:
SortTPAFrom(var a: TPointArray; From: TPoint);
This function organizes a TPA from that TPoint. From here we could define a TPoint CLOSER to the wheel so we can have an easier time finding the wheel.
So now we have to specify that certain point, but this point has to be EASILY distinguished from other color points because if the color recurs like the previous recurring point we'll be back at stage one lol.
Look back at the picture and notice the blue curtains (marked by magenta box) that happen to be right next to the wheel, thankfully. Since the color of the curtain, (7355682, is the only color of its kind on the screen it works as a perfect starting point.
Example....
[
SCAR Code:
if FindColorTolerance(x, y, 7355682, MSX1, MSY1, MSX2, MSY2, 10) then
FindColorsSpiralTolerance(x, y, TPA, 3293519, MSX1, MSY1, MSX2, MSY2, 10);
From here you can loop through your points (your wheel points should be first) using uptext or w/e to find the wheel.
Of course you could format this any way you want,even by using another TPA to find the curtain colors or something.
Here is another example.

Look at this closed door. This has many parts that share the same color with a lot of things, but if you look carefully you'll see that the door KNOB doesn't have the same color as any of the others. After running the TPA counter I found that the color had a TPA length of 4 - 13 on the entire screen!
THis is an example of a very good choice for picking colors. And is also handy for making sure the door was closed or opened.
The same colors still apply when the door is opened too from the same angle!

After running the Door TPA counter the range was from 2 - 10!
In summation by picking colors that are unique to the main screen you'll have less work to do and ultimately more accuracy
Limiting the Size of a TPA Using T2DPointArrays
Credit to EvilChicken! for giving me this idea 
For this example look back at the picture above. Notice a small white cloth at the tip of the wheel? After you see this you'll probably be tempted to choose a point point from here with good reason of course, BUT notice was directly diagonal to the white cloth.... A FREAKIN HUGE ASS WHITE BED. So what do we do? Luckily we have 3 different TPA separating functions.
SCAR Code:
SplitTPA(arr: TPointArray; Dist: LongInt): T2DPointArray;
//Splits the TPA by distance
TPAtoATPA(TPA: TPointArray; Dist: LongInt): T2DPointArray;
//Also splits the TPA by distance but in a different manner
TPAtoATPAEx(TPA: TPointArray;w, h: LongInt): T2DPointArray;
//Splits the TPA by height and width. Therefore the range of each TPA will be organized into a box shape rather than a circular shape like TPAtoaTPA and SPlitTPA. Helpful to find "box-shape" colored areas.
Once you split the points of the color white, 14737636, you should end up with many different TPAs (the number depending on the parameters you specified). Now it would be wise to get the Middle TPoint of each and loop through the tpas like that. For example.
SCAR Code:
FindColorsSpiralTolerance(x, y, TPA, 14737636, MSX1, MSY1, MSX2, MSY2, 10);
if not length(TPA) > 0 then Exit;
TTPA :=SplitTPA(TPA, 10); //The exact distance encompassed by the points idk.
//TTPA := TPAtoaTPA(TPA, 10);
//TTPA := TPAtoaTPAEx(TPA, 6, 10); parameters should be close
for i := 0 to High(TTPA) - 1 do
begin
MiddleTPAEx(TTPA[i], x, y);
MMouse(x, y, 2, 2);
Wait(randomrange(400, 800));
if IsUpText('heel')then
begin
Mouse(x, y, 0, 0, true);
Exit;
end;
end;
You can take this a step further and try to find a range for the amount of colors should be found in each TPA, which would provide for a more accurate result.
Combining Colors into a TPAs and Using T2DPointArrays
This is my most favorite way of finding and picking particular colors for TPAs because its really accurate
. This involves using this function.
SCAR Code:
CombineTPA(TPA: TPointarray; TPA2: TPointArray): TPointarray;
This procedure combines two TPointArrays into one single TPointArray;
Why would you want to use this? Because you can add DIFFERENT colors into one TPointArray thats why! Say for example you have the wheel and on the wheel there are 2 predominant colors (13355985, 14408671) and you want to find a high concentration of those colors, which would most likely contain the wheel.
SCAR Code:
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 13355985, MSX1, MSY1, MSX2, MSY2, 10);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 14408671, MSX1, MSY1, MSX2, MSY2, 10);
CTPA := CombineTPA(TPA, TPA2);
CTTPA := TPAtoaTPAEx(CTPA, 15, 15);
for i := 0 to High(CTTPA)do
begin
MiddleTPAEx(CTTPA[i], x, y);
MMouse(x, y, 1,1);
Wait(RandomRange(400, 800));
if IsUpText('heel')then
begin
Mouse(x, y, 0, 0 , true);
Exit;
end;
end;
The first three function are rather extraneous since you could just do FindColorsSpiralTolerance with the same TPA without choosing another and combining it, but I used this function to portray a more simplistic circumstance. There will be times when you actually need different TPAs and then have to combine them. Also, I created this function that comines the TPAs for you using AS MANY colors as you want in a TIntegerArray.
SCAR Code:
function AddTPAS(XX, YY: Integer; Var TPA: TPointArray; Colors: TIntegerArray; Tol, X1, Y1, X2, Y2: Integer): Boolean;
Var v: Integer;
Var TPAS: Array of TPointArray;
Var CT: Integer;
begin
Result := False;
if Length(Colors) < 0 then Exit;
SetArrayLength(TPAS, Length(Colors));
CT := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
for v := 0 to Length(Colors) -1 do
FindColorsSpiralTolerance(XX, YY, TPAS[v], Colors[v], X1, Y1, X2, Y2, Tol);
ColorToleranceSpeed(CT);
TPA := CombineTPA(TPAS[0], TPAS[1]);
if Length(Colors) = 2 then
begin
Result := True;
Exit;
end;
for v := 2 to High(TPAS) - 1 do
TPA := CombineTPA(TPA, TPAS[v]);
if Length(TPA) = 0 then Exit;
Result := True;
end;
You guys can use this if you decide to use the TPA combination method. It will make the job much easier.

Rep + and Rate the thread!