PvH
2008-07-23 04:19:29
Hey everyone:D
This is a new function.
It is very short, though it is very effective.
It might be usefull for new scripters, which want to use tpa's even if they don't understand them.
It searches for a color, moves the mouse to it, checks for uptext, clicks, can use chooseoption, writes the time it took to find the object, has tolerance and more:)
Here it is:
Enjoy it:D
PvH
This is a new function.
It is very short, though it is very effective.
It might be usefull for new scripters, which want to use tpa's even if they don't understand them.
It searches for a color, moves the mouse to it, checks for uptext, clicks, can use chooseoption, writes the time it took to find the object, has tolerance and more:)
Here it is:
{*****************************************************************************************************************]
function FindObject(var x,y:integer; uptext, objectname, option:string; Mouseway,color,tolerance:integer):boolean;
By: PvH
Description: Find the object with uptext, chooseoption, clicks and uses tpa
Use:
X,y as variables (integer declared in script)
Uptext: The uptext from the object as a string
Object: Name of the object as a string, used for writing in the debug
Option: Option to choose when rightclicking, still declare it if you don't use it ;)
Mouseway: 1 for leftclicking, 2 for rightclicking and 3 for moving the mouse over it
Color: The color of the object
Tolerance: The Tolerance in to search (10-20 recommend)
X1,y1,x2,y2: The place where to search on the screen
Example:
FindObject(x,y,'ishing','fishing spot' ,'ait', 2, 11708835, 3, msx1, msy1, msx2, msy2);
******************************************************************************************************************}
function FindObject(var x,y:integer; uptext, objectname, option:string; Mouseway,color,tolerance, x1,y1,x2,y2:integer):boolean;
var
ObjectTPA: T2DPointArray;
ObjectPoint: TPointArray;
Tries, I, cts, ObjectTime: integer;
begin
if not LoggedIn then exit;
wait(300+random(600));
marktime(ObjectTime);
repeat
cts := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
FindColorsTolerance(ObjectPoint, color, x1, y1, x2, y2, tolerance);
ObjectTPA := TPAtoATPAEx(ObjectPoint, 20, 20);
SortATPAFromFirstPoint(ObjectTPA, Point(MSCX, MSCY));
For I:= 0 to High(ObjectTPA) do
begin
MiddleTPAEx(ObjectTPA[i], x, y);
MMouse(x, y, 3, 3);
Wait(150 + Random(70));
Tries:=Tries+1;
if isuptext(uptext)then
begin
Writeln('Finding '+(objectname)+' took:' +inttostr(timefrommark(ObjectTime))+ ' ms!');
Tries:=Tries-Tries;
GetMousePos(x,y);
if Mouseway = 1 then
begin
mouse(x,y,0,0,true);
fflag(0);
end;
if Mouseway = 2 then
begin
mouse(x,y,0,0,false);
wait(300+random(500));
Chooseoption(option);
fflag(0);
end;
wait(700+random(1000));
result := true;
exit;
end else
begin
mmouse(392, 268, 30, 30);
Status('Failed to find the object');
end;
end;
until((tries >10) or (timefrommark(ObjectTime) > (20000+random(10000))));
writeln('We couldn''t find the '+(objectname)+ '!');
end;
Enjoy it:D
PvH