SRL Archive - Help

Count color in dynamic area


rj

2013-01-25 17:44:37

So I was messing around with count color, and I was wondering how would I look for a count of color that appear within lets say a 5x5 pixel range anywere on the screen, instead of it just looking for count pixels in one area.

Best code I got is:

program new;
{$i srl/srl.simba}
const
TOL = 15;
ONE = 12761001; // each word is 40 14846307


var
CountOne, FileFind: Integer;

begin
MouseSpeed := 15;
ClearDebug;
// 0 0 1914 1041
CountOne := CountColorTolerance(ONE, 0, 0, 1914, 1041, TOL);

FileFind := CountOne/33;

Writeln('There are about ' + IntToStr(FileFind) + ' .jar documents on the desktop');
Writeln('There are ' + IntToStr(CountOne) + ' Pixels that are ' + IntToStr(ONE) + ' color');

end.

riwu

2013-01-25 19:13:20

So basically search the whole client and determine how many objects are within a range of color counts?
TPA can be more accurate here, by grouping the close ones as ATPA, then determine the number of objects by looping and checking the InRange(Length(ATPA), mincount, maxcount).

Wardancer

2013-01-25 19:26:27

To continue with what riwu said, nothing stops you from adding count color to your TPA function to further narrow down your search. You can turn a coordinate into a TBox.

Example:

Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));

This makes a TBox from a TPoint. You can use count colour after this.

All that being said, this might be going overboard and stick to only TPA if it works.

rj

2013-01-25 19:44:50

From: Wardancer
To continue with what riwu said, nothing stops you from adding count color to your TPA function to further narrow down your search. You can turn a coordinate into a TBox.

Example:

Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));

This makes a TBox from a TPoint. You can use count colour after this.

All that being said, this might be going overboard and stick to only TPA if it works.


I only know how to use TPA's to click a color like this:

program ClickSpot;
{$i srl/srl.simba}
Procedure FindBankTPA;
var
tmpCTS, l, r:Integer;
BankTPA:TPointArray;
begin
MouseSpeed:=15;
tmpCTS := GetToleranceSpeed;
SetColorToleranceSpeed(2);
SetToleranceSpeed2Modifiers(0.19, 0.91);
if FindColorsTolerance(BankTPA, 3954018, 8, 25, 518, 359, 3) then
begin
SetColorToleranceSpeed(tmpCTS);
SetToleranceSpeed2Modifiers(0.02, 0.02);
L := High(BankTPA);

//wait(randomrange(60, 100));
mmouse((BankTPA[r].x), (BankTPA[r].y), 2, 2);
wait(randomrange(100, 150));
clickmouse2(mouse_left);
wait(randomrange(2000, 2500));
end;
end;
begin
FindBankPA;
end.

How would i split those

Wardancer

2013-01-25 20:00:58

Your code basically defeat the purpose of a TPA function. TPA stands for an array of TPoints. The way you use it, you only use a single TP. You need to add a loop to go through each TP found.

Example:


function FindObject(var x, y : Integer; Obj: MSObject; X1, Y1, X2, Y2:integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if not LoggedIn then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Obj.Hue, Obj.Sat);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Obj.Col, X1, Y1, X2, Y2, Obj.Tol);
SortTPAFrom(TPA, point(MSCX,MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
if MP.x = 0 then
Continue;
Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
MMouse(MP.x,MP.y,4,4);
if(WaitUpText(Obj.UpText, 400))then
begin
x := MP.x; y := MP.y;
Result := True
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2,0.2);
end;

To add CountColor in your function, you call add a line in the loop similar to:


if CountColorTolerance(Color, Box.x1, Box.y1, Box.x2, Box.y2, Tolerance) < 100 then
Continue;

EDIT: Just to make sure "Continue;" is understood… what it does is basically skip the rest of the loop and go directly to the next TP. For example, if you were at the TPA[3] and you get it to Continue, it would jump straight to TPA[4] starting at the beginning of the loop.

This explanation is HORRIBLY worded, but hopefully you do understand.

rj

2013-01-25 21:59:52

From: Wardancer
Your code basically defeat the purpose of a TPA function. TPA stands for an array of TPoints. The way you use it, you only use a single TP. You need to add a loop to go through each TP found.

Example:


function FindObject(var x, y : Integer; Obj: MSObject; X1, Y1, X2, Y2:integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
if not LoggedIn then Exit;
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Obj.Hue, Obj.Sat);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Obj.Col, X1, Y1, X2, Y2, Obj.Tol);
SortTPAFrom(TPA, point(MSCX,MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
if MP.x = 0 then
Continue;
Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
MMouse(MP.x,MP.y,4,4);
if(WaitUpText(Obj.UpText, 400))then
begin
x := MP.x; y := MP.y;
Result := True
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2,0.2);
end;

To add CountColor in your function, you call add a line in the loop similar to:


if CountColorTolerance(Color, Box.x1, Box.y1, Box.x2, Box.y2, Tolerance) < 100 then
Continue;

EDIT: Just to make sure "Continue;" is understood… what it does is basically skip the rest of the loop and go directly to the next TP. For example, if you were at the TPA[3] and you get it to Continue, it would jump straight to TPA[4] starting at the beginning of the loop.

This explanation is HORRIBLY worded, but hopefully you do understand.


I get an error when i run it:


[Error] (5:46): Unknown type 'MSObject' at line 4
Compiling failed.

Program click;
{$i srl/srl.simba}

function FindObject(var x, y : Integer; Obj: MSObject; X1, Y1, X2, Y2:integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.19, 0.91);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3954018, 8, 25, 518, 359, 3);
SortTPAFrom(TPA, point(MSCX,MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
if MP.x = 0 then
Continue;
Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
MMouse(MP.x,MP.y,4,4);
begin
x := MP.x; y := MP.y;
Result := True
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2,0.2);
end;
Procedure Clickit;
begin
FindObject;
end;
begin
Clickit;
end.

Wardancer

2013-01-25 23:16:20

You have to understand that MSObject is a global record I use for my scripts. I'm feeling a bit lazy to explain so the easier way would be for you to remove the variables from the function and directly put them in the function itself. If you prefer, this is my generic TPA finding function. I use it for all my basic searches. Well, actually, I no more use this particular one, but it used to be my generic function so I could search multiple items with it.

rj

2013-01-26 00:06:49

From: Wardancer
You have to understand that MSObject is a global record I use for my scripts. I'm feeling a bit lazy to explain so the easier way would be for you to remove the variables from the function and directly put them in the function itself. If you prefer, this is my generic TPA finding function. I use it for all my basic searches. Well, actually, I no more use this particular one, but it used to be my generic function so I could search multiple items with it.


So.. what do i do with it?

Wardancer

2013-01-26 01:32:48

Simply remove all the variables after FindObject (the stuff in parenthesis) and add your clicking to the function.

rj

2013-01-26 10:48:43

I'm still getting a invalid number of parameters at line 38 when I cut them out:

Program click;
{$i srl/srl.simba}

function FindObject(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.19, 0.91);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3954018, 8, 25, 518, 359, 3);
SortTPAFrom(TPA, point(MSCX,MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
if MP.x = 0 then
Continue;
Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
MMouse(MP.x,MP.y,4,4);
begin
x := MP.x; y := MP.y;
Result := True
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2,0.2);
end;
Procedure Clickit;
begin
FindObject;
end;
begin
Clickit;
end.

Line 38

FindObject;

Justin

2013-01-26 10:51:18

From: rjj95
I'm still getting a invalid number of parameters at line 38 when I cut them out:

Program click;
{$i srl/srl.simba}

function FindObject(var x, y : Integer) : Boolean;
var
a : Integer;
TPA : TPointArray;
ATPA : T2DPointArray;
MP : TPoint;
tmpCTS : Integer;
Box : TBox;
begin
tmpCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.19, 0.91);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, 3954018, 8, 25, 518, 359, 3);
SortTPAFrom(TPA, point(MSCX,MSCY));
ATPA := TPAtoATPAEx(TPA, 15, 15);
for a := 0 to High(ATPA) do
begin
MP := MiddleTPA(ATPA[a]);
if MP.x = 0 then
Continue;
Box := IntToBox((MP.x - 20), (MP.y - 20), (MP.x + 20), (MP.y + 20));
MMouse(MP.x,MP.y,4,4);
begin
x := MP.x; y := MP.y;
Result := True
Break;
end;
end;

ColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2,0.2);
end;
Procedure Clickit;
begin
FindObject;
end;
begin
Clickit;
end.

Line 38

FindObject;


That's because you aren't sending the integers when you call FindObject as it isn't a procedure, it's a function.

Wardancer

2013-01-26 11:01:57

I guess there has to be a short explanation of what the information in parenthesis next to a procedure or a function means.

Let's take the original FindObject function:

function FindObject(var x, y : Integer; X1, Y1, X2, Y2:integer)          //Removed the record not to confuse you

Variables/information put in parenthesis can serve two purposes. One is to "feed" the function, telling it what to do. The other is to return a value (you'll see "var" before the actual variables in those cases). It goes without saying that you need to tell your function as many variables as the number of parameters it asks for else it just won't work. It'll need some feeding or something to give its feedback to.

In this particular case, you kept the var x, y in the FindObject function. Therefore, you absolutely MUST have a variable ready so the function gives you a feedback for these two variables. In other words, FindObject by itself can't work, but FindObject(x, y) would (assuming you defined x and y as variables.

I really hope that you'll understand this explanation and not just blindly copy the fix. It'll help a great deal into helping you make your own core functions for your scripts.

rj

2013-01-26 12:27:39

Lol, chris GTFO if your going to go onto the help section and expect people to know what their doing, im in the help section for a reason


Also, im still getting the same error when ever i try to do the function

Wardancer

2013-01-26 13:09:23

We explained exactly what you did wrong. I don't see how else I could explain it. Re-read our posts.