kanah
2011-12-08 23:40:39
I was having some problems using OpenBank and OpenBankNpc so I crafted this sweet function.
function OpenLumbridgeBank: Boolean;
//This finds the counter and the glass pair to open the bank
// by: Kanah 12/8/11
var
CounterInfo,GlassInfo: TExtendedArray;
CounterTPA,GlassTPA,probBank: TPointArray;
CounterATPA,TempATPA: T2DPointArray;
tmpCTS,i,q,len: Integer;
SearchBox: TBox;
begin
CounterInfo := [6978442,4,0.08,0.18]; //[Color,Tol,HueMod,SatMod]
GlassInfo := [9278106,7,0.28,0.48];
tmpCTS := GetColorToleranceSpeed;
SetColorToleranceSpeed(2);
SetColorspeed2Modifiers(CounterInfo[2],CounterInfo[3]);
//Find the counter colors
if (FindColorsToleranceOptimised(CounterTPA,Round(CounterInfo[0]),MSX1,MSY1,MSX2,MSY2,Round(CounterInfo[1]))) then
begin
//Now split it into groups, that are continuous color blocks
SplitTPAWrap(CounterTPA,1,CounterATPA);
len := length(CounterATPA);
SetLength(TempATPA,len);
//DrawDotsMulti(true,CounterATPA);
//loop Through and check the lengths, get rid of short ones
for i := 0 to (len-1) do
begin
if length(CounterATPA[i]) > 180 then
begin
TempATPA[q] := CopyTPA(CounterATPA[i]);
Inc(q);
end;
end;
len := q;
SetLength(TempATPA,len);
CounterATPA := CopyATPA(TempATPA);
SetLength(CounterATPA,len);
//DrawDotsMulti(true,CounterATPA);
//Now lets find the 4 that are close to each other
MergeATPAWrap(CounterATPA,CounterTPA);
//Split it again, this will make that group of 4 into 1
SplitTPAWrap(CounterTPA,50,CounterATPA);
len := length(CounterATPA);
//DrawDotsMulti(true,CounterATPA);
//Grab the biggest one and that is the 4 counters
if not(len = 0) then
begin
SortATPASize(CounterATPA,true);
CounterTPA := CopyTPA(CounterATPA[0]);
SearchBox := GetTPABounds(CounterTPA);
//Expand it a little in the y direction, in case we facing exactly north or south
IncEx(SearchBox.y1,-10);
IncEX(SearchBox.Y2,10);
//Now I'm going to go ahead and seperate the counters back into individual counters; as
// a back in case the glass can't be found
SplitTPAWrap(CounterTPA,1,CounterATPA);
len := length(CounterATPA);
//SMART_DrawBoxEx(false,SearchBox,clRed);
SetLength(probBank,len);
for i := 0 to (len-1) do
begin
probBank[i] := MiddleTPA(CounterATPA[i]);
end;
end;
//Now begins the search for the glass
SetColorspeed2Modifiers(GlassInfo[2],GlassInfo[3]);
if FindColorsToleranceOptimised(GlassTPA,Round(GlassInfo[0]),SearchBox.X1,SearchBox.Y1,SearchBox.X2,SearchBox.Y2,Round(GlassInfo[1])) then
begin
//Found some glass points
//SMART_DrawDotsEx(false,GlassTPA,clRed);
Inc(len);
SetLength(probBank,len);
probBank[len-1] := middleTPA(GlassTPA);
end else
writeln('Failed to find any glass points');
//Now i need to mouse over each one and check the uptext
for i := (len-1) downto 0 do
begin
MMouse(probBank[i].x,probBank[i].y,0,0);
if (WaitUptext('ank bo',500)) then
begin
//here goes all the bank stuff
for q := 0 to 3 do
begin
Mouse(probBank[i].x,probBank[i].y,0,0,false);
wait(100);
ChooseOption('qui');
if (WaitFunc(@BankScreen,100,3000)or(PinScreen)) then
begin
if (PinScreen) then
begin
if not(InPin(Players[CurrentPlayer].Pin)) then
CloseBank;
end;
//Force end the loops
i := -1;
q := 4;
end;
end;
end;
end;
end else
writeln('Failed to find counter colors');
SetColorToleranceSpeed(tmpCTS);
SetColorSpeed2Modifiers(0.2, 0.2);
Result := BankScreen;
if (Result) then
begin
writeln('opened bank');
end else
writeln('failed to open bank');
end;