SRL Archive - SRL Archives

FindBankTPA


Sir R. M8gic1an

2008-06-07 08:30:00

well earlier today (at about 1am for me) i posted this in SRL New Functions.

i now finished it.


{*******************************************************************************
function FindBankTPA(TheBank: String): Boolean;
By: Rasta Magician
Description: Finds and opens any given bank in the free world.
Uses TPAs to find the bankers.
Valid arguments are:
'feb' (Falador East Bank)
'fwb' (Falador West Bank)
'veb' (Varrock East Bank)
'vwb' (Varrock West Bank)
'db' (Draynor Bank)
'akb' (Al-Kharid Bank)
'eb' (Edgevile Bank)
*******************************************************************************}
Function FindBankTPA(TheBank:string):boolean;
var
TPA:TPointArray;
ATPA: T2DPointArray;
TP: TPoint;
i, rx, ry, ExtraAngle:integer;
TempCTS, k:integer;
TPASize:integer;
begin
TempCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.00, 0.13);
Result:=False;
try
FindColorsTolerance(TPA, 125931, MMX1, MMY1, MMX2, MMY2, 7)
if Length(TPA) = 0 then
begin
Writeln('Failed to find the color, no result.');
Exit;
end;

ATPA:=TPAToATPA(TPA, 3); //to find out how many bankers

if Length(ATPA) < 3 then
begin
writeln('could not find bankers');
exit;
end;

TPASize := Length(ATPA[0]); //to know how big the banker dots are

for i:=0 to High(ATPA) do //re joining the tpa, smaller split
TPA := CombineTPA(TPA, ATPA[i]);


ATPA := SplitTPA(TPA, 6); //seprating the bankers from any other npcs around
k:=0;

for i:=0 to High(ATPA) do //checking where there are 4+ npcs together
if (Length(ATPA[i]) > (3*TPASize))then
begin
TPA[k] := MiddleTPA(ATPA[i]);
inc(k);
end;


SetLength(TPA, k);
//SortTPAFrom(TPA, Point(MMCX, MMCY));
if Length(TPA) > 1 then
TP := MiddleTPA(TPA)
else
TP:=TPA[0];

rx := 0; ry:=0; ExtraAngle:=0;

case lowercase(TheBank) of
'eb' : begin rx := -11; ry := -3; ExtraAngle := -90; end;
'veb': begin rx := 3; ry := 11; ExtraAngle := 0; end;
'fwb': begin rx := 10; ry := 8; ExtraAngle := 0; end;
'feb': begin rx := 3; ry := 8; ExtraAngle := 0; end;
'akb' : begin rx := 7; ry := 5; ExtraAngle := -90; end;
'db' : begin rx := 9; ry := 10; ExtraAngle := 0; end;
'vwb':
begin
ExtraAngle:=0;

if rs_GetCompassAngleDegrees < 180.0 then
begin
if TP.x > MMCX then
rx:=+10
else
rx:=-10;

if TP.y < MMCY then
ry:= -15
else
ry:= +15;

end else begin
if TP.x > MMCX then
rx:=-10
else
rx:=+10;

if TP.y < MMCY then
ry:= +15
else
ry:= -15;
end

end;
end;

IncEx(TP.x, Round(rx * Cos(Radians(rs_GetCompassAngleDegrees + ExtraAngle))));
IncEx(TP.y, Round(ry * Sin(Radians(rs_GetCompassAngleDegrees + ExtraAngle))));
Mouse(TP.x, TP.y, 0, 0, True);
FFLag(0);
if OpenBankQuiet(lowercase(TheBank)) then
begin
FixBank;
Result := True;
exit;
end;


finally
ColorToleranceSpeed(tempCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
end;
end;

~RM

markuska815

2008-06-07 10:03:41

Hey i know you were talking about making it open the bank too so maybe in the parameter add an open boolean and then do

if (Open) then
OpenBankFast(TheBank);

Or OpenBankQuiet.

Just a suggestion.

Edit: Sorry I didn't see you had the open in there my bad.

Nava2

2008-06-09 08:32:05

    if OpenBankQuiet(lowercase(TheBank)) then
begin
FixBank;
Result := True;
exit;
end;

Maybe do:

Result := BankScreen or PinScreen;

More likely correct answer?

Nava2

Sir R. M8gic1an

2008-06-09 12:22:40

OpenBankQuiet already does that ;)

~RM

Sir R. M8gic1an

2008-06-09 13:27:50

tested it. 31 ms. munk made one that only takes 0 ms and i'm not even sure if this actually beats the DTMs. i'm revamping it right now :)

meh. still 31ms.

tried taking out the TPAtoATPA and CombineTPA cus i got the impression each banker is always 10 dots, but it didn't speed it up, so i might as well leave it there for a bit extra security.

~RM

Nava2

2008-06-09 15:40:21

Could his be faster because it doesn't open the bank?

Nava2

Nava2

2008-06-09 16:14:21

Couple things, you have some unneeded variables and a compiling error.

Unneeded:

FoundVWB, FoundVWB2:integer;
You never use those two variables.

Error:

FindColorsTolerance(MMCX, MMCY, TPA, 125931, MMX1, MMY1, MMX2, MMY2, 7)
Should be:
FindColorsTolerance(TPA, 125931, MMX1, MMY1, MMX2, MMY2, 7);

Unless you meant FindColorsSpiralTolerance, in that case re-add the constants and add spiral ;)

Also, it doesn't seem to open the bank, it just walks there then errors out.


Nava2

Sir R. M8gic1an

2008-06-10 01:08:08

true, i edited and forgot those compiling errors. it gives an error before opening bank cus there are no players declare and OpenBankQuiet needs them to be declared. and no, i counted the time without the opening of the bank.

~RM

Nava2

2008-06-10 18:29:01

Oh I added this to my script, and it wouldnt open the bank until I added OpenBankQuiet outside the script.

Nava2

ZephyrsFury

2008-06-12 06:23:28

From: Rasta Magician

for i:=0 to High(ATPA) do //re joining the tpa, smaller split
TPA := CombineTPA(TPA, ATPA);


Minor detail and I'm not sure if it will speed it up at all but you can use MergeATPA (from WizzyPlugin).

Oh and I personally think OpenBank should be separate as people might like to use their own bank openers or a different SRL one.

Wizzup?

2008-06-12 06:43:56

It looks alright. Did OpenBankFast stop working? Fast is faster and better than Quiet.

IncEx(), it's so ugly, please don't ever use it again. :( :p

ZephyrsFury

2008-06-12 07:15:08

From: Wizzup?
IncEx(), it's so ugly, please don't ever use it again. :( :p


Looks fine to me. :)

I tested this function against Munk's. I won't compare the good points and bad points of each here but I did find that they were pretty much the same in terms of speed (both were around 0 to 16 ms each time). Anyway I don't think speed really matters in this case as its more about accuracy.

With this function in particular, I found that it clicked outside the bank a bit (especially in Draynor where it clicked in the middle of the square). It also happened a couple of times in Varrock West Bank. I also noticed that you use tolerance to find the colour of the NPC dots. The NPC dots have a couple of constant colour pixels and you shouldn't need tolerance to find them.

Anyway, nice job. :D

PvH

2008-06-12 07:38:24

ZephyrsFury, draynor is very hard, since there are always firemakers/npc's walking, and thats why dtms and things will fail (they have same kind of position , at another place)