PDA

View Full Version : [TUT]Picking Colors for TPointArrays



FreakyMonkey
01-11-2009, 12:24 AM
How To Pick Proper Colors to Find Certain Objects Using TPAs

**Note this requires some fundamental knowledge of TPAs and some knowledge of the WizzyPlugin functions!

This tutorial might not be extremely necessary, but it helps for those new to TPAs and how to exactly pick colors when finding certain objects.

Introduction

Have you ever wondered how to find a certain object when there is just a butt load of that same color? This tutorial will give you some advice on how to accomplish just that :f:.

Say for example that we are trying to find the spinning wheel in the Lumbridge Castle (boxed "red" in the picture below) based on the color 3293519, which is brown. You decide that since the wheel has the most of that color it would be the most likely option, right?

WRONG! Take a look at this screenshot. The places marked in blue are areas in which that color recurs.

http://i41.tinypic.com/14y0txc.jpg

Poory boxed but conveys the message :D.



Color Counting Helper

Before we continue however to find out how many recurring instances of the color found use this procedure to find the length of the TPA.

program New;

const
Color = {color};
Tolerance = {tolerance};

procedure ColorCounter;

Var TPA: TPointArray;

begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Color, MSX1, MSY1, MSX2, MSY2, Tolerance);
Writeln('Length of TPA is ' +inttostr(length(TPA)));
end;

begin
ColorCounter;
end.

This is a basic procedure that will count the TPA number. This is handy to see if you really need to spiral from a certain location.

Finding Colors with FindColorsSpiralToleracne

Anyway back to our major dilema

So how do we find that bloody spinning wheel then? :duh: That's why we have this function here.

FindColorsSpiralTolerance(x, y: Integer; var Points: TPointArray; color, xs, ys, xe: Integer; Tolerance: Integer);

The key part in here is the "x and y". This denotes where to starts searching for TPoints to add your TPointArray spirally outward. You guys might have seen that people often use MSCX and MSCY for these points, which in essense starts searching for points with the denoted colors from the middle of the main screen (MSC = Main Screen Center btw :D).

Finding Colors with FindColorsSpiralTolerance with a Fixed TPoint

Look back at the picture shown above and you might notice that when you spiral from the center there are still four different objects that have added to your TPA! (the god damn chair, door, the chest, and the spinning wheel)

Luckily we have another solution. It's this procedure...

SortTPAFrom(var a: TPointArray; From: TPoint);

This function organizes a TPA from that TPoint. From here we could define a TPoint CLOSER to the wheel so we can have an easier time finding the wheel.

So now we have to specify that certain point, but this point has to be EASILY distinguished from other color points because if the color recurs like the previous recurring point we'll be back at stage one lol.

Look back at the picture and notice the blue curtains (marked by magenta box) that happen to be right next to the wheel, thankfully. Since the color of the curtain, (7355682, is the only color of its kind on the screen it works as a perfect starting point.

Example....
[

if FindColorTolerance(x, y, 7355682, MSX1, MSY1, MSX2, MSY2, 10) then
FindColorsSpiralTolerance(x, y, TPA, 3293519, MSX1, MSY1, MSX2, MSY2, 10);

From here you can loop through your points (your wheel points should be first) using uptext or w/e to find the wheel.

Of course you could format this any way you want,even by using another TPA to find the curtain colors or something.

Here is another example.

http://i43.tinypic.com/2m2hmci.jpg

Look at this closed door. This has many parts that share the same color with a lot of things, but if you look carefully you'll see that the door KNOB doesn't have the same color as any of the others. After running the TPA counter I found that the color had a TPA length of 4 - 13 on the entire screen!

THis is an example of a very good choice for picking colors. And is also handy for making sure the door was closed or opened.

The same colors still apply when the door is opened too from the same angle!

http://i41.tinypic.com/o05anm.jpg

After running the Door TPA counter the range was from 2 - 10!

In summation by picking colors that are unique to the main screen you'll have less work to do and ultimately more accuracy


Limiting the Size of a TPA Using T2DPointArrays

Credit to EvilChicken! for giving me this idea :D

For this example look back at the picture above. Notice a small white cloth at the tip of the wheel? After you see this you'll probably be tempted to choose a point point from here with good reason of course, BUT notice was directly diagonal to the white cloth.... A FREAKIN HUGE ASS WHITE BED. So what do we do? Luckily we have 3 different TPA separating functions.

SplitTPA(arr: TPointArray; Dist: LongInt): T2DPointArray;
//Splits the TPA by distance

TPAtoATPA(TPA: TPointArray; Dist: LongInt): T2DPointArray;
//Also splits the TPA by distance but in a different manner

TPAtoATPAEx(TPA: TPointArray;w, h: LongInt): T2DPointArray;
//Splits the TPA by height and width. Therefore the range of each TPA will be organized into a box shape rather than a circular shape like TPAtoaTPA and SPlitTPA. Helpful to find "box-shape" colored areas.


Once you split the points of the color white, 14737636, you should end up with many different TPAs (the number depending on the parameters you specified). Now it would be wise to get the Middle TPoint of each and loop through the tpas like that. For example.

FindColorsSpiralTolerance(x, y, TPA, 14737636, MSX1, MSY1, MSX2, MSY2, 10);
if not length(TPA) > 0 then Exit;
TTPA :=SplitTPA(TPA, 10); //The exact distance encompassed by the points idk.
//TTPA := TPAtoaTPA(TPA, 10);
//TTPA := TPAtoaTPAEx(TPA, 6, 10); parameters should be close
for i := 0 to High(TTPA) - 1 do
begin
MiddleTPAEx(TTPA[i], x, y);
MMouse(x, y, 2, 2);
Wait(randomrange(400, 800));
if IsUpText('heel')then
begin
Mouse(x, y, 0, 0, true);
Exit;
end;
end;

You can take this a step further and try to find a range for the amount of colors should be found in each TPA, which would provide for a more accurate result.


Combining Colors into a TPAs and Using T2DPointArrays

This is my most favorite way of finding and picking particular colors for TPAs because its really accurate :f: . This involves using this function.

CombineTPA(TPA: TPointarray; TPA2: TPointArray): TPointarray;

This procedure combines two TPointArrays into one single TPointArray;

Why would you want to use this? Because you can add DIFFERENT colors into one TPointArray thats why! Say for example you have the wheel and on the wheel there are 2 predominant colors (13355985, 14408671) and you want to find a high concentration of those colors, which would most likely contain the wheel.

FindColorsSpiralTolerance(MSCX, MSCY, TPA, 13355985, MSX1, MSY1, MSX2, MSY2, 10);
FindColorsSpiralTolerance(MSCX, MSCY, TPA2, 14408671, MSX1, MSY1, MSX2, MSY2, 10);
CTPA := CombineTPA(TPA, TPA2);
CTTPA := TPAtoaTPAEx(CTPA, 15, 15);
for i := 0 to High(CTTPA)do
begin
MiddleTPAEx(CTTPA[i], x, y);
MMouse(x, y, 1,1);
Wait(RandomRange(400, 800));
if IsUpText('heel')then
begin
Mouse(x, y, 0, 0 , true);
Exit;
end;
end;

The first three function are rather extraneous since you could just do FindColorsSpiralTolerance with the same TPA without choosing another and combining it, but I used this function to portray a more simplistic circumstance. There will be times when you actually need different TPAs and then have to combine them. Also, I created this function that comines the TPAs for you using AS MANY colors as you want in a TIntegerArray.

function AddTPAS(XX, YY: Integer; Var TPA: TPointArray; Colors: TIntegerArray; Tol, X1, Y1, X2, Y2: Integer): Boolean;

Var v: Integer;
Var TPAS: Array of TPointArray;
Var CT: Integer;

begin
Result := False;
if Length(Colors) < 0 then Exit;
SetArrayLength(TPAS, Length(Colors));
CT := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
for v := 0 to Length(Colors) -1 do
FindColorsSpiralTolerance(XX, YY, TPAS[v], Colors[v], X1, Y1, X2, Y2, Tol);
ColorToleranceSpeed(CT);
TPA := CombineTPA(TPAS[0], TPAS[1]);
if Length(Colors) = 2 then
begin
Result := True;
Exit;
end;
for v := 2 to High(TPAS) - 1 do
TPA := CombineTPA(TPA, TPAS[v]);
if Length(TPA) = 0 then Exit;
Result := True;
end;

You guys can use this if you decide to use the TPA combination method. It will make the job much easier. :f: :f:

Rep + and Rate the thread!

NCDS
01-11-2009, 12:33 AM
Very Nice TUT!

Should definately be stickied!

FreakyMonkey
01-11-2009, 12:43 AM
Thanks, still have a lot more to say about the subject. Hopefully this is a good starting point and not too confusing.

NCDS
01-11-2009, 12:59 AM
I think you explained things very well so far.

Smarter Child
01-11-2009, 01:09 AM
Nice TUT, you explained this very well. Thank God for the blue curtains:p

EvilChicken!
01-11-2009, 01:11 PM
function FindWheel: Boolean;
var
I, X, Y: Integer;
WhiteColor, BrownColor: TPointArray;
ATPA: T2DPointArray;

begin
Result := False;
if not LoggedIn then exit;
FindColorsSpiralTolerance(MSCX, MSCY, WhiteColor, 14737636, MSX1, MSY1, MSX2, MSY2, 10);
ATPA := TPAtoATPAEx(WhiteColor, 6, 3);
for I := 0 to High(ATPA) do
if InRange(Length(ATPA[I]), 8, 18) then
if MiddleTPAEx(ATPA[I], X, Y) then
if FindColorsTolerance(BrownColor, 4478308, X - 15, Y - 15, X + 15, Y + 15, 12) then
if InRange(Length(BrownColor), 80, 200) then
begin
MMouse(X, Y, 0, 0);
Wait(200 + Random(175));
if Pos('inning', RS_GetUpText) > 0 then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, True);
Result := True;
Exit;
end;
end;
end;

This is an old function I took out of a flax spinner I was working on a long time ago when I had a members account on RuneScape.

As you see, it searches for the tiny white box that is "in front of" the actual wheel on the spinning wheel. This is a simple, yet powerful object finding technique that I haven't seen been used too often. This technique, along with length checks, is a nice way of finding objects that have multiple colors. :)

Baked0420
01-11-2009, 01:55 PM
Wow never thought of something like this before, thanks FreakyMonkey. This will help a lot when I make my TPA's, and I was almost thinking the same as EvilChicken at first, I thought you were just gonna say something as simple as use the white color, and tell people to search for a more unique color on the object, but I was close to how you do it, search for a different object nearvy with unique color, then your object. Nice tut so far, can't wait to see the rest of this.

FreakyMonkey
01-11-2009, 06:29 PM
THanks guys. Probably won't be able to finish until tomorrow or so but I'll try my best.

BTW: EvilChicken I liked how you did that with the white cloth. I tried to use that but it kept on getting the bed instead :(. Do you mind if I use your example of T2DPointArrays to add to my tut?

Floor66
01-11-2009, 08:02 PM
I need a tut on how to use these splitting functions :p
I always get confused with tons of Points in my array and have no clue on how to quickly find the correct one.

FreakyMonkey
01-11-2009, 09:50 PM
Oh, you can just mess around with it I guess. Usually what I do when I split TPAs is to loop through them by using the MiddleTPAEx function. Usually helps instead of looping through all the points.

FreakyMonkey
02-12-2009, 05:49 AM
Sorry for the double post, but couldn't find this tutorial in the acutal intermediate forum but found with search?

Weird, could a moderator help me to put this back into the main forum?

EvilChicken!
02-12-2009, 07:17 AM
BTW: EvilChicken I liked how you did that with the white cloth. I tried to use that but it kept on getting the bed instead :(. Do you mind if I use your example of T2DPointArrays to add to my tut?

Sorry, just saw your post now. (How convenient.)
Feel free to use that example, but remember to tell that using length checks is crucial when this method. Demonstrate the use of InRange.

Look at this function.

function FindWheel: Boolean;
var
I, X, Y: Integer;
WhiteColor, BrownColor: TPointArray;
ATPA: T2DPointArray;

begin
Result := False;
if not LoggedIn then exit;
FindColorsSpiralTolerance(MSCX, MSCY, WhiteColor, 14737636, MSX1, MSY1, MSX2, MSY2, 10);
ATPA := TPAtoATPAEx(WhiteColor, 6, 3);
for I := 0 to High(ATPA) do
if InRange(Length(ATPA[I]), 8, 18) then
if MiddleTPAEx(ATPA[I], X, Y) then
if FindColorsTolerance(BrownColor, 4478308, X - 15, Y - 15, X + 15, Y + 15, 12) then
if InRange(Length(BrownColor), 80, 200) then
begin
MMouse(X, Y, 0, 0);
Wait(200 + Random(175));
if Pos('inning', RS_GetUpText) > 0 then
begin
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, True);
Result := True;
Exit;
end;
end;
end;

I have a feeling that I've posted this function in this thread before, but this is very important nevertheless. Just notice how I use InRange here for the APTA's length check, it is this method I'm talking about.

And by the way, I couldn't find your tutorial in the intermediate section either O__o (Though, I "ctrl+f"-ed it, but still -- that should've made me find it.) If no mod sees this, just PM a mod/admin.

markuska815
02-12-2009, 08:41 AM
good tut... a lot of useful information that you explained very well