SRL Archive - SRL-OSR Snippets

[OSR] ScrollToItemDTM (Finding bank items)


Flight

2013-04-10 00:12:18

Hey guys, I updated these couple of functions to work for OSR. Basically you feed this function a DTM of a bank item you want to find and this will search your bank for it via the scroll bar. I put out this function previously for EoC RS but for it to work with OSR it required some modifications here and there. This should be quite useful as there's currently no way (in the SRL-OSR include) to search a bank account for an item.

Function WindMouseDTM
-Required for the main function.


Function WindMouseDTM(xs, ys, xe, ye, gravity, wind, minWait, maxWait, targetArea: extended; DTM: Integer): Boolean;
var
veloX,veloY,windX,windY,veloMag,dist,randomDist,lastDist,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);
//Search for the scroll bar near the mouse
if (not FindColorTolerance(fX, fY, 3359309, B.x1, B.y1, B.x2, B.y2, 30)) 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; var Pnt: TPoint): Boolean;
-2 parameters, the first is the input item DTM you're searching for, the second is the point at which the DTM is found ("if" found). Results true if the DTM is found, false if not.


Function ScrollToItemDTM(DTM: Integer; var Pnt: TPoint): Boolean;
var
randSpeed: extended;
X,Y,A: integer;
begin
Result := False;
if not BankScreen then
Exit;

if FindDTM(DTM, X, Y, MSx1, MSy1, MSx2, MSy2) then
begin
Result := True;
Pnt := Point(X, Y);
Exit;
end;

FixBank;

A := MouseSpeed;
MMouse(476, 85, 3, 5);
GetMousePos(X, Y);
HoldMouse(X, Y, mouse_left);

MouseSpeed := 30;
randSpeed:= (random(30) / 30) / 10.0;
if randSpeed = 0.0 then
randSpeed := 0.1;

if windMouseDTM(X, Y, 476+RandomRange(-3,3), 265+RandomRange(-5,5), 9.0,3.0,10.0/randSpeed,15.0/randSpeed,10.0*randSpeed, DTM) then
Result := FindDTM(DTM, Pnt.X, Pnt.Y, MSx1, MSy1, MSx2, MSy2);

GetMousePos(X, Y);
ReleaseMouse(X, Y, mouse_left);

MouseSpeed := A;
end;

Below is a short video of searching my back account for Flax & withdrawing all.

[YOUTUBE]36WhnuE1wq8[/YOUTUBE]

Justin

2013-04-10 00:17:22

Amazing work Flight, Love how fast it finds it too

Wetish

2013-04-10 06:48:04

My god Flight. This is genius. I would have never thought of something like this

Flight

2013-04-10 07:48:33

From: Wetish
My god Flight. This is genius. I would have never thought of something like this


Oh I doubt that Wetish! Thank you both for the kind comments. :)

The Bot

2013-04-12 05:28:39

Thank you so much for this! I can see it being useful for other legitimate tasks too, like spending ages trawling through a bank to find that pesky rope or spade for a clue scroll… I can just save an array of DTMs and and give them names, then I'll never have to search again. In fact, I might make a public script for this soon with common items like spades, flax, logs and what-not. Thanks! :)

Flight

2013-04-13 01:04:30

I just edited in 1 line that I'd forgotten before. Inside the ScrollToItemDTM function I added in this in the beginning of the function (where the initial DTM check is done):

if FindDTM(DTM, X, Y, MSx1, MSy1, MSx2, MSy2) then
begin
Result := True;
Exit;
end;
To this:

if FindDTM(DTM, X, Y, MSx1, MSy1, MSx2, MSy2) then
begin
Result := True;
Pnt := Point(X, Y);
Exit;
end;

Before if the item was initially found (without ever having to scroll) the function would, of course, result true and exit, but it did not return the point at which the item was found. I didn't realize this until real-time running minutes ago. It should work, once again, correctly now.

Shatterhand

2013-04-14 15:39:50

Very nice, gonna try this out tomorrow! :)

Flight

2013-07-31 22:47:17

There was a slight flaw in this and I've fixed it to work perfectly with OSRS. I've also moved this to the SRL-OSR Snippets section.

rj

2013-07-31 22:51:31

From: Flight
There was a slight flaw in this and I've fixed it to work perfectly with OSRS. I've also moved this to the SRL-OSR Snippets section.


Hey, small suggestion it would be cool it it had the option to wait randomly after it found the dtm. Sometimes when i'm scrolling for an object in my bank I overshoot a little bit :p

Flight

2013-07-31 22:59:37

From: Officer Barbrady
Hey, small suggestion it would be cool it it had the option to wait randomly after it found the dtm. Sometimes when i'm scrolling for an object in my bank I overshoot a little bit :p


Ah yeah that's possible indeed. If you really wanted it just make a function that continues to scroll down a little bit.