Results 1 to 22 of 22

Thread: Using Almighty TPA's for object finding

  1. #1
    Join Date
    May 2007
    Location
    in a pineapple under the sea
    Posts
    1,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Using Almighty TPA's for object finding

    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

    SCAR Code:
    var
      Blah: 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)

    SCAR Code:
    var
      Blah: TPointArray;

    - Short for TPointArray.
    - In essence it is an array of TPoints. (see above)
    - used in many ways including object finding.

    T2DPointArray

    SCAR Code:
    var
      Blah: 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.
    [SIZE="4"][CENTER][URL="http://www.youtube.com/watch?v=5YsGJz3j4os"]LOL u mad bro?[/URL][/CENTER][/SIZE]

  2. #2
    Join Date
    Oct 2006
    Posts
    2,297
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Nice tutorial! Though, I prefer to explain it a bit more, like that a T2DPointArray is 2-deminsional and so that there also excists T3DPointArray, have a look at SRL's Playerform made by Sumilion, I think it's being used over there

    I'm only suggesting

    Oh, maybe you could expand your tutorial by explaining other functions from inside the WizzyPlugin aswell

    -Tsn.
    [QUOTE=Santa_Clause;277761]I love you too TSN :p[/QUOTE]
    [CENTER][URL="http://www.stats.srl-forums.com/sigs"][IMG]http://www.stats.srl-forums.com/sigs/1324.png[/IMG][/URL][/CENTER]

  3. #3
    Join Date
    Jul 2007
    Location
    Right now? Chair.
    Posts
    8,488
    Mentioned
    3 Post(s)
    Quoted
    12 Post(s)

    Default

    *****5 stars cleared a lot of things, especially the SplitTPA/TPAtoATPA image

    ~RM

    I & I know Zion. It is in the spirit, body and mind of every one of us
    RMouse(obj: TMSIObject): boolean;

  4. #4
    Join Date
    Jul 2007
    Location
    Norway.
    Posts
    1,938
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Tell more about theese functions:

    SCAR Code:
    {*******************************************************************************
    procedure RAaSTPAEx(var a: TPointArray; const w, h: Integer);
    Description: Leaves one point per box with side lengths W and H to the TPA.
    *******************************************************************************}


    {*******************************************************************************
    procedure RAaSTPA(var a: TPointArray; const Dist: Integer);
    Description: Leaves one point per box with the side length Dist.
    *******************************************************************************}


    {*******************************************************************************
    procedure SortTPAFrom(var a: TPointArray; const From: TPoint);
    Description: Sorts the TPointArray a from the point From.
    Closest one to the point is [0], second closest is [1] etc.
    *******************************************************************************}


    {*******************************************************************************
    procedure SortATPAFrom(var a: T2DPointArray; const From: TPoint);
    Description: Sorts the T2DPointArray a from the point From.
    *******************************************************************************}

     
     
    {*******************************************************************************
    procedure SortATPAFromFirstPoint(var a: T2DPointArray; const From: TPoint);
    Description: Sorts the T2DPointArray a from the point From.
    *******************************************************************************}

     
     
    {*******************************************************************************
    procedure InvertTPA(var a: TPointArray);
    Description: Inverts / Reverts the TPointArray a.
    *******************************************************************************}

    {*******************************************************************************
    procedure InvertATPA(var a: T2DPointArray);
    Description: Inverts / Reverts the T2DPointArray a.
    *******************************************************************************}

    {*******************************************************************************
    procedure SortATPASize(var a: T2DPointArray; const BigFirst: Boolean);
    Description: Sorts the T2DPointArray a from either largest or smallest, by the
    amount of points in the TPAs.
    *******************************************************************************}

     
     
    {*******************************************************************************
    function CombineTPA(Ar1, Ar2: TPointArray): TPointArray;
    Description: Combines the TPointArrays Ar1 and Ar2, and results the combination.
    *******************************************************************************}

    {*******************************************************************************
    function SplitTPAEx(arr: TPointArray; w, h: Integer): T2DPointArray;
    Description: Splits the points with max X and Y distances W and H to their
    own TPointArrays.
    *******************************************************************************}

    {*******************************************************************************
    procedure FilterPointsPie(var Points: TPointArray; const SD, ED, MinR, MaxR: Extended; Mx, My: Integer);
    Description: Removes the points in the TPointArray Points that are not within
    the degrees SD (StartDegree) and ED (EndDegree) and the distances
    MinR (MinRadius) and MaxR (MaxRadius) from the origin (Mx, My).
    *******************************************************************************}

     
     
    {*******************************************************************************
    function RemoveDistTPointArray(x, y, dist: Integer; ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray;
    Description: Removes the points that are inside or outside the distance Dist
    from the point (x, y) from the TPointArray ThePoints.
    *******************************************************************************}

     
     
    {*******************************************************************************
    function GetTPABounds(TPA: TPointArray): TBox;
    Description: Returns the boundaries of the TPA as a TBox.
    *******************************************************************************}

     
     
    {*******************************************************************************
    function FindTPAinTPA(SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;
    Description: Looks for the TPA SearchTPA in the TPA TotalTPA and returns
    the matched points to the TPA Matches. Returns true if there were atleast one
    match(es).
    *******************************************************************************}

     
     
    {*******************************************************************************
    function FindTextTPAinTPA(Height: Integer; SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;
    Description: Read the description of FindTPAinTPA. Additional Height parameter.
    *******************************************************************************}

     
     
    {*******************************************************************************
    function FindGapsTPA(TPA: TPointArray; MinPixels: Integer): T2DPointArray;
    Description: Finds the possible gaps in the TPointArray TPA and results the
    gaps as a T2DPointArray. Considers as a gap if the gap length is >= MinPixels.
    Only horizontal, sorry folks.
    *******************************************************************************}

    {*******************************************************************************
    Function MergeATPA(ATPA: T2DPointArray): TPointArray;
    Description: Merges the TPointArrays of the T2DPointArray ATPA in to one TPA.
    *******************************************************************************}

    Note: Underline the differences between the normal and the "Ex" procedures.. (TPAToATPA vs. TPAToATPAEx)

    Pleeeease?

  5. #5
    Join Date
    Oct 2006
    Posts
    2,297
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by EvilChicken! View Post
    Note: Underline the differences between the normal and the "Ex" procedures.. (TPAToATPA vs. TPAToATPAEx)

    Pleeeease?
    Meh! It's 02:06 AM atm over here, I'll only tell you about TPAToATPA and TPAToATPAEx

    function TPAtoATPA(TPA: TPointArray; Dist: Integer): T2DPointArray;
    Input: TPointArray and distance.
    What does it do? It devides the TPointArray you've inputted into seperated groups. It does this by the "distance".
    It makes groups that are close to eachother, by a given max distance.

    function TPAtoATPAEx(TPA: TPointArray; w, h: Integer): T2DPointArray;

    Input: TPointArray and a "widh" and "heigth".
    What does it do? It devides the TPointArray in sperated groups, just as TPAToATPA does, but! instead of checking the distance, it checks the widh and height, like the widh and height of an object, not the distance.

    They both output a 2-dimensional array, but makesthe groups in a different way

    I hope that cleared it out better..

    -Tsn.
    [QUOTE=Santa_Clause;277761]I love you too TSN :p[/QUOTE]
    [CENTER][URL="http://www.stats.srl-forums.com/sigs"][IMG]http://www.stats.srl-forums.com/sigs/1324.png[/IMG][/URL][/CENTER]

  6. #6
    Join Date
    Jun 2007
    Location
    Hell Stream
    Posts
    584
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

  7. #7
    Join Date
    May 2007
    Location
    in a pineapple under the sea
    Posts
    1,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    im glad you like it guys
    [SIZE="4"][CENTER][URL="http://www.youtube.com/watch?v=5YsGJz3j4os"]LOL u mad bro?[/URL][/CENTER][/SIZE]

  8. #8
    Join Date
    Aug 2007
    Location
    Georgia, U.S.
    Posts
    890
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    very nice! I never understood TPA's very well. Added rep.

  9. #9
    Join Date
    May 2007
    Location
    in a pineapple under the sea
    Posts
    1,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    no problem... il probably make a form tutorial soon also

    this tutorial needs to be seen more
    [SIZE="4"][CENTER][URL="http://www.youtube.com/watch?v=5YsGJz3j4os"]LOL u mad bro?[/URL][/CENTER][/SIZE]

  10. #10
    Join Date
    Apr 2008
    Posts
    30
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by Timothegreat View Post
    ...
    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.
    ...
    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.
    ...
    Regarding TPAtoATPAEx, how can points have a height and width? They are just points. This part confuses me. Do you mean within a certain box around a point? For example, if we start with the TPoint 10,10, do width 3 and height 4 mean all the points within +/- 3 pixels in the x-direction and 4 pixels in the y-direction (i.e. anything within the box 7,6 to 13,14)?

    Assuming that's the case, then I have a follow-up question about how it groups the TPoint arrays (applies to function that does this by distance as well). Does it do it somehat holistically by looking at all of the points at once or does it just start with the first point in the input array and add in every other point within a certain distance/box to that array to form the first group and then takes the next unused point in the array as the basis for the next group of TPoints, finding all of the remaining unused points within a certain distance/box, and so on?

  11. #11
    Join Date
    Dec 2006
    Location
    Copy pastin to my C#
    Posts
    3,788
    Mentioned
    8 Post(s)
    Quoted
    29 Post(s)

    Default

    Nice tutorial, but the cold truth is that if doing object finding, there is no need for a huge chunk of code since FindObjTPA does it all...

  12. #12
    Join Date
    May 2007
    Location
    Some where fun.
    Posts
    2,891
    Mentioned
    1 Post(s)
    Quoted
    5 Post(s)

    Default

    wow, gr8 tut man.. Rep +

    and btw n3ss3s, the big chunk of code is needed because when using findobjtpa it moves the mouse around the screen if it doesnt find it. If u use the "big chunk of code" then you can save it as a boolean and be
    repeat
    if not AttackMonster then wait(1000+Random(1000));
    until(imadmin)or (immod) or (banned)// lol

  13. #13
    Join Date
    May 2007
    Location
    in a pineapple under the sea
    Posts
    1,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by tetazoo View Post
    Regarding TPAtoATPAEx, how can points have a height and width? They are just points. This part confuses me. Do you mean within a certain box around a point?
    the array of the points has a certain width and height not the points themselves.
    [SIZE="4"][CENTER][URL="http://www.youtube.com/watch?v=5YsGJz3j4os"]LOL u mad bro?[/URL][/CENTER][/SIZE]

  14. #14
    Join Date
    Dec 2007
    Location
    Colombia. Bogotá D.C
    Posts
    720
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thanks Timo!! this helped me a lot, those little pics you put are really helpfull I like em, I would like the other TPA guides to add pics also , would be really really helpfull :
    -------------------------------------------------------------------


  15. #15
    Join Date
    May 2007
    Location
    in a pineapple under the sea
    Posts
    1,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    np glad i can be of help to you.

    and yes... pics do help.
    [SIZE="4"][CENTER][URL="http://www.youtube.com/watch?v=5YsGJz3j4os"]LOL u mad bro?[/URL][/CENTER][/SIZE]

  16. #16
    Join Date
    Dec 2006
    Location
    Florida
    Posts
    18
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    How is the Distance Argument Measured in TPA's? Is it pixels? and why is it declared as a longint?

  17. #17
    Join Date
    May 2007
    Location
    in a pineapple under the sea
    Posts
    1,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    distance is measured in pixels... and idk im sure it can be a longint or an integer
    [SIZE="4"][CENTER][URL="http://www.youtube.com/watch?v=5YsGJz3j4os"]LOL u mad bro?[/URL][/CENTER][/SIZE]

  18. #18
    Join Date
    Dec 2006
    Posts
    173
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Thank you! Great tutorial, helped me a lot. The pics were nice too. Rep +

    Will definitely be using this in my upcoming script!
    Starting to merchant, if you know of any good clans, PM me please.

  19. #19
    Join Date
    May 2007
    Location
    in a pineapple under the sea
    Posts
    1,040
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Macho Man67 View Post
    Thank you! Great tutorial, helped me a lot. The pics were nice too. Rep +

    Will definitely be using this in my upcoming script!
    np dude, thanks
    [SIZE="4"][CENTER][URL="http://www.youtube.com/watch?v=5YsGJz3j4os"]LOL u mad bro?[/URL][/CENTER][/SIZE]

  20. #20
    Join Date
    Dec 2006
    Posts
    908
    Mentioned
    1 Post(s)
    Quoted
    17 Post(s)

    Default

    I still dont get how to do TPA, i read yours and Naurman's Guide...
    I know the functions, i just dont know how to put them all together to make it work.


    SCAR Code:
    program UsingTPALast; {TimoTheGreat, thanks for the guide!}
    {.include SRL/SRL.scar}

    function FindWillows: Boolean;
    var
      WX, WY, x, y, i, W, WillowColor : Integer;
      WillowPoints : TPointArray;
      Willow2D : T2DPointArray;
      WillowPoint : TPoint;

    begin
      x := MSCX
      y := MSCY
      W := High(Willow2D);
      FindColorsSpiralTolerance(x, y, WillowPoints, 2119757, MSX1, MSY1, MSX2, MSY2, 10);
      Willow2D := TPAtoATPAEx(WillowPoints, 3, 3);
      for I := 0 to W do
      begin
        WillowPoint := MiddleTPA(Willow2D[i]);
        WX := WillowPoint.X;
        WY := WillowPoint.Y;
        MMouse(WX, WY, 1, 1);
        Wait(530 + Random(890));
        if IsUpText('hop') then
        begin
          GetMousePos(x, y)
          WillowColor := GetColor(WX, WY);
          Mouse(x, y, 0, 0, true);
          Writeln('True');
          Result := True;
          Break;
          Exit;
        end else
          Writeln('False');
          Result := False;
          Exit;
      end;
    end;

    procedure PleaseWork;
    begin
      if FindWillows then
        Writeln('');
    end;

    begin
      ActivateClient;
      Wait(2000);
      PleaseWork;
    end.

    Also what does High({Insert T2DPointArray}) do?

    What could be wrong with this

  21. #21
    Join Date
    Dec 2007
    Posts
    2,766
    Mentioned
    2 Post(s)
    Quoted
    37 Post(s)

    Default

    Rep++, 5 star rate.

    Thanks alot, i've read many TPA tuts but this one is the best (its the one which made me understand TPA's).

    Ty ty ty !

  22. #22
    Join Date
    Nov 2008
    Location
    Norway, Alesund
    Posts
    924
    Mentioned
    0 Post(s)
    Quoted
    37 Post(s)

    Default

    great!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. need help finding object
    By Baked0420 in forum OSR Help
    Replies: 13
    Last Post: 12-15-2008, 01:27 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •