SRL Archive - Research & Development Lounge

FindObject By PvH


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:

{*****************************************************************************************************************]
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

lordsaturn

2008-07-23 07:41:02

Thanks, Pvh.

The_Shermanator

2008-07-23 13:21:19

Ooooo, Looks nice, I'll keep this in mind ;)

Laur€ns

2008-07-23 13:23:57

Ah, d*mnit, I've been learning TPAs and the date before applying you come with this :/ Whatever, I have TPA now.

Twisted

2008-07-23 16:49:22

could be better if you have a x1, y1, x2, y2 in it, so people could say where they want to find it. If they want to find it in MS, MI, MM, or MC. You know?

PvH

2008-07-24 02:27:44

From: Twisted
could be better if you have a x1, y1, x2, y2 in it, so people could say where they want to find it. If they want to find it in MS, MI, MM, or MC. You know?


Ohh yea, thanks, I fully forgot about that:p
I'll change that now;)
Thanks again:D

PvH

the nerd

2008-07-26 12:07:33

PVH, could you make a second one that accepts colour arrays and text arrays so it can be used to search for multipal objects and to increace it likly hood of find the object that is wanted???

PvH

2008-07-26 13:28:27

From: the nerd
PVH, could you make a second one that accepts colour arrays and text arrays so it can be used to search for multipal objects and to increace it likly hood of find the object that is wanted???


With only 1 color and only 1 isuptext, the chance of finding an object is higher.
Pick a unique color, which is really good and use that one.
Also, the less colors/isuptext, the less lagg:)

PvH

turbobk

2008-07-27 00:34:30

Nice PvH!!

Well done on the function, look's really niice! :)
Now noob's will use your pwnage function instead of learning TPA's themselves :p

PvH

2008-07-27 03:30:59

From: turbobk
Nice PvH!!

Well done on the function, look's really niice! :)
Now noob's will use your pwnage function instead of learning TPA's themselves :p


Hehe, thanks:D
And yes, I hope they go use this or some other advanced function when they start scripting, and after that, they go learn TPA's :)

PvH