Results 1 to 7 of 7

Thread: Intermediate TPA Usage

  1. #1
    Join Date
    Jun 2012
    Posts
    2,182
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Cool Intermediate TPA Usage

    Intermediate TPA Usage

    Contents
    • Intro
    • WizzyPlugin
      [-]What is an ATPA
    • SplitTPAEx
    • Creating an advanced Object-finding ATPA Function
    • Conclusion


    Intro

    Hey guys, welcome to my Intermediate TPA Usage Tutorial! This tutorial is a sequal to my other one, and assumes you know everything covered in the last one. If you havn't read it, the link is here. As usual, this tutorial was made in simba using the Pascalscript interpreter. The only knowledge needed to understand this tutorial is what I covered in the last one. If you feel confident creating CTS2 functions, then you are ready to step it up to the next level! Please post constructive critisism below, I'm always looking to improve! Now, lets dive head-first into the WizzyPlugin!

    WizzyPlugin

    The WizzyPlugin is about to become your best friend. What it is is a huge list of functions that can twist and shape TPA's and ATPA's to your needs. In this tutorial, we will be using SplitTPAEx from the WizzyPlugin. If you are ever attempting to create a function, but you just can't find a function to do what you need, it might be worth checking the WizzyPlugin here. Time to learn about ATPA's!

    ATPA's

    What is an ATPA??? Well, its actually not that complicated. If a TPA is an array of TPoints, an ATPA is simply an Array of TPA's! Yes, thats right. It's an Array of an Array of TPoints. To make it simpler, I've drawn this.



    The Black boxes are TPA's, and the red box is the big ATPA. The TPA's can be called the same way you can call a Tpoint from a TPointArray, ATPA[Numberhere]. If you want, you can even get a TPoint from a ATPA, by going like this! ATPA[WhichTPA][WhichTPoint] I think thats enough exitement about ATPA's for now, lets move onto SplitTPAEx!

    SplitTPAEx

    SplitTPAEx is the function we will be using in our object finding function. What does SplitTPAEx do? Lets look at some pictures to figure out. This, is a picture of swiss cheese.


    Lets say we want to find where these black holes are, how many of them there are, and make each hole have its own TPA. To do that, we use SplitTPAex! What it does is it will make TPA's the size of whatever you entered in your parameters(Width, Height). Then, It will merge all touching TPA's into one big TPA!

    For example, first, it will make TPA boxes the size of your entered parameters. This picture shows 20x20(Imagine they are 20x20) boxes made on the holes.



    Now thats all fine and dandy, but do we really need a crap ton of boxes per hole? No, we need one per hole, which is why SplitTPAEx combines all touching boxes into one awesome super-box!



    There we go! A nice, clean group of TPA's. Each hole has its own TPA, and they can very easily be counted by grabbing the length of our ATPA. Now lets learn how to use this IRL(In Runescape Life).

    Creating an advanced Object-finding ATPA Function

    Alright, all this information is pretty neat, but I didn't teach it to you to fill up precious space in your brain. No, I taught this to you so you can use it on the big stage, runescape! It's time to create a function that will accurately find this bank chest!



    Now you may be thinking, "That's easy! Just look for the brown color! You taught us that last tutorial Footy!". Well sometimes, it's just not that easy. In this case, as you can see in the above picture, a large portion of the background is brown. The exact same brown as the bank chest. Unfortunately Simple TPA's and CTS2 won't cut it this time. It's time to pull the big boys out.

    Alright, so first, we need a game plan. An idea on how to find this bank chest without finding all the other brown spear thingys. Well, judging by that picture, the rim color seems pretty unique. There are a few other small points of this color elsewhere on the screen, but that won't be a problem using SplitTPAEx. Lets get into the code portion.

    Okay, so we will start off with finding the rim color, and loading it into a TPA. This TPA will be called RimTPA. Find the Rim color the same way you did in the last tutorial. This was my final result.

    Simba Code:
    Function OpenBankCustom:boolean;
    var
      RimTPA:TPointArray;
    begin
     if not(loggedin) then
        exit;
      SetColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.07, 1.21);
      if findcolorstolerance(RimTPA, 9738699, 205, 102, 325, 227, 25) then
        begin
        end;
    end;

    Note: The Xs, Ys, Xe, and Ye were determined by getting a box that would house the chest no matter what camera angle I was using. If you are confident, you can use the entire screen(MSX1, MSY1...).

    So the various bits of this rim color will all be collected into our TPA. What happens if we find a piece of rim color on the other side of the screen though? What if we accidently move our mouse to that pixel? It would screw the script up and look horribly bot-like. Thats why we will use SplitTPAEx to create boxes of this Rimcolor, then sort the TPA's by size, leaving us with our chest. This is my code after doing the above, I'll explain it all in a minute.

    Simba Code:
    Function OpenBankCustom:boolean;
    var
      RimTPA:TPointArray;
      RimATPA:T2DPointArray;
      RimBox:TBox;
    begin
     if not(loggedin) then
        exit;
      SetColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.07, 1.21);
      if findcolorstolerance(RimTPA, 9738699, 205, 102, 325, 227, 25) then
        begin
          RimATPA := SplitTPAEx(RimTPA, 20, 20);
          SortATPASize(RimATPA, True);
          RimBox := GetTPABounds(RimATPA[0]);
        end;
    end;

    So, I added SplitTPAEx, which we already went over(Note: You have to assign a variable to SplitTPAEx since it returns the ATPA.) Next, I used SortATPASize. What this will do is look at the sizes of those boxes(Think swiss cheese) and sort them in the ATPA. The True means biggest go first. This means the largest box becomes RimATPA[0], the text largest becomes RimATPA[1], Etc... Now that we have done this, our bank chest will be in RimATPA[0]. I'm also assigning the area of our TPA to RimBox. This just makes it easier to work with.

    Now what happens if somehow, for some bizarre reason, we were returned the wrong RimTPA? A Character walked by wearing silver clothes, and our script returned him as the largest. Well why don't we check for brown inside that box? That sounds like a good idea? No? Now we are going to put all this into a for..to..do loop, to make returning to the beginning incase of an error easier. This is my script now.

    Simba Code:
    Function OpenBankCustom:boolean;
    var
      RimTPA:TPointArray;
      RimATPA:T2DPointArray;
      RimBox:TBox;
      i:integer;
    begin
     if not(loggedin) then
        exit;
      SetColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.07, 1.21);
      if findcolorstolerance(RimTPA, 9738699, 205, 102, 325, 227, 25) then
        begin
          RimATPA := SplitTPAEx(RimTPA, 20, 20);
          SortATPASize(RimATPA, True);
          for i := 0 to high(RimATPA) do
            begin
              RimBox := GetTPABounds(RimATPA[i]);
              SetColorSpeed2Modifiers(0.04, 0.28);
              if findcolorstolerance(WoodTPA, 4609378, RimBox.x1, Rimbox.Y1, Rimbox.X2, Rimbox.Y2, 15) then
                Break;
              if i = high(RimATPA) then
                begin
                  writeln('We went through all TPA''s and found no brown! Check your CTS2 Work!');
                  Terminatescript;
                end;
            end;
        end;
    end;

    Okay, I added quite a bit of stuff there. We should all know what a for..to..do loop is, so I'll skip that. I'm now assigning Rimbox to RimATPA[i], so if we don't find the brown the first time, we will loop again, and increase i, thus changing to the next TPA. I set the modifiers again because I'm using them when looking for the wood color. If we do find this brown color inside our RimTPA box, I'm breaking out of the for..to..do loop. Lastly, I have a failsafe. If we go through every single TPA and we couldn't find brown, we are terminating the script. This is likely because you either didn't use CTS2 correctly, grabbed your colors wrong, or are in the wrong spot all together.

    Right, we are just about finished now. All we have to add is an uptext check, and we are done.

    Simba Code:
    Function OpenBankCustom:boolean;
    var
      RimTPA, WoodTPA:TPointArray;
      RimATPA:T2DPointArray;
      RimBox:TBox;
      i, r, counter:integer;
    begin
     if not(loggedin) then
        exit;
      SetColorToleranceSpeed(2);
      SetColorSpeed2Modifiers(0.07, 1.21);
      if findcolorstolerance(RimTPA, 9738699, 205, 102, 325, 227, 25) then
        begin
          RimATPA := SplitTPAEx(RimTPA, 20, 20);
          SortATPASize(RimATPA, True);
          for i := 0 to high(RimATPA) do
            begin
              RimBox := GetTPABounds(RimATPA[i]);
              SetColorSpeed2Modifiers(0.04, 0.28);
              if findcolorstolerance(WoodTPA, 4609378, RimBox.x1, Rimbox.Y1, Rimbox.X2, Rimbox.Y2, 15) then
                Break;
              if i = high(RimATPA) then
                begin
                  writeln('We went through all TPA''s and found no brown! Check your CTS2 Work!');
                  Terminatescript;
                end;
            end;
          SetColorToleranceSpeed(1);
          SetColorSpeed2Modifiers(0.02, 0.02);
          marktime(counter);
          while (not isuptext('ank')) do
            begin
              r := random(length(WoodTPA));
              mmouse(WoodTPA[r].x, WoodTPA[r].y, 3, 3);
              wait(randomrange(200, 500));
              if timefrommark(counter) > 5000 then
                begin
                  writeln('Dafuq?!? Uptext never showed! Logging out!');
                  Logout;
                  Terminatescript;
                end;
            end;
          clickmouse2(mouse_left);
        end;
    end;

    Finished! Now if you followed correctly, and did everything correct, you should be able to find this bank chest easily! Please note that this can be used in other situations, not just bank chests. You just have to be creative, and utilize the WizzyPlugin to your advantage.

    Conclusion

    Wow, second tutorial down! I'll be honest, I didn't think it would be as long as the last, but I just kept finding things to talk about, . I hope you guys enjoyed the tutorial, or atleast learned something. If you don't understand something, or if theres something thats incorrect or could be improved with my tutorial, please let me know! Also, next time I find some time, I'll probably write another tutorial, let me know below what you would like!

    Thanks and keep learning!
    Footy
    Thx Euphemism and Vinyl for the awesome siggy and avatar!

  2. #2
    Join Date
    Nov 2012
    Posts
    141
    Mentioned
    0 Post(s)
    Quoted
    43 Post(s)

    Default

    Concise guide, great explanations.
    After reading this and your first guide, I understand TPAs well, I'm using them in my Draynor woodcutter.
    Thanks a lot!

  3. #3
    Join Date
    Nov 2008
    Location
    UK
    Posts
    153
    Mentioned
    1 Post(s)
    Quoted
    0 Post(s)

    Default

    Great tutorial. Really clear and easy to understand. I've lso adopted this for my Draynor WC ^ . I'm gonna start adding it to my other scripts as well, as it is a really good method for finding object (and also looks good with a debug box around the ATPA).

  4. #4
    Join Date
    Dec 2011
    Location
    Berlin
    Posts
    795
    Mentioned
    0 Post(s)
    Quoted
    5 Post(s)

    Default

    Quote Originally Posted by Footy View Post
    I love this grahpic! Good for imagination!

    I will try to answer all Runescape related questions!

  5. #5
    Join Date
    Dec 2011
    Location
    U.S.A.
    Posts
    635
    Mentioned
    5 Post(s)
    Quoted
    249 Post(s)

    Default

    I'm not grave digging. I found this guide very helpful. I will use ATPA's and TPA's to find lots of things now.

  6. #6
    Join Date
    Aug 2009
    Location
    The USA
    Posts
    5
    Mentioned
    0 Post(s)
    Quoted
    0 Post(s)

    Default

    These tutorials really helped me

  7. #7
    Join Date
    Apr 2012
    Location
    Land of the Rising Sun
    Posts
    207
    Mentioned
    0 Post(s)
    Quoted
    77 Post(s)

    Default

    I've been reading Footy's tutorials too, they're easy to understand Hopefully he sorts out his stuff and comes back to the SRL community.

Thread Information

Users Browsing this Thread

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

Posting Permissions

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