Olly
12-13-2012, 06:30 PM
The blue colours of openbanknpc function needed updating so I thought I might as well add the other banker colours (blue, green, grey). I could make a pull request for this if people want it and use the current openbankernpc (which is the blue banker) as a wrapper so it doesn't break all scripts that current use it.
OpenBankNPCEx - changes from regular openbanknpc:
added colours
changed tpatoatpa to the wrapper function
increased uptext time
added more mouse randomness
(*
OpenBankNPCEx
~~~~~~~~~~~
.. code-block:: pascal
function OpenBankNPCEx(color:string): Boolean;
Opens the bank by using Banker.
Valid arguments are:
'blue'
'green'
'gray', 'grey'
.. note::
Author: Home
Last Modified: December 13 by Ollybest
Example:
.. code-block:: pascal
if OpenBankNPCEx('blue') then
Withdraw(...);
*)
function OpenBankNPCEx(Color: String): Boolean;
var
NPCBox :TBox;
Colors, NPCArray :TPointArray;
ATPA: T2DPointArray;
MSNPC, NPCPoint :TPoint;
CTS, C, II, I :Integer;
Info: TVariantArray;
begin
Result := False;
if (not LoggedIn) then
Exit;
Result := (BankScreen) or (PinScreen);
If Result then
Exit;
case LowerCase(Color) of { Color Tol Hue Sat }
'blue': Info := [4336177, 15, 0.16, 0.66];
'green': Info := [1988959, 17, 0.11, 1.52];
'gray', 'grey': Info := [5855838, 8, 0.42, 0.11];
else
begin
srl_Warn('OpenBankNPCEx', 'Unknown banker color: '+Color, warn_AllVersions);
Exit;
end;
end;
NPCArray := GetMinimapDots('NPC');
If Length(NPCArray) < 1 then
Exit;
SortTPAFrom(NPCArray, Point(MMCX, MMCY));
for I := 0 to High(NPCArray) do
begin
NPCPoint := MMToMS(NPCArray[I])
If (NPCPoint.x = -1) and (NPCPoint.y = -1) then
Continue;
with NPCPoint do
NPCBox := IntToBox(Max(X - 40, MSX1), Max(Y - 40, MSY1), Min(X + 40, MSX2), Min(Y + 40, MSY2));
If PixelShift(NPCBox, 150) > 500 then
Continue;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Info[2], Info[3]);
FindColorsTolerance(Colors, Info[0], NPCBox.X1, NPCBox.Y1, NPCBox.X2, NPCBox.Y2, Info[1]);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
TPAtoATPAExWrap(Colors, 15,25, ATPA);
SortATPASize(ATPA, True);
//SMART_DebugATPA(False, ATPA);
for II := 0 to High(ATPA) do
begin
MSNPC := MiddleTPA(ATPA[II]);
MMouse(MSNPC.X, MSNPC.Y, RandomRange(-3, 3), RandomRange(-3, 3));
If WaitUpTextMulti(['ooth', 'anker', '-to Banker'], 250 + Random(100)) then
begin
ClickMouse2(False);
If WaitOptionMulti(['Bank B', 'nk B', 'ank Banker'], 600 + Random(200)) then
MarkTime(c);
Repeat
Wait(RandomRange(50, 100));
Until (BankScreen) or (PinScreen) or (TimeFromMark(C) > 4500);
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);
Result := (BankScreen) or (PinScreen);
If Result then
Exit;
end;
end;
end;
end;
OpenBankCounter:
finds the lightish colour of the bounds and searches in there for the counter
http://i.imgur.com/wMkyX.png
function OpenBankCounter: Boolean;
var
X, Y, CTS, C, L, i: Integer;
TPA, TPAA: TPointArray;
ATPA, ATPAA : T2DPointArray;
BoxArr: TBoxArray;
begin
Result := (BankScreen) or (PinScreen);
if (not LoggedIn) or (Result) then
Exit;
//getting the color of the light line around the counter
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.09, 0.13);
FindColorsTolerance(TPA, 5399914, MSX1, MSY1, MSX2, MSY2, 3);
SplitTPAWrap(TPA, 2, ATPA);
//adding the bounds to an array if the length is more then 140
for i := 0 to high(ATPA) do
if Length(ATPA[i]) > 140 then
begin
L := Length(BoxArr);
SetLength(BoxArr, L + 1);
BoxArr[L] := GetTPABounds(ATPA[i]);
end;
if Length(BoxArr) < 1 then
begin
srl_Warn('OpenBankCounter', 'Didnt find enough color to get box bounds', warn_AllVersions);
exit;
end;
//searching in the box array for the counter colors
SetLength(ATPAA, Length(BoxArr));
SetColorSpeed2Modifiers(0.30, 0.18);
for i := 0 to high(BoxArr) do
with BoxArr[i] do
FindColorsTolerance(ATPAA[i], 4346197, X1, Y1, X2, Y2, 3);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
MergeATPAWrap(ATPAA, TPAA);
SplitTPAExWrap(TPAA, 2, 4, ATPAA);
SortATPAFromFirstPoint(ATPAA, Point(MSCX, MSCY));
if Length(TPA) < 1 then
begin
srl_Warn('OpenBankCounter', 'Didnt find enough color to search for in bounds!', warn_AllVersions);
Exit;
end;
//looping though the counter tpa's seeing if we have a bank counter
for i := 0 to high(ATPAA) do
if length(atpa[i]) > 50 then
begin
MiddleTPAEx(ATPAA[i], X, Y);
//SMART_DrawCircle(False, Point(X, Y), 5, False, clLime);
MMouse(X, Y, RandomRange( - 5, 5), RandomRange( - 7, 7));
if WaitUpTextMulti(['Bank Counter', 'ank Count', 'Bank Co', 'Counter / '], 300 + Random(100)) then
begin
ClickMouse2(True);
Flag;
MarkTime(c);
repeat
Wait(RandomRange(50, 100));
until (BankScreen) or (PinScreen) or (TimeFromMark(C) > 5000);
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);
Result := (BankScreen) or (PinScreen);
if Result then
Exit;
end;
end;
end;
OpenBankNPCEx - changes from regular openbanknpc:
added colours
changed tpatoatpa to the wrapper function
increased uptext time
added more mouse randomness
(*
OpenBankNPCEx
~~~~~~~~~~~
.. code-block:: pascal
function OpenBankNPCEx(color:string): Boolean;
Opens the bank by using Banker.
Valid arguments are:
'blue'
'green'
'gray', 'grey'
.. note::
Author: Home
Last Modified: December 13 by Ollybest
Example:
.. code-block:: pascal
if OpenBankNPCEx('blue') then
Withdraw(...);
*)
function OpenBankNPCEx(Color: String): Boolean;
var
NPCBox :TBox;
Colors, NPCArray :TPointArray;
ATPA: T2DPointArray;
MSNPC, NPCPoint :TPoint;
CTS, C, II, I :Integer;
Info: TVariantArray;
begin
Result := False;
if (not LoggedIn) then
Exit;
Result := (BankScreen) or (PinScreen);
If Result then
Exit;
case LowerCase(Color) of { Color Tol Hue Sat }
'blue': Info := [4336177, 15, 0.16, 0.66];
'green': Info := [1988959, 17, 0.11, 1.52];
'gray', 'grey': Info := [5855838, 8, 0.42, 0.11];
else
begin
srl_Warn('OpenBankNPCEx', 'Unknown banker color: '+Color, warn_AllVersions);
Exit;
end;
end;
NPCArray := GetMinimapDots('NPC');
If Length(NPCArray) < 1 then
Exit;
SortTPAFrom(NPCArray, Point(MMCX, MMCY));
for I := 0 to High(NPCArray) do
begin
NPCPoint := MMToMS(NPCArray[I])
If (NPCPoint.x = -1) and (NPCPoint.y = -1) then
Continue;
with NPCPoint do
NPCBox := IntToBox(Max(X - 40, MSX1), Max(Y - 40, MSY1), Min(X + 40, MSX2), Min(Y + 40, MSY2));
If PixelShift(NPCBox, 150) > 500 then
Continue;
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(Info[2], Info[3]);
FindColorsTolerance(Colors, Info[0], NPCBox.X1, NPCBox.Y1, NPCBox.X2, NPCBox.Y2, Info[1]);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
TPAtoATPAExWrap(Colors, 15,25, ATPA);
SortATPASize(ATPA, True);
//SMART_DebugATPA(False, ATPA);
for II := 0 to High(ATPA) do
begin
MSNPC := MiddleTPA(ATPA[II]);
MMouse(MSNPC.X, MSNPC.Y, RandomRange(-3, 3), RandomRange(-3, 3));
If WaitUpTextMulti(['ooth', 'anker', '-to Banker'], 250 + Random(100)) then
begin
ClickMouse2(False);
If WaitOptionMulti(['Bank B', 'nk B', 'ank Banker'], 600 + Random(200)) then
MarkTime(c);
Repeat
Wait(RandomRange(50, 100));
Until (BankScreen) or (PinScreen) or (TimeFromMark(C) > 4500);
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);
Result := (BankScreen) or (PinScreen);
If Result then
Exit;
end;
end;
end;
end;
OpenBankCounter:
finds the lightish colour of the bounds and searches in there for the counter
http://i.imgur.com/wMkyX.png
function OpenBankCounter: Boolean;
var
X, Y, CTS, C, L, i: Integer;
TPA, TPAA: TPointArray;
ATPA, ATPAA : T2DPointArray;
BoxArr: TBoxArray;
begin
Result := (BankScreen) or (PinScreen);
if (not LoggedIn) or (Result) then
Exit;
//getting the color of the light line around the counter
CTS := GetColorToleranceSpeed;
ColorToleranceSpeed(2);
SetColorSpeed2Modifiers(0.09, 0.13);
FindColorsTolerance(TPA, 5399914, MSX1, MSY1, MSX2, MSY2, 3);
SplitTPAWrap(TPA, 2, ATPA);
//adding the bounds to an array if the length is more then 140
for i := 0 to high(ATPA) do
if Length(ATPA[i]) > 140 then
begin
L := Length(BoxArr);
SetLength(BoxArr, L + 1);
BoxArr[L] := GetTPABounds(ATPA[i]);
end;
if Length(BoxArr) < 1 then
begin
srl_Warn('OpenBankCounter', 'Didnt find enough color to get box bounds', warn_AllVersions);
exit;
end;
//searching in the box array for the counter colors
SetLength(ATPAA, Length(BoxArr));
SetColorSpeed2Modifiers(0.30, 0.18);
for i := 0 to high(BoxArr) do
with BoxArr[i] do
FindColorsTolerance(ATPAA[i], 4346197, X1, Y1, X2, Y2, 3);
SetColorSpeed2Modifiers(0.2, 0.2);
ColorToleranceSpeed(CTS);
MergeATPAWrap(ATPAA, TPAA);
SplitTPAExWrap(TPAA, 2, 4, ATPAA);
SortATPAFromFirstPoint(ATPAA, Point(MSCX, MSCY));
if Length(TPA) < 1 then
begin
srl_Warn('OpenBankCounter', 'Didnt find enough color to search for in bounds!', warn_AllVersions);
Exit;
end;
//looping though the counter tpa's seeing if we have a bank counter
for i := 0 to high(ATPAA) do
if length(atpa[i]) > 50 then
begin
MiddleTPAEx(ATPAA[i], X, Y);
//SMART_DrawCircle(False, Point(X, Y), 5, False, clLime);
MMouse(X, Y, RandomRange( - 5, 5), RandomRange( - 7, 7));
if WaitUpTextMulti(['Bank Counter', 'ank Count', 'Bank Co', 'Counter / '], 300 + Random(100)) then
begin
ClickMouse2(True);
Flag;
MarkTime(c);
repeat
Wait(RandomRange(50, 100));
until (BankScreen) or (PinScreen) or (TimeFromMark(C) > 5000);
if (Players[CurrentPlayer].Pin <> '') then
InPin(Players[CurrentPlayer].Pin);
Result := (BankScreen) or (PinScreen);
if Result then
Exit;
end;
end;
end;