SRL Archive - SRL Archives

FindBankEx - Smart bank opener for all f2p banks.


EvilChicken!

2008-07-05 15:55:57

Hi, and thanks for opening this thread.

Opens all f2p banks, probably works with most member banks as well.
Replaces all bankopeners in Bank.scar.

What I mean by saying this is a 'smart' bankopener, is .. Sigh. Read.

Function SetUpBanks loads pre-picked colors of banks. I've picked two unique colors of each bank, and the procedure is made to be easily modifiable for easy addition or removal of any colors. These pre-picked colors are loaded into a 2D integer array, or one color array for every bank.

The main procedure, FindBankEx, will by itself call the SetUpBanks procedure if it has not been called already.

FindBankEx will, firstly, search for the bank with 0 tolerance for the colors in the variable array for the search target bank. If it finds the bank, it will move the color which was used to find the bank, one place ahead in the previously mentioned color array, if it isn't already in the first place if the array.

If the search with zero tolerance is of no result, a new search, this time with 10 tolerance, will be done. If it finds the bank this time, it will add the color used to find the bank, to that bank's pre-picked color array.

This menthod is preferable, at least by me, for following reasons:
  • Almost every single script that opens a bank, does it more than once. Since this procedure is progressive, it will (if not already) finally end up in being a flawless bank opener.
  • The first search which uses 0 tolerance, contributes to reducing lag and improving the general performance of the script.


There are probably more reasons, but I can't think of any more now because I'm really hungry. (In case you're interested: The scent of delicious, juicy chicken is kinda distracting me.)

Oh, and. The procedure(s) are extensively tested, and also contains random checks at the relevant places. If the function encounters a random, and SRL solves it, it will try to open the bank a second time after handling the random.

program New;
{.include SRL/SRL.scar}

var// THESE ARE GLOBAL VARIABLES!
BankColors: T2DIntArray;
BankArraysSetUp: Boolean;


procedure SetUpBanks;
begin // If you know what you're doing, feel free to add more colors.
SetArrayLength(BankColors, 8); // Amount of banks.
SetArraylength(BankColors[0], 2); // Amount of colors for Lumbridge Bank.
SetArraylength(BankColors[1], 2); // Amount of colors for Al kharid Bank.
SetArraylength(BankColors[2], 2); // Amount of colors for Falador East Bank.
SetArraylength(BankColors[3], 2); // Amount of colors for Falador West Bank.
SetArraylength(BankColors[4], 2); // Amount of colors for Varrock East Bank.
SetArraylength(BankColors[5], 2); // Amount of colors for Varrock West Bank.
SetArraylength(BankColors[6], 2); // Amount of colors for Edgeville Bank.
SetArraylength(BankColors[7], 3); // Amount of colors for Draynor Bank.

BankColors[0][0] := 7963276; // [0] = Lumbridge Bank
BankColors[0][1] := 4215652;

BankColors[1][0] := 9018028; // [1] = Al Kharid Bank
BankColors[1][1] := 7772857;

BankColors[2][0] := 4938601; // [2] = Falador East Bank
BankColors[2][1] := 3954281;

BankColors[3][0] := 3952736; // [3] = Falador West Bank
BankColors[3][1] := 3756131;

BankColors[4][0] := 7110534; // [4] = Varrock East Bank
BankColors[4][0] := 2970721;

BankColors[5][0] := 2904413; // [5] = Varrock West Bank
BankColors[5][1] := 4539722;

BankColors[6][0] := 2571851; // [6] = Edgeville Bank
BankColors[6][1] := 6647670;

BankColors[7][0] := 339006; // [7] = Draynor West Bank
BankColors[7][1] := 4282984;
BankColors[7][2] := 4145738;

BankArraysSetUp := True; // Global boolean.
end;

function OpenBankEx(Which: string): Boolean; // Thanks to Zeph for help and support.
var // Also thanks to GoF for being .. Beyond epic. (My sig..)
ATPA: T2DPointArray;
TPA: TPointArray;
A, B, C, D, X, Y, ClickedColor: Integer;
BankNum, UTWaits, curCTS: Byte;
begin
Result := False;
if not LoggedIn then exit; // or NoGameTab.. ?
if not BankArraysSetUp then SetUpBanks;
case LowerCase(Which) of
'lb', 'lumbridge': BankNum := 0;
'ak', 'al kharid': BankNum := 1;
'feb', 'falador east': BankNum := 2;
'fwb', 'falador west': BankNum := 3;
'veb', 'varrock east': BankNum := 4;
'vwb', 'varrock west': BankNum := 5;
'eb', 'edgeville': BankNum := 6;
'db', 'draynor': BankNum := 7;
else
begin
srl_Warn('OpenBankEx', Which + ' is not a valid bank', warn_AllVersions);
Exit;
end;
end;
B := Length(BankColors[BankNum]) - 1;
curCTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
for A := 0 to B do
begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, BankColors[BankNum][A], MSX1, MSY1, MSX2, MSY2, 12);
if GetArrayLength(TPA) = 0 then Continue;
ATPA := TPAtoATPAEx(TPA, 30, 10);
D := Length(ATPA) - 1;
for C := 0 to D do
begin
MiddleTPAEx(ATPA[C], X, Y);
MMouse(X, Y, 16, 6);
UTWaits := 0;
while LoggedIn and (not(Pos('ank booth', RS_GetUpText) > 0)) do
begin
Wait(50 + Random(45));
Inc(UTWaits); // UT = UpText, as you might've guessed already.
if UTWaits > 10 then Break;
end;
if UTWaits > 10 then Continue;
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, False);
Wait(150 + Random(175));
if not ChooseOption('quickly') then Continue;
UTWaits := 0;
if FTWait(2) then OpenBankEx(Which);
FFlag(0);
if FTWait(2) then OpenBankEx(Which);
while LoggedIn and (not BankScreen) do
begin
Inc(UTWaits);
if FTWait(2 + Random(2)) then OpenBankEx(Which);
if UTWaits > 6 then Break;
end;
if UTWaits > 6 then Continue;
if A > 0 then Swap(BankColors[BankNum][A], BankColors[BankNum][A - 1]);
if FTWait(5) then OpenBankEx(Which);
Result := True;
ColorToleranceSpeed(curCTS);
WriteLn(Which + ' bank was found without using tolerance.');
Exit;
end;
end;

for A := 0 to B do
begin
FindColorsSpiralTolerance(MSCX, MSCY, TPA, BankColors[BankNum][A], MSX1, MSY1, MSX2, MSY2, 10);
if GetArrayLength(TPA) = 0 then Continue;
ATPA := TPAtoATPAEx(TPA, 30, 10);
D := Length(ATPA) - 1;
for C := 0 to D do
begin
MiddleTPAEx(ATPA[C], X, Y);
ClickedColor := GetColor(X, Y);
MMouse(X, Y, 16, 6);
UTWaits := 0;
while LoggedIn and (not Pos('ank booth', RS_GetUpText) > 0) do
begin
Wait(50 + Random(45));
Inc(UTWaits);
if UTWaits > 10 then break;
end;
if UTWaits > 10 then Continue;
GetMousePos(X, Y);
Mouse(X, Y, 0, 0, False);
Wait(150 + Random(175));
if not ChooseOption('quickly') then Continue;
if FTWait(2) then OpenBankEx(Which);
UTWaits := 0;
while LoggedIn and (not BankScreen) do
begin
Inc(UTWaits);
if FTWait(2 + Random(2)) then OpenBankEx(Which);
if UTWaits > 6 then Break;
end;
if UTWaits > 6 then Continue;
X := Length(BankColors[BankNum]);
SetArrayLength(BankColors[BankNum], X + 1);
BankColors[BankNum][X] := ClickedColor; // Add the clicked color the the
if FTWait(5) then OpenBankEx(Which);
Result := True; // corresponding bank's color array.
ColorToleranceSpeed(curCTS);
WriteLn(Which + ' bank was found using tolerance.');
Exit;
end;
end;
if FTWait(5) then OpenBankEx(Which);
Result := True;
ColorToleranceSpeed(curCTS);
end;

begin
SetUpSRL;
NumberOfPlayers(1);
Players[0].Nick := 'moo'; // to avoid AntiRandoms.scar conflicts.
ActivateClient;
Wait(500);
OpenBankEx('lb');
end.


Please do comment on anything, especially bugs and your opinion on these functions.

Sir R. M8gic1an

2008-07-05 16:04:21

i didn't look much through the code, only read what you wrote. I'm happy to see you're using the same principle as SmartColors, i think it's great, what i suggest is that once the mouse finds the bank you check th exact color of that place and if the color is rare in the MainScreen then add it to the color array.

i will definitely have a better look and tweak it myself when i get back ;)

~RM

LordGregGreg

2008-07-05 16:10:44

The only scarry part I see is when it has to find that bank the first time…

also, dont the rs colors keep changing over game time? so eventually even colors that you found to be correct, will stop working, and eventually you will just have a really big array?

ihavnt looked closely enough to see, but make sure that is not the case.

EvilChicken!

2008-07-05 16:52:04

From: Rasta Magician
i didn't look much through the code, only read what you wrote. I'm happy to see you're using the same principle as SmartColors, i think it's great, what i suggest is that once the mouse finds the bank you check th exact color of that place and if the color is rare in the MainScreen then add it to the color array.

i will definitely have a better look and tweak it myself when i get back ;)

~RM


Yes, this is Tara's method, but every single bit (literary :p) is a result of my own key presses. It adds a color to the array, but it does not check it that is a common color, and I don't think that it is necessary either.

Oh, and. Please PM me or post your editing results ^.^

From: LordGregGreg
The only scarry part I see is when it has to find that bank the first time…

also, dont the rs colors keep changing over game time? so eventually even colors that you found to be correct, will stop working, and eventually you will just have a really big array?

ihavnt looked closely enough to see, but make sure that is not the case.


I knew you didn't look closely. ø(-_-)ø
As I wrote, the most commonly used colors are moved to the front of the array. And, the preset colors I picked are very good, not to mention that the function has to fail a whole of 4 searches to not find the bank. An that is only the first time.


Try it and see. I've posted the functions as a whole script that is ready to be copied and pasted into your scar, just copy, paste, log in and run.

ZephyrsFury

2008-07-06 00:43:47

Looks great. Only thing though is that its not compatible with Draynor Bank. And do the colours have to be picked from a specific part of the booth or can it just be any part that has a unique colour?

EvilChicken!

2008-07-06 07:19:42

From: ZephyrsFury
Looks great. Only thing though is that its not compatible with Draynor Bank. And do the colours have to be picked from a specific part of the booth or can it just be any part that has a unique colour?


zomg zomg I forgot Draynor! *rushes to fix*
Huge thanks, in addition to the potato (cookie got old) you get for looking at this.

And, this function only needs (an) unique color(s). Or just any color from the bank will do. The uniqueness will just (in most cases) contribute to the bank being found faster. And, since this will open up the bank from any camera direction and angle, the color does not need to be of any specific part. Although I've picked two unique colors in the pre-picked color arrays, one from the glass part and one from the bank booth "desk" part center.


I'll add Draynor bank as soon as I can. Probably within the hour.

ZephyrsFury

2008-07-06 08:44:33

From: EvilChicken!
zomg zomg I forgot Draynor! *rushes to fix*
Huge thanks, in addition to the potato (cookie got old) you get for looking at this.


I believe you also forgot Edgeville :p.

I've been looking at the code and testing a bit and I've found a couple of small bugs. First of all:


for C := 0 to D do
begin
MiddleTPAEx(ATPA[C], X, Y);
MMouse(X, Y, 16, 6);
UTWaits := 0;
while LoggedIn and (not Pos('ank booth', RS_GetUpText) > 0) do
begin
Wait(50 + Random(45));
Inc(UTWaits); // UT = UpText, as you might've guessed already.
if UTWaits > 10 then
begin
Break;
Continue;
end;
end;

The Continue will not be called as you've already broken out of the loop. You'll need to do something like this:


for C := 0 to D do
begin
MiddleTPAEx(ATPA[C], X, Y);
MMouse(X, Y, 16, 6);
UTWaits := 0;
while LoggedIn and (not Pos('ank booth', RS_GetUpText) > 0) do
begin
Wait(50 + Random(45));
Inc(UTWaits); // UT = UpText, as you might've guessed already.
if UTWaits > 10 then
Break;
end;
if (UTWaits > 10) then Continue;

Also:


while LoggedIn and (not Pos('ank booth', RS_GetUpText) > 0) do

The

(not Pos('ank booth', RS_GetUpText) > 0)

will always result in False. (Don't ask me why.. I'm tired and can't think). Its got something to do with the logic operator 'not' though.

You'll need to make it:


while LoggedIn and (not(Pos('ank booth', RS_GetUpText) > 0)) do

or just make it:


while LoggedIn and (not(IsUpText('Bank booth'))) do

Also when I tested the function in VWB it kept moving the mouse to the ground. I think the ground colour is too similar to the booth colour.

I also think you can shorten the function down by half if you combine the two loops together in another loop:


function OpenBankEx(Which: string): Boolean;
begin
for II := 0 to 1 do
begin
if (FindColorsTolerance(TPA,...., i * 10 {Tolerance})) then
//blah blah
end;
end;

Something like that. :)

EvilChicken!

2008-07-06 18:34:30

Zeph, in addition to being epic, you are now credited in my function. (No, it is absolutely not a big thing, and I would absolutely neglect it if I were you.) I fixed all the flaws you showed be, and added the two banks. I didn't bother to shorten the function.
Because.. I just didn't bother. And that byte takes up memory. :o
But genius idea.


Huge, enormous, big thanks to you.
Also thanks to Nielsie95 who bothered to take the time to look at it.