Using Simple CTS2/TPA's
Contents
- Intro
- What is a TPoint?
- What is a TPointArray?
- What is CTS2?
- Creating a Object-finding TPA Function
- Conclusion
Intro
Hello all, Welcome to my Simple TPA Tutorial! In this tutorial, I will teach you what a TPA is, and how to use one in runescape. This tutorial requires very little background knowledge. Knowledge on co-ordinates(Cartesian Plane), basic Pascal Script scripting, for..to..do loops and variables is assumed. This tutorial was made using Simba using the pascalscript interpreter(default). I'm sorry this tutorial is long, I tried to explain everything in depth and give lots of examples/diagrams. High-level scripters, this tutorial only focuses on basic TPA functions. This tutorial probably isn't for you. This is my first tutorial, so please give me advice on what to fix and work on!
What is a TPoint?
I'm sure many of you are wondering what exactly a TPoint is. If you aren't, head to the next section. Basically, a TPoint is a co-ordinate. It is an x value, and a y value, stored into one variable. A Tpoint equal to (2, 3) would be equal to this on a Cartesian plane:
However in Runescape, we use an inverted Cartesian plane. This means the x values still increment from left to right, but y values increment from top to bottom, rather then bottom to top like in Cartesian's plane. The (0, 0) point is in the top left-hand corner.
When using TPoints, you declare the variable like this:
Simba Code:
var
YourTPointNameHere:TPoint;
Thats all you really have to know about TPoints for this tutorial. Brace yourselves... The TPA section is coming.....
What is a TPointArray?
What is a TPA? Its a beast, all color object finding revolves around TPA's. Really, all a TPA is is a collection of TPoints, stored into one variable. What makes TPA's so amazing is the things we can do with them, the ways we can twist, shape, and altar them to fit our needs. In this tutorial, we wont go over any advanced TPA uses, just simple object finding methods. If I was to turn a TPA into a picture, it would look something like this.
Make sense? All a TPA is is a big bag of TPoints(not literally). Just like how a TPoint stores an x and y value, TPointArrays store Tpoints. Simple enough, right? Lets move on to CTS2.
What is CTS2?
CTS2? Its just come collection of letters and numbers right now. After you read and understand this tutorial, you will use CTS2 in every single color finding function you ever use for the rest of your life! Okay, that's a bit of an exaggeration, but I'm not kidding, CTS2 is the most useful thing in the world when you need to find colors accurately.
I guess I should explain what CTS means now, right? CTS is just a method of finding colors using tolerances, RGB values, hue and sat, etc. CTS stands for Color Tolerance Speed. Dont ask me what it means, I dont know either! Generally, a higher CTS is more accurate at finding color, which is why we will use CTS2 Today.
Also, before we begin, I should note I use ACA for testing and finding colors. ACA is downloadable here. If you don't know how to use ACA, check Yohojo's Tutorial. The only difference is that he uses the Generated code from ACA. We are big boys now, we make our own functions! Not only do custom functions show a higher skill level, they also function better, because you can customise them to do exactly what you want!
Open up ACA and find your way to something you want to find. Now before you start picking colors like you did in Yohojo's tutorial, pick CTS2 from the radiobuttons to the right.
Now pick your colors and play with them until you are pleased with the result. This is what my imp looked like after I finished with him.
Now take down these numbers here, write them down somewhere, we will use them in a few minutes. They are located right above the CTS selection radiobuttons.
Alright, now that we have those numbers written down somewhere, we can write our actual function that will find the imp(in my case). Start off with the default script, and creating a procedure called FindImp.
Simba Code:
program new;
{$i srl/srl.simba}
Procedure FindImp;
begin
end;
begin
SetupSRL
end.
Next, we need to tell the script what our current CTS is. We need this for after we finish using CTS2. Text finding, and other primary functions rely on CTS, so ALWAYS change CTS back to normal after you are finished. The simplest way of doing this is to assign the current CTS to a variable, often called tmpCTS. After doing that, We need to tell the script what CTS we are using. To do that, use:
Simba Code:
program new;
{$i srl/srl.simba}
Procedure FindImp;
var
tmpCTS:integer;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
end;
begin
SetupSRL
end.
Incase you didn't follow, I declared a variable named tmpCTS, then assigned tmpCTS to whatever the current CTS is. Next, we told the script we want to use CTS2. As of that moment, all color finding functions will use CTS2.
Now we need to set our hue and sat mods. What on earth are those??? They are just numbers that the script somehow uses in some fancy algorithm while finding colors for you. All you need to know is how to set it. To set it, do this:
Simba Code:
program new;
{$i srl/srl.simba}
Procedure FindImp;
var
tmpCTS:integer;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(hue, sat);
end; //when doing a decimal
//put 0 infront of it
begin //Good: 0.45 -Will work
SetupSRL //Bad: .45 -Will give an error
end.
Alright, now we've told our script to save the current CTS to a variable, set the CTS to 2 and set our super complicated modifiers. Whats next? Your color finding function! You can use findcolor, findcolortolerance, findcolorstolerance, whatever you want! Note that if ACA gave you a tolerance that wasn't 0, you have to use a tolerance version of the function.
We've made our function that finds our color, but what do we do now? Right after we find the colors, before we utilise them, or do anything else, we need to set our CTS back to 1. To do that, we use our tmpCTS variable. Also, we need to set the modifiers back to 0.02. This is the value used in text finding.
Simba Code:
program new;
{$i srl/srl.simba}
Procedure FindImp;
var
tmpCTS, x, y:integer;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(hue, sat);
FindColorTolerance(x, y, thecolorACAgaveus, MSX1, MSY1, MSX2, MST2, TolerancethatACAgaveus);
SetColorToleranceSpeed(tmpCTS); //RIGHT AFTER we find our colors, we
SetToleranceSpeed2Modifiers(0.02, 0.02); //Change the CTS back.
mmouse(x, y, 1, 1);
end;
begin
SetupSRL
end.
And thats all there really is to CTS. If you did everything right, your function will find exactly what ACA highlighted when you picked your colors.
Note: Finding colors using ACA does not require credits in a script or members application. You only need to credit if you use ACA's Generated function. If you don't understand CTS2, read it over again, then feel free to ask me.
Creating an Object-finding TPA function
This is what everyone is here for, no? You want to incorporate TPA object finding into your script. I'm here to show you how. In my tutorial, I'll be using TPA's to find the Imp I used in the CTS2 section. You can use whatever you want.
Alright, bring up the script we used in the CTS2 section, but remove the findcolor bit. It should look like this.
Simba Code:
program new;
{$i srl/srl.simba}
Procedure FindImp;
var
tmpCTS, x, y:integer;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(hue, sat);
SetColorToleranceSpeed(tmpCTS); //RIGHT AFTER we find our colors, we
SetToleranceSpeed2Modifiers(0.02, 0.02); //Change the CTS back.
end;
begin
SetupSRL
FindImp;
end.
Alright, lets start by collecting our TPoints, and placing them into a TPA. How do we do that? It's actually very very simple, its what you do with the TPA that is complicated. First, declare a Local TPA variable, name it whatever you want. In order to find colors and put the results into a TPA, we will use FindColorsTolerance. Whenever filling TPA's, you want to use the plural forms of the FindColor functions. For example; Use FindColors instead of FindColor, FindcolorsTolerance instead of FindColorTolerance, etc.. The parameters are as follows:
FindColorsTolerance(TPointArray, Color, xs, ys, xe, ye, tol);
TPointArray is where you put the name of your TPA. Color is the color you got in ACA. xs, ys, xe, and ye are MSX1, MSY1, MSX2, MSY2, assuming you are finding an object on the Main screen. Tolerance is the tolerance ACA found for you. Plug in your numbers, and your script should look like this so far. Note: I've plugged my numbers in, so it wont look identical to yours.
Simba Code:
program new;
{$i srl/srl.simba}
Procedure FindImp;
var
tmpCTS:integer;
ImpTPA:TPointArray;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.08, 0.95); //Ive plugged in my hue and sat mods. Plug in your own here.
FindColorsTolerance(ImpTPA, 1911631, MSX1, MSY1, MSX2, MSY2, 8);
SetColorToleranceSpeed(tmpCTS); //RIGHT AFTER we find our colors, we
SetToleranceSpeed2Modifiers(0.02, 0.02); //Change the CTS back.
end;
begin
SetupSRL
FindImp;
end.
Now after we return the CTS and modifiers to normal, we can start playing around with our TPA. In this tutorial, I will only go through very basic TPA methods. If you are interested in learning more, I suggest you look at the WizzyPlugin. Its a huge(I'm not lying) list of TPA functions that will do anything you ever imagined to a TPA. Back on topic, to start, we will create a for..to..do loop. This will go through points in the TPA, stopping when we find a point with the correct uptext. I'll show you what it will look like, then I'll explain everything.
Simba Code:
program new;
{$i srl/srl.simba}
Procedure FindImp;
var
tmpCTS, i, l, r, counter:integer;
ImpTPA:TPointArray;
begin
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.08, 0.95); //Ive plugged in my hue and sat mods. Plug in your own here.
FindColorsTolerance(ImpTPA, 1911631, MSX1, MSY1, MSX2, MSY2, 8);
SetColorToleranceSpeed(tmpCTS); //RIGHT AFTER we find our colors, we
SetToleranceSpeed2Modifiers(0.02, 0.02); //Change the CTS back.
L := High(ImpTPA)
marktime(counter);
for i := 0 to L do
begin
r := random(L);
wait(randomrange(60, 200));
mmouse(ImpTPA[r].x, ImpTPA[r].y, 2, 2);
if waituptext('mp', 300) then
Break;
if timefrommark(counter) > 3000 then
begin
writeln('We failed to find the Imp!');
Terminatescript;
end;
end;
writeln('We found the imp!');
clickmouse2(mouse_right);
end;
begin
SetupSRL
FindImp;
end.
Alright, there is the finished script. It will fill a TPA with colors found using CTS2, then go through random points in the TPA until it finds the imp or time out(IMPORTANT FAILSAFE). Lets dissect this code so we understand what every bit means.
Simba Code:
L := High(ImpTPA)
marktime(counter);
Lets start with the first line. High will count how many items there are in an array, and return with the final count. In other words, it will figure out how many TPoints are in our TPA. Marktime(counter) is a very simple failsafe that most of you should know. I'm simply starting the timer for the failsafe I will use in the for..to..do loop.
Very simple for to do loop. Everything between the following begin and matching end will be looped through until i = L.
Simba Code:
r := random(L);
wait(randomrange(60, 200));
First of all, r := random(L) just gives r a random value between 0 and L. We use this to pick a random point in our TPA. When you get more advanced, You can sort your TPA's based on size, shape, and a whole bunch of other things. For now though, we will just use a random point. The next line is a wait. You must have this. It prevents the mouse from going 100 miles an hour between points in your TPA by having a small wait before every mouse movement.
Simba Code:
mmouse(ImpTPA[r].x, ImpTPA[r].y, 2, 2);
By far the most complicated part of the script. Everything else has been child's play. This is where we separate the boys from the men. First off, this is a mouse movement using mmouse. I thought I should clear that before I start with the parameters. For our X parameter, we used ImpTPA[r].x. ImpTPA is the name of our TPA, and the number in square brackets is the number of the TPA. Think of it this way. Every TPoint in the TPA has a number. They are all in order of when they were found, and they are all given a number. 0, 1, 2 and so on. Here's a picture of some people in a line, just like TPoints in a TPA.
I hope that cleared up the number in the bracket. Every point in the TPA has a number, so we picked a random number(r) to use a random TPoint.
Next up is the .x and .y part. This is known as the dot operator. The dot operator basically splits the variable into smaller pieces. Our TPoint that we have just selected(using ImpTPA[r]) is made of two smaller values; An x value, and a y value. When you press . after ImpTPA[r], a small menu should pop up showing you the small pieces inside of the TPoint. For x in mmouse, pick x, for y, pick y.the last two parameters are randomness. They aren't required since using TPA's already involves randomness. However, a small amount of randomness is suggested. It just ensures you aren't always clicking the same color. Well, thats the tough part out of the way, lets finish with some easier stuff.
Simba Code:
if waituptext('mp', 300) then
Break;
WaitUptext will wait for the uptext "mp" for 300ms. If it doesn't find it, we will continue sifting through our TPA. If we do find the uptext, we will break out of the for..to..do loop. The rest of the script is simple enough, I dont think I have to explain it anymore. Lets test this and see what happens. Incase you don't know, Marktime will start a timer in miliseconds using the variable in the parameters. Timefrommark will check how long its been since the timer has started.
Turns out his uptext wasn't Imp. After fixing that, it worked perfectly, first try!
Conclusion
Thanks for reading my (Very large)CTS2/TPA tutorial! Hopefully you gained something out of this. Let me know what you thought, pro's, con's, suggestions, all that fun stuff. If you learned something, post below, or just rep me, either work! This TPA usage is very simple, I might make more advanced TPA tutorials in the future, but this is enough to find any normal NPC/bank. Looking for more advanced TPA usage? I'd suggest NKN's TPA[Explained] Tutorial. It will teach you the basics of ATPA's and SplitTPAex, a very useful ATPA function.
~Footy