TPointArrays
In this tutorial, I will teach you how to use TPAs - TPointArrays a.k.a Arrays of TPoint.
Lets start from how to declare a TPointArray.
How to declare a TPoint array
1. Most cool looking and the fastest to type
SCAR Code:TPA: TPointArray;
2. The "old" waySCAR Code:TPA: Array of TPoint;
With the way 2 you can declare the length of the array when declaring.
Now, you may think that TPointArrays are more complex or harder than other arrays, but thats just figment of your imagination.
Now, lets have a small example:
SCAR Code:Procedure TPAExample;
Var
TPA: TPointArray;
Begin
SetArrayLength(TPA, 1);
// Remember that SetArrayLength sets it so that first slot is 0!
TPA[0].x := 10;
TPA[0].y := 5;
Writeln('1.');
Writeln('TPA[0].x = '+IntToStr(TPA[0].x)+'.');
Writeln('TPA[0].y = '+IntToStr(TPA[0].y)+'.');
// Now, another way for setting a point in a TPA
TPA[0] := IntToPoint(10, 5);
Writeln('TPA[0].x = '+IntToStr(TPA[0].x)+'.');
Writeln('TPA[0].y = '+IntToStr(TPA[0].y)+'.');
End;
There you have a TPointArray with one slot, and two ways of setting the point.
Now, you all wonder how to surf through a TPA with your mouse?
Nothing more special than writelning an integer array.
SCAR Code:Procedure TPAMouseExample;
Var
TPA: TPointArray;
I, C: Integer;
Begin
SetArrayLength(TPA, 10);
For I := 0 To High(TPA) Do // High = highest slot
Begin
TPA[i].x := (i + 1) * 10;
TPA[i].y := (i + 1) * 20;
End;
// Now, we go through with it using mouse, watch...
For C := 0 To High(TPA) Do
Begin
MoveMouse(TPA[c].x, TPA[c].y);
Wait(250);
End;
End;
Always remember that a point is two integers, X and Y.
Now, you all think "Omfgz0r m003vfmouse d00z not fawnd me objz0r"
FindColorsSpiralTolerance & FindColorsTolerance
The difference between these two wonderful functions is that FindColorsSpiralTolerance searches starting from the two first params, spiralling out.
FindColorsTolerance instead just Finds from X1, Y1 to X2, Y2.
Try messing with this:
SCAR Code:Procedure TPAColorExample(StartX, StartY, Color, x1, y1, x2, y2: Integer);
Var
TPA: TPointArray;
I: Integer;
Begin
FindColorsSpiralTolerance(StartX, StartY, TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now, we go through the points found by FindColorsSpiralTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
FindColorsTolerance(TPA, Color, x1, y1, x2, y2, 0);
Writeln('Now we go through the points from FindColorsTolerance');
For I := 0 To High(TPA) Do
Begin
MoveMouse(TPA[i].x, TPA[i].y);
Wait(100);
End;
End;
I gotta stop for today, but don't worry, I'll be back writing this Tut after about 19 hours
Cya, hope you learnt something though this session wasn't very long!
-----CONTINUES-----
So, now you know a little, you should be able to make a TPointArray, and do something with the points
Multidimensional TPointArrays
Sometimes you may face this feeling that one array just isn't enough, and its
a) Stupid
b) Waste of time
to write like "A1, A2, A3, A4, A5, A6: TPointArray".
Then, just like any other array, you can make a multidimensional array.
For example, you want to find the player pixels of minimap.
You would first do a FindColors with spiral or not to get all the white points.
But now, you have a messy array with points around, you can use that to get the points of the players To get the amount of players you can do just like
SCAR Code:Players := Round(GetArrayLength(whitePoints) / 9)
Note that the 9 propably isn't the right amount one dot has pixels.
Now, back on topic, now you would want to get the dots.
What do you think you are going to do?
You would (should, IMO) use SplitTPA from WizzyPlugin, or a function of your own that serves the same purpose.
SplitTPA creates a two dimensional array -of one TPointArray, making a TPointArray of each group of points that are next to each other.SCAR Code:Array of TPointArray
Now you would do something like:
There you've got your player dots.SCAR Code:PlayerDots := SplitTPA(whitePoints);
But, you can't click a TPointArray, or can you?
Well its kind of how you like to say it, you can click the TPointArray's middle, or the point in middle of the array, or something else.
Well the first option makes most sence, so, you will then have a for loop, and a new TPointArray.
Then you do something like this:
SCAR Code:For I := 0 To High(PlayerDots) Do
Try
TheRealDamnPlayerDots[i] := MiddleTPA(PlayerDots[i]);
Except
Writeln('Seems like we had shitty points.');
End;
The try except is because if some array had too low amount of points, our story would end sadly in a runtime error.
I made today early one function for checking the amount of players so the brand new autotalker in my script won't be chatting with JaGeX.
Try to learn something of it :
SCAR Code:Function GetPlayers: Integer;
Var
PlayerDots: Array of TPointArray;
WhitePixels: TPointArray;
CTS, X, Y, I: Integer;
Begin
CTS := GetColorToleranceSpeed;
If Not CTS = 2 Then ColorToleranceSpeed(2);
FindColorsTolerance(WhitePixels, 16711422, MMX1, MMY1, MMX2, MMY2, 3);
PlayerDots := SplitTPA(WhitePixels);
For I := 0 To High(PlayerDots) Do
Begin
If GetArrayLength(PlayerDots[i]) > 9 Then
Begin
MiddleTPAEx(PlayerDots[i], X, Y);
If Distance(MMCX, MMCY, X, Y) <= 22 Then
Result := Result + 1;
End;
End;
ColorToleranceSpeed(CTS);
End;
^^ free to use in scripts if I'm being credited.
Simple, isnt it? But even more effective
I don't have anything to teach about TPAs in mind atm, but request here if you have something to ask!
Cya ppl!
-----------------------------------------------------------------------------------------
Okay, request number one!
Pros and Cons of TPoint Arrays
Pro - Effective
Pro - Fast to make, unlike DDTMs or something like that.
Con - Slow to sort through a TPA and do changes, like any array. (Plugins though)
-----------------------------------------------------------------------------------------
Number two - using TPAs in loops fast.
Number one, don't do
SCAR Code:For I := 0 To High(TPA) Do
You can do that, but if you are fighting of milliseconds you need to do
SCAR Code:Le := High(TPA);
For I := 0 To Le Do
That ways, it doesn't have to call High every time, and can save you tens of milliseconds.
Then, another thing, since now we have WizzyPlugin in our .Includes/SRL/SRL/Misc/
we should use its functions over your home-made scar ones, unless yours are more effective.
For example, if you first do a FindColors, and then for each point you would like to know how much of color is around it, don't make a loop that does FindColors around each point, instead, just make an Array of TPointArray, and then do like
SCAR Code:TPAA := TPAToATPA(TPA, Distance)
Thats propably some of the important things, also common sense will help you.