I know all of you have heard of the ever powerful TPA (TPointArray) and T2DPointArray. Many of you who have heard of it think it is hard/confusing. Well i am here to iron out those confusing spots. I will help you better understand TPA's and T2DPointArrays, and be able to use them in object finding.
In reading this tutorial i assume you have already learned some of the basics of scar and srl.
TPoint
A point on a screen stored into a variable. Like a tpoint's value could have an
x value of 100 and a y value of 105. That would be a point on your screen.
You can also store coords to a TPoint.
SCAR Code:
TPoint:= inttopoint(100,105);
TPA (TPointArray)
- Short for TPointArray.
- In essence it is an array of TPoints. (see above)
- used in many ways including object finding.
T2DPointArray
- used to be called Array of TPointArray but thats changed.
- In essence it is an array of TPointArrays.
- used in certain functions to make life easier.
Functions for using TPA's
SCAR Code:
function FindColorsTolerance(var Points: TPointArray; Color, xs, ys, xe, ye, Tolerance: integer):boolean;
The function above ^^ is used in storing TPoints of a color to a TPointArray. This will aid you in object finding.
SCAR Code:
function MiddleTPA(tpa:TPointArray):TPoint
The function above ^^ takes the middle of a TPA and stores it to a TPoint. This helps when getting the middle of an object.
Now that you have learned the above functions, we will get to using TPA's in object finding.
Using TPA's for object finding
SCAR Code:
function FindRange:boolean;
var
i: integer;
Range: TPointArray;
R: TPoint;
begin
if not LoggedIn then exit;
FindColorsTolerance(Range,1319583,MSX1,MSY1,MSX2,MSY2,25);
if length(Range) = 0 then
begin
FindColorsTolerance(Range,593993,10,10,508,325,5);
end;
for i:= 0 to High(Range)do
begin
if FindNormalRandoms then
begin
ClickFood;
FindRange;
end;
if CookScreen then break;
R:= Range[i];
if FindColorTolerance(x,y,8160902,R.X-20,R.Y-20,R.X+20,R.Y+20,30)then
begin
MMouse(R.X,R.Y,4,4);
wait(75+random(25));
if (Pos('ange',rs_GetUpText) <> 0) then
begin
GetMousePos(x,y);
result:= True;
Mouse(x,y,0,0,true);
FFlag(0);
if FindNormalRandoms then
begin
ClickFood;
FindRange;
end;
wait(750+random(500));
Break;
exit;
end;
end;
end;
if not result then
begin
if ModFindObjCustom(x,y,['ange'],[1319583,8094852],15)then
begin
if (Pos('ange',rs_GetUpText) <> 0) then
begin
GetMousePos(x,y);
result:= True;
Mouse(x,y,0,0,true);
FFlag(0);
if FindNormalRandoms then
begin
ClickFood;
FindRange;
end;
wait(750+random(500));
exit;
end;
end;
end;
end;
I took this function out of a cooker i am making. The above function won't compile because you dont have my other functions needed for it to compile.
When you use FindColorsTolerance it stores all the points on the screen that have the color to a TPointArray, in this case being a TPA named Range.
Then you could use that TPA to get a single TPoint from it. Even though i don't use MiddleTPA in the function above, you could use it to get a TPoint for moving your mouse to. I chose to just make the mouse go to each point in the array - another approach.
Functions for advance object finding
SCAR Code:
function SplitTPA(arr:TPointArray; Dist:LongInt):T2DPointArray
The function above will split up a TPointArray into a T2DPointArray (an array of TPA's) and ea TPointArray inside will contain groups of points within a certain distance.
SCAR Code:
function TPAtoATPA(TPA:TPointArray; Dist:LongInt):T2DPointArray
note:
SplitTPA splits points into groups with a max distance between all the points in the array.
TPAtoATPA splits points into groups with a max distance based on the first point.
Like this:

SCAR Code:
function TPAtoATPAEx(TPA:TPointArray; w:LongInt; h:LongInt):T2DPointArray
The function above splits TPA's into a T2DPointArray with arrays of points groups of certain height and width inside it. So inside the T2DPointArray there will be groups of points with same height and width. Just like TPAtoATPA but height and width not distance.
Using TPA's and T2DPointArrays for object finding
SCAR Code:
function FindOres:boolean;
var
tx,ty,i: integer;
CoalPoints,MithPoints: TPointArray;
Mith2D,Coal2D: T2DPointArray;
MithrilPoint,CoalPoint: TPoint;
begin
if not LoggedIn then exit;
x:= MSCX;
y:= MSCY;
if (Players[CurrentPlayer].Strings[1] = 'both') then
begin
FindColorsSpiralTolerance(x,y,MithPoints,8871004,MSX1,MSY1,MSX2,MSY2,10);
Mith2D:= TPAtoATPAEx(MithPoints,30,30); // splits tpa into points with groups of certain height and width
for i:= 0 to length(Mith2D)-1 do
begin
if not LoggedIn then
begin
break;
end;
MithrilPoint:= MiddleTPA(Mith2D[i]); // takes the middle point of TPA
tx:= MithrilPoint.X;
ty:= MithrilPoint.Y;
MMouse(tx,ty,2,2);
wait(90+random(50));
if isuptext('ine')then
begin
GetMousePos(x,y);
OreColor:= GetColor(tx,ty);
MineMith:= true;
result:= true;
break;
exit;
end;
end;
end;
if Result then exit;
if (Players[CurrentPlayer].Strings[1] = 'coal')or(Players[CurrentPlayer].Strings[1] = 'both') then
begin
x:= MSCX;
y:= MSCY;
FindColorsSpiralTolerance(x,y,CoalPoints,2966082,MSX1,MSY1,MSX2,MSY2,10);
Coal2D:= TPAtoATPAEx(CoalPoints,30,30);
for i:= 0 to length(Coal2D)-1 do
begin
if not LoggedIn then
begin
break;
end;
CoalPoint:= MiddleTPA(Coal2D[i]); // takes the middle point of TPA
tx:= CoalPoint.X;
ty:= CoalPoint.Y;
MMouse(tx,ty,2,2);
wait(90+random(50));
if isuptext('ine')then
begin
GetMousePos(x,y);
OreColor:= GetColor(tx,ty);
MineCoal:= true;
result:= true;
break;
exit;
end;
end;
end;
end;
I took this function from my guild miner. It uses advanced techniques with TPA's to find rocks in the guild. This function works flawlessly. You can use all the functions in this tutorial to create a flawless object finder like this. Turning on code hints when using TPA's will help you better understand them too.
Conclusion
Thanks for reading my tutorial about TPA's and object finding. You are welcome to use my functions as long as you properly credit.
If i have forgotten anything please tell me.
I hope you have enjoyed my kinda lengthy tutorial.