SRL Archive - Research & Development Lounge

My gift to the community


Cigue

2010-02-12 16:47:01

here is a short but reliable object finder :) it uses TPAs and UpText. It will work regardless of compass direction, as long as the color is visible.

introducing FindObjectCTS2 !

Parameters :
Color : the color you are trying to find.

Tol : the tolerance you'll admit on that color.

Hue & Sat : hue and saturation of the color. if you put 0 in both, the function will proceed using Color Tolerance Speed of 1.

modx, mody : where the object is located from Main Screen center, when you're looking north. if it's east a square, modx will be 40 and mody 0. east two squares, modx 80 mody 0. You can use negatives !
Higher modx : more east. Higher mody : more south. Leave a comment if this isn't clear enough, I'll try to make it easier to understand.

ATPASize : how large and tall is the item you're trying to find? a banker would be 15, a chest 25, a POH table 50.

MaxTries : once it's found the color and split them into boxes, it will MMouse boxes checking for uptext. this is the max number of boxes it will try before exiting. If you put 0, it will check every box (do not do this with a ATPASize under 5).

MinLength : the number of colored pixels it has to find. if it doesn't, it will exit. This should hang between ATPASize/2 and ATPASize e.g. if your ATPASize is 15, then 10 is a good value for MinLength.

Uptext : the uptext it will search for. :)

Action : 1 is left click, 2 is right click, 3 is nothing.

MouseTol : tolerance for Mouse function. Should be between 1/4 and 1/2 ATPASize !

I'm currently making a MM finding function based on this, if you like this one I will submit it.

function FindObjectCTS2(Color, Tol : Integer; Hue, Sat : Extended; modx, mody, ATPASize, MaxTries, MinLength : Integer; Uptext : String; Action, MouseTol : Integer) : Boolean;
var
StartCoords : TPoint;
ColorPoints : TPointArray;
ColorBoxes : T2DPointArray;
EndOfTries : Integer;

begin
if (Action > 3) or (Action < 1) then
begin
Writeln('Action parameter should be 1 for left click, 2 for right click, 3 for no click !');
Exit;
end;
StartCoords := Point(MSCX + modx * Round(Cos(rs_GetCompassAngleRadians)) + mody * Round(Sin(rs_GetCompassAngleRadians)), MSCY - modx * Round(Sin(rs_GetCompassAngleRadians)) + mody * Round(Cos(rs_GetCompassAngleRadians)));
if (Hue <> 0) and (Sat <> 0) then
begin
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Hue, Sat);
end;
FindColorsSpiralTolerance(StartCoords.x, StartCoords.y, ColorPoints, Color, MSX1, MSY1, MSX2, MSY2, tol);
if High(ColorPoints) < MinLength then
begin
Result := False;
Exit;
end;
ColorBoxes := TPAtoATPAEx(ColorPoints, ATPASize, ATPASize);
if MaxTries = 0 then
EndOfTries := High(ColorBoxes)
else
begin
if High(ColorBoxes) > MaxTries then
EndOfTries := MaxTries
else
EndOfTries := High(ColorBoxes);
end;
for i := 0 to EndOfTries do
begin
StartCoords := MiddleTPA(ColorBoxes[i]);
MMouse(StartCoords.x, StartCoords.y, 5, 5);
Wait(175+Random(50));
if IsUpText(UpText) then
begin
if Action < 3 then
begin
GetMousePos(StartCoords.x, StartCoords.y);
if Action = 1 then
Mouse(StartCoords.x, StartCoords.y, 0, 0, True)
else
Mouse(StartCoords.x, StartCoords.y, 0, 0, False)
Result := True;
Break;
end;
end;
ColorToleranceSpeed(1);
SetColorSpeed2Modifiers(0.2, 0.2);
end;

Gu3st...

2010-02-12 17:15:54

This is really basic.. I don't think we really need more obj finding functions in SRL tbh :/

Timer

2010-02-12 17:30:15

Maybe if you just made it able to input a TIntArray of colours. It gets the Hue/Sat Mods, Etc. And finds it. :)

Gu3st...

2010-02-12 17:32:07

From: Timer
Maybe if you just made it able to input a TIntArray of colours. It gets the Hue/Sat Mods, Etc. And finds it. :)
Yeah, that would be neat :)

Naum

2010-02-12 17:37:02

From: Timer
Maybe if you just made it able to input a TIntArray of colours. It gets the Hue/Sat Mods, Etc. And finds it. :)


From: Zyt3x
Yeah, that would be neat :)


Someone's been there, done that:

http://www.villavu.com/repositories/srl-opendev/SRL/core/Color.scar,

Regarding the function itself, I'm pretty adamant that it wont get put into SRL, primarily because FindObjTPA etc are inside Objects.scar. Furthermore, many people make their own custom finders anyway. Good job, rep+ for effort :)

YoHoJo

2010-02-12 17:38:49

=( Good effort! Keep on scripting! :] Don't let it get you down! :)

Cigue

2010-02-12 17:47:48

I was not counting on getting this in SRL Library, else it'd be in the Public SVN forum. :P Could a moderator change the title to "My gift to the community" ?

Also, this is a lot more JR Members oriented than full members. :P

chitin

2010-02-12 18:23:09

From: Zyt3x
This is really basic.. I don't think we really need more obj finding functions in SRL tbh :/


the truth is in the eye of the beholder my friend. one mans trash is another mans treasure. err may be useless to you but for others could be a guide =p

Cigue

2010-02-12 18:30:49

Thanks chitin :)

If anybody wants, I also might release a public version of my TPAWalk function ;) parameters are something like Autocolor, N/S/E/W, x, y and it gets you where you want it to.

Gu3st...

2010-02-13 04:02:22

From: chitin
the truth is in the eye of the beholder my friend. one mans trash is another mans treasure. err may be useless to you but for others could be a guide =p
True.. But my point was that inside Objects.scar there is already functions like that that also can be used as a guide :)