Flight
04-09-2012, 03:01 AM
So, still playing around with mouse movements and what not, I've whipped up another neat function some of you might find useful. What this does is scrolls through your bank (1 time) until the specified item (DTM) is found. You can tell it to start at the first bank tab or remain on the current bank tab.
Function WindMouseDTM
--Too many parameters to mention :/--
*Slowly moves the mouse while searching for a DTM on the main-screen
Function WindMouseDTM(xs, ys, xe, ye, gravity, wind, minWait, maxWait, targetArea: extended; DTM: Integer): Boolean;
var
veloX,veloY,windX,windY,veloMag,dist,randomDist,la stDist,step: extended;
lastX,lastY,MSP,W,maxStep,X,Y: integer;
sqrt2,sqrt3,sqrt5: extended;
fX,fY,mX,mY: Integer;
B: TBox;
begin
Result := False;
MSP := MouseSpeed;
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);
repeat
dist:= hypot(xs - xe, ys - ye);
wind:= minE(wind, dist);
maxStep := (RandomRange(2, 4));
if dist >= targetArea then
begin
windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
end else
begin
windX:= windX / sqrt2;
windY:= windY / sqrt2;
end;
veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (xe - xs) / dist;
veloY:= veloY + gravity * (ye - ys) / dist;
if hypot(veloX, veloY) > maxStep then
begin
randomDist:= maxStep / 2.0 + random(round(maxStep) div 2);
veloMag:= sqrt(veloX * veloX + veloY * veloY);
veloX:= (veloX / veloMag) * randomDist;
veloY:= (veloY / veloMag) * randomDist;
end;
lastX:= Round(xs);
lastY:= Round(ys);
xs:= xs + veloX;
ys:= ys + veloY;
if (lastX <> Round(xs)) or (lastY <> Round(ys)) then
MoveMouse(Round(xs), Round(ys));
GetMousePos(mX, mY);
B := IntToBox(mX-5, mY-5, mX+5, mY+5);
if (not FindColorTolerance(fX, fY, 4807781, B.x1, B.y1, B.x2, B.y2, 25)) then
Exit;
if FindDTM(DTM, X, Y, MSX1, MSY1, MSX2, MSY2) then
begin
Result := True;
Exit;
end;
case Random(50) of
1..25: W := (MSP + (Random((MSP/4))));
26..50: W := (MSP - (RandomRange((MSP/2), MSP-1)));
end;
if (W < 1) then
W := 1;
wait(W);
step:= hypot(xs - lastX, ys - lastY);
lastdist:= dist;
until(hypot(xs - xe, ys - ye) < 1)
if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
MoveMouse(Round(xe), Round(ye));
MouseSpeed := MSP;
end;
Function ScrollToItemDTM(DTM: Integer; FirstTab: Boolean): Boolean;
--Parameters--
*DTM (Integer) - The DTM of your item
*FirstTab (Boolean) - True to start the search at bank tab #1, False to remain at the current bank tab
Function ScrollToItemDTM(DTM: Integer; FirstTab: Boolean): Boolean;
var
randSpeed: extended;
X,Y,A: integer;
begin
Result := False;
if not BankScreen then Exit;
if FirstTab then
FixBankTab;
FixBank;
A := MouseSpeed;
MMouse(489, 108, 3, 3);
GetMousePos(X, Y);
HoldMouse(X, Y, mouse_left);
MouseSpeed := 30;
randSpeed:= (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
Result := WindMouseDTM(X, Y, 489, 270, 9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed, DTM);
GetMousePos(X, Y);
ReleaseMouse(X, Y, mouse_left);
MouseSpeed := A;
end;
Example:
Procedure ScrollToDFS;
Var
DFS: Integer; //Dragonfire shield
begin
DFS := DTMFromString('mbQAAAHicY2VgYLBmZGDwBmIPILYBYlMg/gcU/wbEDEA2NxDzAvHfpSpAASYUzA9RgoKZsGAwAACfSgVE');
if ScrollToItemDTM(DFS, False) then
Writeln('Success!');
FreeDTM(DFS);
end;
I think it could be improved a bit, maybe adding the option of searching for a Bitmap instead. Also if your player is lagging there's a chance the scroll bar might randomly stop completely while the mouse is still moving, this is Runescape's fault (lousy coding), don't blame me. :p
Function WindMouseDTM
--Too many parameters to mention :/--
*Slowly moves the mouse while searching for a DTM on the main-screen
Function WindMouseDTM(xs, ys, xe, ye, gravity, wind, minWait, maxWait, targetArea: extended; DTM: Integer): Boolean;
var
veloX,veloY,windX,windY,veloMag,dist,randomDist,la stDist,step: extended;
lastX,lastY,MSP,W,maxStep,X,Y: integer;
sqrt2,sqrt3,sqrt5: extended;
fX,fY,mX,mY: Integer;
B: TBox;
begin
Result := False;
MSP := MouseSpeed;
sqrt2:= sqrt(2);
sqrt3:= sqrt(3);
sqrt5:= sqrt(5);
repeat
dist:= hypot(xs - xe, ys - ye);
wind:= minE(wind, dist);
maxStep := (RandomRange(2, 4));
if dist >= targetArea then
begin
windX:= windX / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
windY:= windY / sqrt3 + (random(round(wind) * 2 + 1) - wind) / sqrt5;
end else
begin
windX:= windX / sqrt2;
windY:= windY / sqrt2;
end;
veloX:= veloX + windX;
veloY:= veloY + windY;
veloX:= veloX + gravity * (xe - xs) / dist;
veloY:= veloY + gravity * (ye - ys) / dist;
if hypot(veloX, veloY) > maxStep then
begin
randomDist:= maxStep / 2.0 + random(round(maxStep) div 2);
veloMag:= sqrt(veloX * veloX + veloY * veloY);
veloX:= (veloX / veloMag) * randomDist;
veloY:= (veloY / veloMag) * randomDist;
end;
lastX:= Round(xs);
lastY:= Round(ys);
xs:= xs + veloX;
ys:= ys + veloY;
if (lastX <> Round(xs)) or (lastY <> Round(ys)) then
MoveMouse(Round(xs), Round(ys));
GetMousePos(mX, mY);
B := IntToBox(mX-5, mY-5, mX+5, mY+5);
if (not FindColorTolerance(fX, fY, 4807781, B.x1, B.y1, B.x2, B.y2, 25)) then
Exit;
if FindDTM(DTM, X, Y, MSX1, MSY1, MSX2, MSY2) then
begin
Result := True;
Exit;
end;
case Random(50) of
1..25: W := (MSP + (Random((MSP/4))));
26..50: W := (MSP - (RandomRange((MSP/2), MSP-1)));
end;
if (W < 1) then
W := 1;
wait(W);
step:= hypot(xs - lastX, ys - lastY);
lastdist:= dist;
until(hypot(xs - xe, ys - ye) < 1)
if (Round(xe) <> Round(xs)) or (Round(ye) <> Round(ys)) then
MoveMouse(Round(xe), Round(ye));
MouseSpeed := MSP;
end;
Function ScrollToItemDTM(DTM: Integer; FirstTab: Boolean): Boolean;
--Parameters--
*DTM (Integer) - The DTM of your item
*FirstTab (Boolean) - True to start the search at bank tab #1, False to remain at the current bank tab
Function ScrollToItemDTM(DTM: Integer; FirstTab: Boolean): Boolean;
var
randSpeed: extended;
X,Y,A: integer;
begin
Result := False;
if not BankScreen then Exit;
if FirstTab then
FixBankTab;
FixBank;
A := MouseSpeed;
MMouse(489, 108, 3, 3);
GetMousePos(X, Y);
HoldMouse(X, Y, mouse_left);
MouseSpeed := 30;
randSpeed:= (random(MouseSpeed) / 2.0 + MouseSpeed) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;
Result := WindMouseDTM(X, Y, 489, 270, 9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed, DTM);
GetMousePos(X, Y);
ReleaseMouse(X, Y, mouse_left);
MouseSpeed := A;
end;
Example:
Procedure ScrollToDFS;
Var
DFS: Integer; //Dragonfire shield
begin
DFS := DTMFromString('mbQAAAHicY2VgYLBmZGDwBmIPILYBYlMg/gcU/wbEDEA2NxDzAvHfpSpAASYUzA9RgoKZsGAwAACfSgVE');
if ScrollToItemDTM(DFS, False) then
Writeln('Success!');
FreeDTM(DFS);
end;
I think it could be improved a bit, maybe adding the option of searching for a Bitmap instead. Also if your player is lagging there's a chance the scroll bar might randomly stop completely while the mouse is still moving, this is Runescape's fault (lousy coding), don't blame me. :p