I haven't written a tutorial in a while, so here we go.
This stuff is mid level, semi advanced stuff (It's hard to learn the first time, but then it's easy as pie after that.) I will teach you how to make a basic, yet effective TPA function that will do wonders for you~ (No more FindObjCustom =P)
Okay so.. We must start somewhere, no?
Part 1 - Setting Up The TPA and such
Okey, copy this little snippet of script here. It's a very basic setup right now, but WILL be expanded on.
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
begin
end;
begin
end.
We'll use the x and y to return the Mouse's (you got it) x and y coordinates for actual clicking. So far, so good!
Now, we will add our variables.
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
var
CTS, I: Integer; //CTS will store the ColorToleranceSpeed before we change it, for later.
TPA: TPointArray; //The TPointArray in which all Coordinates which are found later will be stored
ATPA: Array of TPointArray;
begin
end;
begin
end.
Not lost yet? Good. If you don't know what TPointArrays are, look it up, they're a simple concept, and I don't feel like explaining. Just know that they are VERY important to we the cheaters (and therefore, it must be effective, no?)
Now, here's where we get into the bad parts..
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
var
CTS, I: Integer; //CTS will store the ColorToleranceSpeed before we change it, for later.
TPA: TPointArray; //The TPointArray in which all Coordinates which are found later will be stored
ATPA: Array of TPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2); //Sets the color tolerance speed to 2 so we can do HSL tolerance stuff
end;
begin
end.
ColorToleranceSpeed? What is that?
Well, good question. I'm not 100% on it, I just know that 0 is the fastest, but the least accurate, and 2 is the best, and the most accurate. 1 is the middle ground, but most everyone uses 2 anywho.
Why can't we keep it at 2 all the time, then? Text finding is not compatible with ColorToleranceSpeed(2), because 2 deals with Hue and Saturation modifiers.
Confused? Keep reading, I'll explain in a sec.
First, paste this into a new script in scar, and SAVE IT. You will need it if you continue to use TPA's.
SCAR Code:
program New;
//By Mastaraymond
//0 = Min
//1 = Max
var
I,II : integer;
RGBColor : Array[1..3] of Integer;
RGB : Array[0..1] of Array[1..3] of Integer;
XYZColor, HSLColor : Array[1..3] of Extended;
HSL,XYZ : Array[0..1] of Array[1..3] of Extended;
Colors : TIntegerArray;
Strings : Array[0..9] of String;
Procedure Init;
begin;
Colors := [];
end;
begin
Init;
For I:= 1 to 3 do
begin;
Writeln('');
RGB[0][i] := 255;
HSL[0][i] := 255; //Max is 240?
XYZ[0][i] := 255; //Max is ...?
end;
Strings[1] := 'R: ';
Strings[0] := ' ';
Strings[2] := 'G: ';
Strings[3] := 'B: ';
Strings[4] := 'H: ';
Strings[5] := 'S: ';
Strings[6] := 'L: ';
Strings[7] := 'X: ';
Strings[8] := 'Y: ';
Strings[9] := 'Z: ';
For I:= 0 to High(Colors) do
begin;
Strings[0] := Strings[0] + Padr('Color: '+inttostr(Colors[i]),16) +' | ';
ColortoRGB(Colors[i],RGBColor[1],RGBColor[2],RGBColor[3]);
ColortoHSL(Colors[i],HSLColor[1],HSLColor[2],HSLColor[3]);
ColortoXYZ(Colors[i],XYZColor[1],XYZColor[2],XYZColor[3]);
For II:= 1 to 3 do
begin;
RGB[0][II] := Min(RGBColor[II],RGB[0][II]);
RGB[1][II] := Max(RGBColor[II],RGB[1][II]);
HSL[0][II] := MinE(HSLColor[II],HSL[0][II]);
HSL[1][II] := MaxE(HSLColor[II],HSL[1][II]);
XYZ[0][II] := MinE(XYZColor[II],XYZ[0][II]);
XYZ[1][II] := MaxE(XYZColor[II],XYZ[1][II]);
end;
For II := 1 to 3 do
Strings[II] := Strings[II] +Padr(IntToStr (RGBColor[II]),16) +' | ';
For II := 4 to 6 do
Strings[II] := Strings[II] +Padr(FloatToStr(HSLColor[II-3]),16) +' | ';
For II := 7 to 9 do
Strings[II] := Strings[II] +Padr(FloatToStr(XYZColor[II-6]),16) +' | ';
end;
For I:= 0 to 9 do
Delete(Strings[i],Length(Strings[i])-2,3);
For I:= 0 to 9 do
begin;
if (I = 1) or (I = 4)or (I = 7) then Writeln('');
Writeln(Strings[i]);
end;
Writeln('');
Writeln('Highest RGB values = R: '+ Padr(FloatToStr(RGB[1][1]),3) + ' | ' +'G: '+ Padr(FloatToStr(RGB[1][2]),3) + ' | ' +'B: '+ Padr(FloatToStr(RGB[1][3]),3) );
Writeln('Lowest RGB values = R: '+ Padr(FloatToStr(RGB[0][1]),3) + ' | ' +'G: '+ Padr(FloatToStr(RGB[0][2]),3) + ' | ' +'B: '+ Padr(FloatToStr(RGB[0][3]),3) );
Writeln('Differ RGB values = R: '+ Padr(IntToStr(RGB[1][1] - RGB[0][1]),3) + ' | G: '+ Padr(inttostr(RGB[1][2] - RGB[0][2]) ,3) + ' | B: '+Padr(inttostr(RGB[1][3] - RGB[0][3]),3));
Writeln('Middle RGB values = R: '+ Padr(IntToStr((RGB[1][1] + RGB[0][1]) div 2),3) + ' | G: '+ Padr(inttostr((RGB[1][2] + RGB[0][2]) div 2),3) + ' | B: '+Padr(inttostr((RGB[1][3] + RGB[0][3]) div 2),3));
Writeln('Middle RGB color = ' + IntToStr(RGBToColor((RGB[1][1] + RGB[0][1]) div 2,(RGB[1][2] + RGB[0][2]) div 2,(RGB[1][3] + RGB[0][3]) div 2)));
Writeln('');
Writeln('Highest HSL values = H: '+ Padr(FloatToStr(HSL[1][1]),16) + ' | ' +'S: '+ Padr(FloatToStr(HSL[1][2]),16) + ' | ' +'L: '+ Padr(FloatToStr(HSL[1][3]),16) );
Writeln('Lowest HSL values = H: '+ Padr(FloatToStr(HSL[0][1]),16) + ' | ' +'S: '+ Padr(FloatToStr(HSL[0][2]),16) + ' | ' +'L: '+ Padr(FloatToStr(HSL[0][3]),16) );
Writeln('Differ HSL values = H: '+ Padr(FloatToStr(HSL[1][1] - HSL[0][1]),16) + ' | S: '+ Padr(FloatToStr(HSL[1][2] - HSL[0][2]) ,16) + ' | L: '+Padr(FloatToStr(HSL[1][3] - HSL[0][3]),16));
Writeln('Middle HSL values = H: '+ FloatToStr((HSL[1][1] + HSL[0][1]) div 2) + ' | S: '+ FloatToStr((HSL[1][2] + HSL[0][2]) div 2) + ' | L: '+FloatToStr((HSL[1][3] + HSL[0][3]) div 2));
Writeln('Middle HSL color = ' + IntToStr(HSLToColor((HSL[1][1] + HSL[0][1]) div 2,(HSL[1][2] + HSL[0][2]) div 2,(HSL[1][3] + HSL[0][3]) div 2)));
Writeln('');
Writeln('Highest XYZ values = X: '+ Padr(FloatToStr(XYZ[1][1]),16) + ' | ' +'Y: '+ Padr(FloatToStr(XYZ[1][2]),16) + ' | ' +'Z: '+ Padr(FloatToStr(XYZ[1][3]),16) );
Writeln('Lowest XYZ values = X: '+ Padr(FloatToStr(XYZ[0][1]),16) + ' | ' +'Y: '+ Padr(FloatToStr(XYZ[0][2]),16) + ' | ' +'Z: '+ Padr(FloatToStr(XYZ[0][3]),16) );
Writeln('Differ XYZ values = X: '+ Padr(FloatToStr(XYZ[1][1] - XYZ[0][1]),16) + ' | Y: '+ Padr(FloatToStr(XYZ[1][2] - XYZ[0][2]) ,16) + ' | Z: '+Padr(FloatToStr(XYZ[1][3] - XYZ[0][3]),16));
Writeln('Middle XYZ values = X: '+ FloatToStr((XYZ[1][1] + XYZ[0][1]) div 2) + ' | Y: '+ FloatToStr((XYZ[1][2] + XYZ[0][2]) div 2) + ' | Z: '+FloatToStr((XYZ[1][3] + XYZ[0][3]) div 2));
Writeln('Middle XYZ color = ' + IntToStr(XYZToColor((XYZ[1][1] + XYZ[0][1]) div 2,(XYZ[1][2] + XYZ[0][2]) div 2,(XYZ[1][3] + XYZ[0][3]) div 2)));
WritelN('');
end.
I'll tell you what you need it for in a minute, so just hang on to your britches, kiddo.
So, we want to find something, right? Well, for that, we need colors. Go ahead, choose some colors from something or another. Be it from a tree, or a Lesser Demon. It doesn't really matter. Just get 3-5 different colors to make this work as well as it can.
Now, in that script I just had to paste in, find where it says Colors := [];
Paste in your 3-5 colors, separated by a comma (,);
Now click run. Like magic, things popped up in our Debug Box! Oh yay~
Find where it says Differ HSL Value. Everything surrounding this is important.
Okay. First, we need to change something in the TPA finding script we're developing. We're going to add a nice little thing we call... *drumroll* SetColorSpeed2Modifers.
YAY!
This sets the Hue and Saturation modifiers used for finding colors with tolerance. You'll see...
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
var
CTS, I: Integer; //CTS will store the ColorToleranceSpeed before we change it, for later.
TPA: TPointArray; //The TPointArray in which all Coordinates which are found later will be stored
ATPA: Array of TPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2); //Sets the color tolerance speed to 2 so we can do HSL tolerance stuff
SetColorSpeed2Modifiers(HueMod, SatMod);
end;
begin
end.
It only has those two modifiers, so it's not that bad.
Now comes the math time.
Remember that info in the debug text box? Well, we'll need to do some stuff.
Here's what you need to do.
Divide H by L to get = HueMod
Divide S by L to get = SatMod
L is your Tolerance (rounded up)
Middle HSL color is the color (You'll need this and Tolerance in a sec.)
Remember, all these values are in Differ HSL values, after putting in the colors of whatever you did. At this point, you should almost understand what I'm talking about.
Put in your values for HueMod and SatMod. I will make up some for mine.
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
var
CTS, I: Integer; //CTS will store the ColorToleranceSpeed before we change it, for later.
TPA: TPointArray; //The TPointArray in which all Coordinates which are found later will be stored
ATPA: Array of TPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2); //Sets the color tolerance speed to 2 so we can do HSL tolerance stuff
SetColorSpeed2Modifiers(.76, .55);
end;
begin
end.
So far, so good! Now..
We find the color.
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
var
CTS, I: Integer; //CTS will store the ColorToleranceSpeed before we change it, for later.
TPA: TPointArray; //The TPointArray in which all Coordinates which are found later will be stored
ATPA: Array of TPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2); //Sets the color tolerance speed to 2 so we can do HSL tolerance stuff
SetColorSpeed2Modifiers(.76, .55);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, YourColorHere, MSX1, MSY1, MSX2, MSY2, Tolerance); //For tolerance, put in your own tolerance. MSCX and MSCY are the starting points in the center of the mainscreen. MSX1, MSY1, etc. are the outside of the Main Screen.
end;
begin
end.
Make sure it's FindColorsSpiralTolerance, and not FindColorSpiralTolerance. If you don't understand this, then .
This will find every coordinate within range of your colors in the Main Screen and then store it in TPoints in an array, hence TPointArray. But, right now, it's pretty dis organized, just a jumble of TPoints all over the place. That's why we group them into separate TPA's in a Array of TPA's. We do this thus:
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
var
CTS, I: Integer; //CTS will store the ColorToleranceSpeed before we change it, for later.
TPA: TPointArray; //The TPointArray in which all Coordinates which are found later will be stored
ATPA: Array of TPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2); //Sets the color tolerance speed to 2 so we can do HSL tolerance stuff
SetColorSpeed2Modifiers(.76, .55);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, YourColorHere, MSX1, MSY1, MSX2, MSY2, Tolerance); //For tolerance, put in your own tolerance. MSCX and MSCY are the starting points in the center of the mainscreen. MSX1, MSY1, etc. are the outside of the Main Screen.
ColorToleranceSpeed(CTS); //Make sure you do this after you're done color finding, so text finding will work again.
ATPA := TPAToATPAEx(TPA, 15, 15);
end;
begin
end.
Now, we have an ATPA with all the TPA's in it. Here comes the, hopefully, final part. Ish.
The Final Part ISH!
Okay, so. Now we need to make it see if it's what we're looking for (If it's a lesser or if it' s a torch; it has to know the difference somehow!) Hopefully you picked unique colors from whatever you're finding, but whatever floats your boat!
Okay we'll use a For To Do statement to deal with this.
I tried to explain it as well as I could in the script, please bear with me, it's 11 at night and I'm bushed
SCAR Code:
program TPALearningTut;
{.include SRL/SRL.scar}
function TPAFinder(x, y: Integer): Boolean;
var
CTS, I: Integer; //CTS will store the ColorToleranceSpeed before we change it, for later.
TPA: TPointArray; //The TPointArray in which all Coordinates which are found later will be stored
ATPA: Array of TPointArray;
begin
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2); //Sets the color tolerance speed to 2 so we can do HSL tolerance stuff
SetColorSpeed2Modifiers(.76, .55);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, YourColorHere, MSX1, MSY1, MSX2, MSY2, Tolerance); //For tolerance, put in your own tolerance. MSCX and MSCY are the starting points in the center of the mainscreen. MSX1, MSY1, etc. are the outside of the Main Screen.
ColorToleranceSpeed(CTS); //Make sure you do this after you're done color finding, so text finding will work again.
ATPA := TPAToATPAEx(TPA, 15, 15);
For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], x, y); //Returns the middle coords of the current TPA in the ATPA
MMouse(x, y, 2, 2); //Moves mouse over the object
If(IsUpTextMultiCustom(['your uptext(s) here'])) then
begin
Result := True;
GetMousePox(x, y); //Sets the x and y values for future use (Like clicking)
Break; //Exits the For To Do statement so it doesn't keep moving around looking for the object
end;
end;
end;
begin
end.
Now, it will look around for the object, starting from the middle out (Simply because of FindColorsSpiralTolerance) When it finds it, it will stop looking and hover the mouse right there (or not, depending on what you do next)
Usage
So, you found the object. What now?
Simple!
You can just put in another procedure that will Click on the object then wait, or do antirandoms/antiban. It's all downhill from here. ^.^
Afterword
I learned this from a few different tutorials, one of which I got the color script thing. It's mastaraymond's, not mine. Just for copyright stuff, y'know.
Thanks for reading my tutorial. I probably didn't explain well enough in some places, so please post here with questions if you have them. I just thought I'd share this with you, since it's so useful.
Cheers,
ProphesyOfWolf