Log in

View Full Version : object finding



CowFish
07-21-2012, 02:23 AM
in my script im using tpas to try and find trees, and while it is finding them i think there is something wrong with the way i coded it because the mouse jumps to each object many many times and eventually (sometimes after a matter of minutes or sometimes never) actually clicks the object. i'll attach my procedure but I'd love to fix this because it's really pissing me off.. sorry about standards but this is kind of a quick and dirty script. btw i can't use uptext so that's why i have a dtm to figure out if its the right object. also i know findtree doesn't need to be a function, not sure why I made it one.



function ismagic: boolean;
var
updtm,x ,y : integer;
begin

updtm := DTMFromString('mlwAAAHicY2dgYIgH4kwgLgXiSiDuBOKpQD wXiIWAWAyIxYFYBIgFoWxRIGa6eYOB/e4tBs77Nxi4Hj0C8m8xMN++zcD79CkDP1AeF2bEg6EAANguEL0 =');
if FindDTM(updtm, x, y, 0, 0, 500, 500) then
begin
Result := True;
end;
freedtm(updtm);
end;

function findtree: boolean;
var x,y: integer;
TPA: array of tpoint;
atpa: t2dpointarray;
i: integer;
begin
FindColorsSpiralTolerance(x,y, TPA,10672344, MSX1, MSY1, MSX2, MSY2, 15);
begin
ATPA := TPAtoATPAEx(TPA, 10, 30);
SortATPASize(ATPA,True);
for i:=0 to High(ATPA) do
begin
middletpaex(atpa[i], x,y);
mmouse(x,y,1,1);
if ismagic then
begin
Mouse(x, y,1,1,True);
writeln('tree found and clicked');
Result := true;
break;
end;
end;
end;
end;

procedure choppinloop;
var
x,y:integer;
begin
findtree;
repeat
wait(100);
checkbob;
until not IsChopping or (fullinvy);
end;

MAIN LOOP

repeat
repeat
choppinloop;
until fullinvy
if fullinvy then
repeat
droplogs;
checkbob;
until not ExistsItemz(1);
if not fullinvy then
begin
choppinloop;
end;
until(IsFKeyDown(12));

x[Warrior]x3500
07-21-2012, 02:26 AM
put a wait after your mmouse() and before your ismagic (like 100-200ms) and see if that changes things

CowFish
07-21-2012, 02:29 AM
unfortunately that seems to have slown down the jumping :P but i do notice it clicking the tree after less time has passed so i guess thats good!

P1ng
07-21-2012, 08:33 AM
perhaps try putting
if WaitFunc(@ismagic,10,1500) then
it sounds as though the mouse is moving on too fast before the UpText DTM has appeared.

Everything else appears to be fine, the function looks good and your DTM has sufficient tolerance on all points.

CowFish
07-21-2012, 03:16 PM
That kind of helped but i still have the same problem.. I have a feeling the problem has to do with the loop somehow but it looks fine to me.. I might just try rewriting the function.

CowFish
07-21-2012, 06:04 PM
just a little update, i've confirmed that my ismagic function isn't 100% working. it returns false quite a lot even when the uptext is on the screen. does anyone have any ideas for an alternate method of verifying the object?

P1ng
07-22-2012, 12:25 AM
something along the lines of this -
function PGetUpText: string;
begin
Result := rs_GetUpTextAt(x co-ord, y co-ord);
end;

I'll let you find the x and y co-ordinates yourself. Hope that helps :)