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.
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;