Hello, welcome to my 5th tut fellow and future scriptures!
Breaking it Down
TPoint
Remember way back in grade 6 math when you had that graph with the x axis and the y axis and the teacher gave you coordinates for points on the graph then asked you to put them in, connect the dots and make a picture of a cat?
Each of those (x, y) points were known as 'points'. We call them 'TPoints'. Not to hard . For a more technical and shorter definition: "A specified point on the cartesian plane".
Arrays
Arrays are a simple way of declaring a bunch of variables that have some similarities. They can be any variables, but the most commonly used are booleans, strings, extendeds and integers. As for an example, here is a simple script i stole from NaumanAkhlaQ's array tut:
Originally Posted by
NaumanAkhlaQ
SCAR Code:
Procedure CutTree;
Var
YewColor : Array [0..5] of Integer;
i :Integer;
Begin
YewColor[0]:=2182984;
YewColor[1]:=1855560;
YewColor[2]:=4426622;
YewColor[3]:=1914933;
YewColor[4]:=3239519;
YewColor[5]:=3116158;
Begin
If (not (Loggedin)) then
Exit;
else
For i:= 0 to 5 do
If FindObjCustom(x,y,['ew'],[YewColor[i]],5) then
Begin
If IsUpText('ew') then
Begin
CutDown;
end;
end;
end;
Understanding the Use of TPA's
Now that you understand what a TPoint is, you can also understand that if you use TPoints in a script, and you need multiple TPoints for, lets say, finding an area on the minimap, it would take up a lot of space. It would take up a lot of space because this is how you would give a TPoint a value if you had multiple TPoints, without the use of TPAs:
SCAR Code:
program TPointExample;
var
Point1, Point2, Point3, Point4, Point5, Point6, Point7, Point8, Point9: TPoint;
begin
Point1:= inttopoint(523, 624); //inttopoint is short for integer to point. this takes two integers, in this case an x and a y, and converts it into one TPoint.
Point2:= inttopoint(253, 734);
Point3:= inttopoint(954, 736);
Point4:= inttopoint(1163, 712);
Point5:= inttopoint(52, 977);
Point6:= inttopoint(10, 13);
Point7:= inttopoint(535, 324);
Point8:= inttopoint(16, 61);
Point9:= inttopoint(233, 42);
end.
Thats alot of text .
Setting and Finding the Length of a TPA
First of all, we need to declare the TPA:
Simple as that
Now here are five procedures/functions that can be used for setting and finding the length of a TPA, I will go into more depth later.
SCAR Code:
procedure SetLength(var s; NewLength: Integer);
procedure SetArrayLength(var Arr; Count: Integer);
function Length(s): Integer;
function GetArrayLength(var Arr): Integer;
function High(x): Int64;
SetLength: This takes the TPointArray specified (var s), and changes the length to the length specified (NewLength). Heres an example:
This will take the TPA 'TheTPA' and change its length to 5.
SetArrayLength: Very similar to Setlength. It takes the TPointArray specified (var Arr), and changes the length to the length specified (Count). Example:
SCAR Code:
SetArrayLength(TheTPA, 5);
As you can see, it is almost the exact same, except for the procedure title.
Length: This takes the length of the specified TPA (s) and returns it as an integer. Example:
SCAR Code:
var
TheTPALength: integer;
TheTPA: TPointArray;
begin
TheTPALength := Length(TheTPA);
WriteLn('The length of TheTPA is ' + inttostr(TheTPA) + '.');
end.
This finds the length of the TPA 'TheTPA' and stores it as the integer 'TheTPALength', then it transfers the integer into a string and writes the number in the debug box.
GetArrayLength: This takes the length of the specified TPA (var Arr) and returns it as an integer. Example:
SCAR Code:
var
TheTPALength: integer;
TheTPA: TPointArray;
begin
TheTPALength := GetArrayLength(TheTPA);
WriteLn('The length of TheTPA is ' + inttostr(TheTPA) + '.');
end.
This is almost the same thing as Length, except just a different name.
High: This will find the highest index from out TPA. (e.g., TheTPA[0..10] has a highest index of 10.) Example:
SCAR Code:
Writeln('The highest index for TheTPA is ' + inttostr(High(TheTPA)));
MiddleTPA
This may sound confusing, but it is really easy once you get it. MiddleTPA finds the exact center of all of your TPA's. NOT the middle number of all your indexes, but the center of all your coordinates. Maybe this will help:
The x's are your TPoints. The check mark is the exact center of the four TPoints (yes it is, i measured it ).
Putting it all Togeather
SCAR Code:
program TPATogeatherExample;
var
TheTPALength: Integer;
TheTPoint: TPoint;
TheTPA: TPointArray;
begin
SetArrayLength(TheTPA, 6); //TheTPA now has 6 indexes
TheTPALength := Length(TheTPA); //Giving TheTPA length as the length of TheTPA
WriteLn('The length of TheTPA is ' + inttostr(TheTPA) + '.');
TheTPA[0]:= inttopoint(613, 834); //Declaring the coordinates...
TheTPA[1]:= inttopoint(336, 236);
TheTPA[2]:= inttopoint(723, 443);
TheTPA[3]:= inttopoint(232, 723);
TheTPA[4]:= inttopoint(234, 442);
TheTPA[5]:= inttopoint(633, 666);
TheTPoint := MiddleTPA(TheTPA); //This declares TheTPoint as the point in the exact center of the other 6 TPoints.
Writeln('The coordinates of TheTPoint are: (' + inttostr(TheTPoint.x) + ', ' + inttostr(TheTPoint.y) + ').'); //TheTPoint.x is the x coordinate of TheTPoint, same with TheTPoint.y, only with y.
end.
Thankyou for reading my first advanced tut. Any questions, comments or corrections, please post below. If you liked my tut, click the blue check mark in the top right corner .