SRL Archive - SRL Archives

FindAndAttachPickHead.


noidea

2009-01-19 01:43:19

Function FindnAttHead(ThePick: String; Weilded: Boolean): Boolean;
Var
head: Tpoint;
TPA: TPointArray;
Optionz: TVariantArray;
ATPA: Array of TPointArray;
CTS, I, CurrTab, x, y, heady, stick, pick: Integer;
begin //8286806 //7826257
heady := DTMFromString('78DA637465626078C280022CBD4318FE03694' +
'620FE0F048C164035CF19D000231209A4BD816A6E1150E349A439' +
'0F09A87125AC060093D70CE0');
Stick := DTMFromString('78DA63B465626078CA8002F415D818FE03694' +
'620FE0F048CF64035F718D000231209A46D806ADE1050630154F3' +
'89801A67A09A9B04D4B800D5DCC2AF060022960C39');
Pick := DTMFromString('78DA63B461626078C1800274E55919FE03694' +
'620FE0F048C264035B719D000231209A403806A1E125003B2EB06' +
'0135DE40357708A8B104AAF9845F0D00183E0C34');
CurrTab := GetCurrentTab;
case Lowercase(ThePick) of
'steel': Optionz := ([ 0.25, 0.05, 5855840, 9 ]);
'bronze': Optionz := ([ 0.05, 0.01, 2110788, 9 ]);
'iron': Optionz := ([ 0.12, 0.04, 5263445, 17 ]);
'mith': Optionz := ([ 0.10, 0.02, 5979710, 11 ]);
'rune': Optionz := ([ 0.00, 0.05, 8812891, 13 ]);
'addy': Optionz := ([ 0.10, 0.03, 5136717, 9 ]);
end;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Optionz[0], Optionz[1]);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Optionz[2] , MSX1, MSY1, MSX2, MSY2, Optionz[3]);
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 2, 2);
For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], head.x, head.y);
MMouse(head.x, head.y, 2, 2);
wait(100+random(100));
If(IsUpTextMultiCustom(['ake', 'ick', 'ead'])) then
begin
GetMousePos(head.x, head.y);
Mouse(head.x, head.y, 0, 0, true);
flag;
wait(200+random(200));
if Weilded then
begin
gametab(5);
wait(100);
mmouse(585, 303, 10, 10);
wait(100);
if isuptext('ick') then
begin
getmousepos(x, y);
mouse(x, y, 0, 0, true);
gametab(4);
end;
end;
gametab(4);
if findDTm(Heady, x, y, MIX1, MIY1, MIX2, MIY2)then
begin
mouse(x, y, 4, 4, true);
wait(100);
if findDTm(stick, x, y, MIX1, MIY1, MIX2, MIY2)then
begin
mouse(x, y, 2 ,2, true);
wait(200);
if findDTm(pick, x, y, MIX1, MIY1, MIX2, MIY2)then
begin
result := true;
FreeDTM(pick);
FreeDTM(heady);
FreeDTM(stick);
exit;
end;
end else
begin
writeln('Couldn''t find stick');
FreeDTM(pick);
FreeDTM(heady);
FreeDTM(stick);
exit;
end;
end else
begin
writeln('Couldtn''t find head of pick');
FreeDTM(pick);
FreeDTM(heady);
FreeDTM(stick);
exit;
end;
end;
end;
Writeln('Couldn''t attatch head of pick and stick together!');
FreeDTM(pick);
FreeDTM(heady);
FreeDTM(stick);
end;
It works FLAWLESSLY for me. Try it?, rate hate?

lordsaturn

2009-01-19 02:26:35

You should definitely use a try/finally block in your for loop so you can exit out and still free all of your DTMs. And maybe a little more randomization please?

Edit: Here's what I mean about the try/finally block:

begin
For I := 0 to High(ATPA) do
try
...
if findDTm(Heady, x, y, MIX1, MIY1, MIX2, MIY2)then
begin
mouse(x, y, 4, 4, true);
wait(100);
if findDTm(stick, x, y, MIX1, MIY1, MIX2, MIY2)then
begin
mouse(x, y, 2 ,2, true);
wait(200);
if findDTm(pick, x, y, MIX1, MIY1, MIX2, MIY2)then
result := true;
end;
end;
end;
finally
FreeDTM(pick);
FreeDTM(heady);
FreeDTM(stick);
end;
Writeln('Couldn''t attatch head of pick and stick together!');
end;
Or whatever variation of that you'd like.

Cazax

2009-01-19 08:47:59

No need to do this:
        FreeDTM(pick);
FreeDTM(heady);
FreeDTM(stick);
In every end else, just free them at the end.

noidea

2009-01-19 10:07:02

From: Cazax
No need to do this:
        FreeDTM(pick);
FreeDTM(heady);
FreeDTM(stick);
In every end else, just free them at the end.


I use exit; though :confused:
I just took this out of one of my scripts and made it universal.
Here is the original:
Function FindHead(var head: Tpoint): Boolean;
Var
CTS, I: Integer;
TPA: TPointArray;
ATPA: Array of TPointArray;
Optionz: TVariantArray;
begin //8286806 //7826257
case Lowercase(ThePick) of
'steel': Optionz := ([ 0.25, 0.05, 5855840, 9 ]);
'bronz': Optionz := ([ 0.05, 0.01, 2110788, 9 ]);
'iron': Optionz := ([ 0.12, 0.04, 5263445, 17 ]);
'mith': Optionz := ([ 0.10, 0.02, 5979710, 11 ]);
'rune': Optionz := ([ 0.00, 0.05, 8812891, 13 ]);
'addy': Optionz := ([ 0.10, 0.03, 5136717, 9 ]);
end;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Optionz[0], Optionz[1]);
FindColorsSpiralTolerance(MSCX, MSCY, TPA, Optionz[2] , MSX1, MSY1, MSX2, MSY2, Optionz[3]);
ColorToleranceSpeed(CTS);
ATPA := TPAToATPAEx(TPA, 2, 2);
For I := 0 to High(ATPA) do
begin
MiddleTPAEx(ATPA[i], head.x, head.y);
MMouse(head.x, head.y, 2, 2);
wait(100+random(100));
If(IsUpTextMultiCustom(['ake', 'ick', 'ead'])) then
begin
Result := True;
GetMousePos(head.x, head.y);
Break;
end;
end;
end;
and the stuff in a procedure I used to pick it up;
if FindHead(head1)then
begin
mouse(head1.x, head1.y, 0, 0, false);
Chooseoption('ake');
SafeFlag;
wait(500+random(300));
if FindDTM(Head, x, y, mix1, miy1, mix2, miy2)then
begin
mouse(x, y, 3, 3, true);
if FindDTM(Stick, x, y, MIX1, MIY1, MIX2, MIY2)then
begin
mouse(x, y, 3, 3, true);
inc(headsrepaired);
If Players[CurrentPlayer].Booleans[0] then
if FindDTM(Pick, x,y, MIX1, MIY1,MIX2, MIY2)then
mouse(x, y, 4, 4, true);
exit;
end else
begin
FindDTM(Head, x, y, MIX1, MIY1, MIX2, MIY2)
mouse(x, y, 3, 3, true);
end;
end else
begin
ndbug('Didnt find pick head');
goto This;
end;
end else
begin
ndbug('Error: Didn''t find pick head on ground!');
Goto This;
end;
end else Goto This;

Sir R. M8gic1an

2009-01-28 12:25:09


begin
try wait(1);
code
code
code
code
exit
finally
FreeDTM(wahtever)
end;
end;
even if you exit it'll still free them ;)

~RM