Page 1 of 3 123 LastLast
Results 1 to 25 of 55

Thread: The Almighty TPA Tutorial

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

    Default The Almighty TPA Tutorial

    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" way
    SCAR 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 -
    SCAR Code:
    Array of TPointArray
    of one TPointArray, making a TPointArray of each group of points that are next to each other.

    Now you would do something like:
    SCAR Code:
    PlayerDots := SplitTPA(whitePoints);
    There you've got your player dots.

    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.

  2. #2
    Join Date
    Oct 2006
    Location
    finland, helsinki
    Posts
    2,501
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Ness all im saying is: You're amazing with TPA's A bit too amazing sometimes.

    Good tut

    Code:
    • Narcle: I recall Jukka releasing a bunch of scripts like this before... Its how he rolls I think. rofl
    • Solarwind: Dude, you are like... t3h s3x.
    • Hy71194: JuKKa you're a machine! You released 3 scripts in 10 minutes! :O
    • benjaa: woah.... Jukka is the man Guildminer pwns all
    • NaumanAkhlaQ: And JuKKa Is my Her0!

  3. #3
    Join Date
    Aug 2007
    Posts
    1,404
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    I knew you were gonna make one for this I'll promise to read I need to learn more about them :P I want to beat you (Impossible dream)

    -Knives

  4. #4
    Join Date
    Nov 2006
    Posts
    1,103
    Mentioned
    0 Post(s)
    Quoted
    6 Post(s)

    Default

    mh, go to the link in my sig and find some more interresting stuff on tpa(its not really explained though but i'm willing to explain on msn...) it also has atpa but nice job on the guide it doesnt really belong in the advanced section though...
    Infractions, reputation, reflection, the dark side of scripting, they are.

  5. #5
    Join Date
    Apr 2007
    Location
    Perth, Australia
    Posts
    3,926
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Goody.... I had to learn this myself . Anyways... n3ss3s you still want a tut on trigonometry?

  6. #6
    Join Date
    Dec 2006
    Posts
    723
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    TPointArrays aren't advanced at all, unless you plan on doing something I've never heard of. All you need to know is how to use a TPoint. . . And how to use an array. . . Now that Wizzup made a plugin you don't really have to do anything yourself, you just put in the parameters

    Who knows, though, you may know something I don't.

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

    Default

    @Zephyr: I'd love to see one
    @Killerdou: Your sig is advertising your finder already
    @JuKKa: Thanks
    @Town: No, they are simple, but many people have said that z0mg hard etc..

    Now, I'm back and continue writing it

  8. #8
    Join Date
    Mar 2007
    Location
    Netherlands->Amersfoort.
    Posts
    1,615
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    i always wanted to know about tpa's. i learned them myself and n3s33s comes with a tut

    good tut dude

  9. #9
    Join Date
    Mar 2007
    Posts
    3,681
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    can you write pros and cons of em?

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

    Default

    Okay, hold on

    Okay, added, though don't have more than three in total in my mind atm...

  11. #11
    Join Date
    Oct 2006
    Location
    finland, helsinki
    Posts
    2,501
    Mentioned
    3 Post(s)
    Quoted
    2 Post(s)

    Default

    Too bad i had to learn this the hard way.. Teaching my self

    Code:
    • Narcle: I recall Jukka releasing a bunch of scripts like this before... Its how he rolls I think. rofl
    • Solarwind: Dude, you are like... t3h s3x.
    • Hy71194: JuKKa you're a machine! You released 3 scripts in 10 minutes! :O
    • benjaa: woah.... Jukka is the man Guildminer pwns all
    • NaumanAkhlaQ: And JuKKa Is my Her0!

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

    Default

    Haha, well thats how I learnt it too

    Though I thought / think of it as fun

  13. #13
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Nice
    You could add the optimizing of loops for TPA's..
    Hup Holland Hup!

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

    Default

    Thanks

    I'll do it today after school

    So, now I'm back from school, what do you mean by optimizing?

  15. #15
    Join Date
    Dec 2006
    Location
    Banville
    Posts
    3,914
    Mentioned
    12 Post(s)
    Quoted
    98 Post(s)

    Default

    Make it faster. Like how you and Ben and all those people were comparing times on the Mining Procedure thread.
    The jealous temper of mankind, ever more disposed to censure than
    to praise the work of others, has constantly made the pursuit of new
    methods and systems no less perilous than the search after unknown
    lands and seas.

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

    Default

    I can't explain it, after all it isn't anything so special...

    Umm the one below is propably bit under 100ms, haven't tested... it was 78 or 62 I think.

    SCAR Code:
    Function FindRockVein(Var Rx, Ry: Integer; x1, y1, x2, y2: Integer): Boolean;
    Var
      L, I, Mx, My, P, Col, CTS: Integer;
      TPA, TPA2, TPA3: TPointArray;
      Box, B2: TBox;
      TP: TPoint;
    Begin
      If Not LoggedIn Then Exit;
      CTS := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      Box := IntToBox(MSCX - 15, MSCY - 20, MSCX + 15, MSCY + 20);
      FindColorsSpiralTolerance(MSCX, MSCY, TPA, RockColor, x1, y1, x2, y2, 15);
      L := GetArrayLength(TPA) - 1;
      For I := 0 To L Do
      Begin
        TP := TPA[i];
        If(Not(PointInBox(TP, Box)))Then
        Begin
          FindColorsTolerance(TPA2, MudColor, TP.x - 10, TP.y - 10, TP.x + 10, TP.y + 10, 15);
          If(GetArrayLength(TPA2) >= 100)Then
          Begin
            MiddleTPAEx(TPA2, TP.x, TP.y);
            B2 := IntToBox(TP.x - 10, TP.y - 10, TP.x + 10, TP.y + 10);
            Mx := B2.x1 + ((B2.x2 - B2.x1) / 2);
            My := B2.y1 + ((B2.y2 - B2.y1) / 2);
            FindColorsSpiralTolerance(Mx, My, TPA3, RockColor, B2.x1, B2.y1, B2.x2, B2.y2, 15);
            If(GetArrayLength(TPA3) >= 25)Then
            Begin
              P := Round((GetArrayLength(TPA3) / GetArrayLength(TPA2)) * 100);
              If(P > 3) And (P < 20)Then
              Begin
                Result := True;
                MiddleTPAEx(TPA3, Rx, Ry);
                RockColor := GetColor(TPA3[0].x, TPA3[0].y);
                Break;
              End;
            End;
          End;
        End;
      End;
      ColorToleranceSpeed(CTS);
    End;

    And the one I used in competition, 47ms =
    SCAR Code:
    Function FindRock(All: Boolean; var RockTPA: TPointArray; Color: Integer): Boolean;
    Var
      I, D, C, B, X, Y, A, Z, M, N: Integer;
    Var
      TPA: TPointArray;
    Begin
      A := GetClientWindowHandle;
      B := GetSystemTime;
      C := GetColorToleranceSpeed;
      ColorToleranceSpeed(2);
      I := BitmapFromString(762, 502, '');
      CopyClientToBitmap(i, 0, 0, 762, 502);
      SetTargetBitmap(i);
      FindColorsTolerance(TPA, Color, MSX1, MSY1, MSX2 - 5, MSY2 + 5, 0);
      Z := GetArrayLength(TPA);
      If(Not(Z <= 0))Then
      Begin
        For D := 0 To Z - 1 Do
        Begin
          FastSetPixel(i, TPA[d].x, TPA[d].y, 255);
        End;
        X := MSX2;
        Y := MSY2;
        If(Not(All))Then
        Begin
          If(FindColorSpiral2(X, Y, 255, MSX1, MSY1, MSX2, MSY2))Then
          Begin
            Result := True;
            FindColorsTolerance(TPA, 255, X - 15, Y - 15, X + 15, Y + 15, 0);
            SetArrayLength(RockTPA, 1);
            RockTPA[0] := MiddleTPA(TPA);
          End;
        End Else
        Begin
          FindColorsSpiralTolerance(MSCX, MSCY, RockTPA, 255, MSX1, MSY1, MSX2, MSY2, 0);
          If(GetArrayLength(TPA) > 0)Then
          Begin
            Result := True;
          End;
        End;
      End;
      FreeBitmap(i);
      SetClientWindowHandle(A);
      ColorToleranceSpeed(C);
      M := GetSystemTime;
      N := M - B;
      Writeln(IntToStr(N));
    End;

    Though I believe I could make better now...

  17. #17
    Join Date
    Sep 2006
    Posts
    6,089
    Mentioned
    77 Post(s)
    Quoted
    43 Post(s)

    Default

    Quote Originally Posted by n3ss3s View Post
    Thanks

    I'll do it today after school

    So, now I'm back from school, what do you mean by optimizing?

    Store the arraylength in a variable to speed up loops, do a rangecheck before you do heavier work (in ATPA's). Don't do FindColors twice, like this:

    SCAR Code:
    FindColorsTolerance(p, 0, 5, 5, 515, 336, 15);
      l := Length(p);
      for i := 0 to l -1 do
      begin
        FindColorsTolerance(tp, 0, p[i].x -5, p[i].y -5, p[i].x +5, p[i].y +5, 15);

    IMO it's better to do a TPAtoATPA here.
    That's pretty much all I can think of now
    Hup Holland Hup!

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

    Default

    Oh, ty, I'll start working on it

  19. #19
    Join Date
    Jul 2007
    Posts
    1,431
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    n3s, could you make few examples about object finding...
    and examples how to use most used functions from Wizzup's plugin...
    and would be cool if you explain all of them : TPoint, TPointArray and Array of TPointArray.

    Thank you.

    Ok, it may be too much asked...just obj finding... I mean I want to make chicken killer.

    Chicken brown colors are hard to seperate from planks and crates and from other same colored stuff...

    So what i wanna do is to find chickens red head color, make 30*30 box on it,
    and in that box i try to find the brown color center...so far I almost done it, put after few kills i get runtime error, or it won't start at all because of type mismatch...[wrong variables] thats why someone shoud exmplain TPoint, TPointArray and Array of TPointArray.

    thx
    [CENTER][SIZE="4"]Inactive[/SIZE]I forgot my password[/CENTER]

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

    Default

    Just do a FindColorsSpiralTolerance(RedThing.x - 5, RedThing.y + 8, TehTPA.....)

    with the brown color, and then do MiddleTPAEx(TehTPA, ChX, ChY);

  21. #21
    Join Date
    Feb 2006
    Location
    Amsterdam
    Posts
    6,136
    Mentioned
    28 Post(s)
    Quoted
    17 Post(s)

    Default

    Stickyfied.
    SRL is a Library of routines made by the SRL community written for the Program Simba.
    We produce Scripts for the game Runescape.

  22. #22
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    Sorry, but I think this should be in Tutorials for Intermediates, BECAUSE there's really not any advanced methods here yet.

    But well done tutorial.

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

    Default

    Thanks BullZeye, and yeah, maybe to Intermeds?

    Woah, stickied? omg lol, my tut got a sticky xD Thx..

  24. #24
    Join Date
    Dec 2006
    Location
    Houston, TX USA
    Posts
    4,791
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    Quote Originally Posted by bullzeye95 View Post
    Sorry, but I think this should be in Tutorials for Intermediates, BECAUSE there's really not any advanced methods here yet.

    But well done tutorial.
    Agreed, this is something that shouldn't just be reserved for advanced scripters, because after all, it isn't all that advanced. If you ask me, it should be one of the first things you learn when it comes to finding objects effectively in rs.

    Is it effective? Very.
    Does it belong in the Advanced Section? No.

    Nice tutorial though, N3ss.

  25. #25
    Join Date
    Jun 2006
    Posts
    3,861
    Mentioned
    3 Post(s)
    Quoted
    0 Post(s)

    Default

    I think you should add stuff like TPA/ATPA size, TPA/ATPA locations, as in middle points related to a point, and mixing TPA/ATPAs, both additive and subtractive. Then I think it would be advanced.

Page 1 of 3 123 LastLast

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Using Almighty TPA's for object finding
    By Timothegreat in forum OSR Advanced Scripting Tutorials
    Replies: 21
    Last Post: 11-04-2008, 06:02 PM
  2. RS Tutorial Bot
    By Jorogan in forum OSR Help
    Replies: 2
    Last Post: 11-25-2007, 01:47 AM
  3. need a tutorial
    By mark9510 in forum RS3 Outdated / Broken Scripts
    Replies: 12
    Last Post: 11-05-2007, 03:56 AM
  4. Replies: 8
    Last Post: 08-23-2007, 08:13 AM
  5. Array Tutorial - (Old Tutorial)
    By XxKanexX in forum Outdated Tutorials
    Replies: 1
    Last Post: 04-12-2006, 03:36 PM

Posting Permissions

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