PDA

View Full Version : Intermediate TPA Usage



Footy
11-07-2012, 11:57 PM
:spot:Intermediate TPA Usage:spot:


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 (http://villavu.com/forum/showthread.php?t=90767). 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 (http://villavu.com/forum/showthread.php?t=49067). 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.

http://i0.simplest-image-hosting.net/picture/untitled249.png#REMEMBER-TO-LINK-SIMPLEST-IMAGE-HOSTING.NET-WHEN-HOTLINKING

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.
http://efficiencymatrix.com.au/wp-content/uploads/2009/11/bg_swisscheese_310.jpg

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.

http://i0.simplest-image-hosting.net/picture/untitled247.png#REMEMBER-TO-LINK-SIMPLEST-IMAGE-HOSTING.NET-WHEN-HOTLINKING

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!

http://i0.simplest-image-hosting.net/picture/untitled248.png#REMEMBER-TO-LINK-SIMPLEST-IMAGE-HOSTING.NET-WHEN-HOTLINKING

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!

http://i0.simplest-image-hosting.net/picture/untitled251.png#REMEMBER-TO-LINK-SIMPLEST-IMAGE-HOSTING.NET-WHEN-HOTLINKING

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.

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.

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.

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. :D

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, :D. 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

Neodymium
11-21-2012, 03:01 AM
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!

mounty
11-27-2012, 12:09 PM
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).

Imanoobbot
11-27-2012, 02:12 PM
http://i0.simplest-image-hosting.net/picture/untitled249.png#REMEMBER-TO-LINK-SIMPLEST-IMAGE-HOSTING.NET-WHEN-HOTLINKING


I love this grahpic! Good for imagination!

Sawyer
03-05-2013, 03:39 PM
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. :)

zeejfps
03-29-2013, 11:07 PM
These tutorials really helped me :D

Thief
04-30-2013, 09:07 AM
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.