SRL Archive - MSI Suggestions

MSI_Bankstuff


Naum

2009-10-16 13:02:00

Hey, I made the functions. They just need to be tested, I would love it if you could test 'em :), you can test on this account:


Bank.Scar:

Type TItemArray = Array Of TItem;

{******************************************************************************}
{ Function MSI_OpenBank(Bank, tPin: string): Boolean; }
{ By: NCDS, minor edit by NaumanAkhlaQ }
{ Rev: 1 }
{ Date: 18 Sep 09 }
{ Description: Opens any bank supported by SRL. tPin = RS Bank Pin. }
{ Set to '0' if you don't have one. }
{******************************************************************************}
function MSI_OpenBank(Bank, tPin: string): Boolean;
var i : Integer;
begin
for i := 0 to 3 do
if OpenBank(Bank, True, False) then
Break;

if not BankScreen and not PinScreen then Exit;
if PinScreen and (Length(tPin) > 1) then
InPin(tPin);

Result := WaitFunc(@BankScreen, 70, 2900 + Random(100))
end;


{********************************************************************************}
{ Function MSI_Deposit(Items : TItemArray; Amount : TIntegerArray) : Boolean }
{ By: NaumanAkhlaQ }
{ Rev: 18 }
{ Date: 16 Oct 09 }
{ Description: Deposits an Item using the TItem type }
{********************************************************************************}

Function MSI_Deposit(Items : TItemArray; Amount : TIntegerArray) : Boolean;
Var ATPA2 : Array Of TPointArray; //The length is the same as items.colors
ATPA : T2DPointArray;
I, BX, BY, II, DX, DY, XX, YY, Tol : Integer;
BitmapCheck, TextCheck, DTMCheck : Boolean;
TB : TBox;

Begin
If Not WaitFunc(@BankScreen, 70, 1300) Then //Just in case
Exit
Else
For I := 0 To High(Items) Do
Begin
Tol := 0;
Repeat
BitmapCheck := FindBitmapToleranceIn(Items[I].BMP, BX, BY, MIX1, MIY1, MIX2, MIY2, Tol);
IncEx(Tol, 5);
Until(BitmapCheck) xOr (Tol > 40);

If Not BitmapCheck Then
Begin
SetArrayLength(ATPA2, High(Items[I].Colors)+1)

For II := 0 To High(Items[I].Colors) Do
FindColorsTolerance(ATPA2[II], Items[I].Colors[II], MIX1, MIY1, MIX2, MIY2, 15);

ATPA2[0] := MergeATPA(ATPA2);
ATPA := SplitTPA(ATPA2[0], 5);

For II := 0 To High(ATPA) Do
Begin
TB := IntToBox(ATPA[II][0].x - 50, ATPA[II][0].y - 50,
ATPA[II][0].x + 43, ATPA[II][0].y + 44);

DTMCheck := DTMRotated(Items[I].DTM, DX, DY, TB.x1, TB.y1, TB.x2, TB.y2);
MMouse(DX, DY, 2, 3);
TextCheck := WaitUpTextMulti(Items[I].UpText, 150+Random(30));
If TextCheck Then Break;
End;
End;

If BitmapCheck Or TextCheck Then
Begin
If BX + BY > 0 Then
MMouse(BX, BY, 2, 3);

TextCheck := WaitUpTextMulti(Items[I].UpText, 1200);
GetMousePos(XX, YY);
Result := TextCheck;

If Result Then
Begin
Mouse(XX, YY, 0, 0, False);

If Amount[I] >= 28 Then
Result := WaitOption('-All', 1200);

If InIntArray([1, 5, 10], Amount[I]) Then
Result := WaitOption('-'+IntToStr(Amount[I]), 1200)
Else
Begin
If WaitOption('-X', 900) Then
If WaitColor(254, 401, ClBlack, 0, 1200) Then
TypeSend(IntToStr(Amount[I]));

Result := True;
End;

If Result Then Exit;

{ MSIDebug('MSI_Deposit', 'Deposited Amount '+IntToStr(Amount[I])+
' Of Item : ''' +Items[I].Name+'''', Debug_SmallDetails); }
End;
End;
End;
End;


{********************************************************************************}
{ Function MSI_Withdraw(Items : TItemArray; Amount : TIntegerArray) : Boolean }
{ By: NaumanAkhlaQ }
{ Rev: 18 }
{ Date: 16 Oct 09 }
{ Description: Widthraws an Item using the TItem type }
{********************************************************************************}

Function MSI_Withdraw(Items : TItemArray; Amount : TIntegerArray) : Boolean;
Var ATPA2 : Array Of TPointArray; //The length is the same as items.colors
ATPA : T2DPointArray;
I, BX, BY, II, DX, DY, XX, YY, Tol : Integer;
BitmapCheck, TextCheck, DTMCheck : Boolean;
WithdrawP : TPoint;
TB : TBox;

Begin
If Not WaitFunc(@BankScreen, 70, 1300) Then //Just in case
Exit
Else
For I := 0 To High(Items) Do
Begin
Tol := 0;
Repeat
BitmapCheck := FindBitmapToleranceIn(Items[I].BMP, BX, BY, MBX1, MBY1, MBX2, MBY2, Tol);
IncEx(Tol, 5);
Until(BitmapCheck) xOr (Tol > 40);

If Not BitmapCheck Then
Begin
SetArrayLength(ATPA2, High(Items[I].Colors)+1)

For II := 0 To High(Items[I].Colors) Do
FindColorsTolerance(ATPA2[II], Items[I].Colors[II], MBX1, MBY1, MBX2, MBY2, 15);

ATPA2[0] := MergeATPA(ATPA2);
ATPA := SplitTPA(ATPA2[0], 5);

For II := 0 To High(ATPA) Do
Begin
TB := IntToBox(ATPA[II][0].x - 50, ATPA[II][0].y - 50,
ATPA[II][0].x + 50, ATPA[II][0].y + 50);

DTMCheck := DTMRotated(Items[I].DTM, DX, DY, TB.x1, TB.y1, TB.x2, TB.y2);
MMouse(DX, DY, 2, 3);
TextCheck := WaitUpTextMulti(Items[I].UpText, 150+Random(30));
If TextCheck Then Break;
End;
End;

If BitmapCheck Or TextCheck Then
Begin
If BX + BY > 0 Then
MMouse(BX, BY, 2, 3);

TextCheck := WaitUpTextMulti(Items[I].UpText, 1200);
GetMousePos(XX, YY);
Result := TextCheck;

If Result Then
Begin
Items[I].ItemP := Point(XX, YY);
WithDrawP := MSTPointToBankPoint(Point(XX, YY));
Withdraw(WithDrawP.X, WithDrawP.Y, Amount[I]);
{ MSIDebug('MSI_Withdraw', 'Withdrew Amount '+IntToStr(Amount[I])+
' Of Item : ''' +Items[I].Name+'''', Debug_SmallDetails); }
End;
End;
End;
End;

To test all the functions:

{.Include SRL/SRL.Scar}
{.Include SRL/SRL/Misc/Debug.Scar}

Type
TItem = Record
Name : String;
UpText : TStringArray;
ItemP : TPoint;
Stackable : Boolean;
Colors : TIntegerArray;
DTM : integer;
BMP : integer;
End;

Type TItemArray = Array Of TItem;

{******************************************************************************}
{ Function MSI_OpenBank(Bank, tPin: string): Boolean; }
{ By: NCDS, minor edit by NaumanAkhlaQ }
{ Rev: 1 }
{ Date: 18 Sep 09 }
{ Description: Opens any bank supported by SRL. tPin = RS Bank Pin. }
{ Set to '0' if you don't have one. }
{******************************************************************************}
function MSI_OpenBank(Bank, tPin: string): Boolean;
var i : Integer;
begin
for i := 0 to 3 do
if OpenBank(Bank, True, False) then
Break;

if not BankScreen and not PinScreen then Exit;
if PinScreen and (Length(tPin) > 1) then
InPin(tPin);

Result := WaitFunc(@BankScreen, 70, 2900 + Random(100))
end;


{********************************************************************************}
{ Function MSI_Deposit(Items : TItemArray; Amount : TIntegerArray) : Boolean }
{ By: NaumanAkhlaQ }
{ Rev: 18 }
{ Date: 16 Oct 09 }
{ Description: Deposits an Item using the TItem type }
{********************************************************************************}

Function MSI_Deposit(Items : TItemArray; Amount : TIntegerArray) : Boolean;
Var ATPA2 : Array Of TPointArray; //The length is the same as items.colors
ATPA : T2DPointArray;
I, BX, BY, II, DX, DY, XX, YY, Tol : Integer;
BitmapCheck, TextCheck, DTMCheck : Boolean;
TB : TBox;

Begin
If Not WaitFunc(@BankScreen, 70, 1300) Then //Just in case
Exit
Else
For I := 0 To High(Items) Do
Begin
Tol := 0;
Repeat
BitmapCheck := FindBitmapToleranceIn(Items[I].BMP, BX, BY, MIX1, MIY1, MIX2, MIY2, Tol);
IncEx(Tol, 5);
Until(BitmapCheck) xOr (Tol > 40);

If Not BitmapCheck Then
Begin
SetArrayLength(ATPA2, High(Items[I].Colors)+1)

For II := 0 To High(Items[I].Colors) Do
FindColorsTolerance(ATPA2[II], Items[I].Colors[II], MIX1, MIY1, MIX2, MIY2, 15);

ATPA2[0] := MergeATPA(ATPA2);
ATPA := SplitTPA(ATPA2[0], 5);

For II := 0 To High(ATPA) Do
Begin
TB := IntToBox(ATPA[II][0].x - 50, ATPA[II][0].y - 50,
ATPA[II][0].x + 43, ATPA[II][0].y + 44);

DTMCheck := DTMRotated(Items[I].DTM, DX, DY, TB.x1, TB.y1, TB.x2, TB.y2);
MMouse(DX, DY, 2, 3);
TextCheck := WaitUpTextMulti(Items[I].UpText, 150+Random(30));
If TextCheck Then Break;
End;
End;

If BitmapCheck Or TextCheck Then
Begin
If BX + BY > 0 Then
MMouse(BX, BY, 2, 3);

TextCheck := WaitUpTextMulti(Items[I].UpText, 1200);
GetMousePos(XX, YY);
Result := TextCheck;

If Result Then
Begin
Mouse(XX, YY, 0, 0, False);

If Amount[I] >= 28 Then
Result := WaitOption('-All', 1200);

If InIntArray([1, 5, 10], Amount[I]) Then
Result := WaitOption('-'+IntToStr(Amount[I]), 1200)
Else
Begin
If WaitOption('-X', 900) Then
If WaitColor(254, 401, ClBlack, 0, 1200) Then
TypeSend(IntToStr(Amount[I]));

Result := True;
End;

If Result Then Exit;

{ MSIDebug('MSI_Deposit', 'Deposited Amount '+IntToStr(Amount[I])+
' Of Item : ''' +Items[I].Name+'''', Debug_SmallDetails); }
End;
End;
End;
End;


{********************************************************************************}
{ Function MSI_Withdraw(Items : TItemArray; Amount : TIntegerArray) : Boolean }
{ By: NaumanAkhlaQ }
{ Rev: 18 }
{ Date: 16 Oct 09 }
{ Description: Widthraws an Item using the TItem type }
{********************************************************************************}

Function MSI_Withdraw(Items : TItemArray; Amount : TIntegerArray) : Boolean;
Var ATPA2 : Array Of TPointArray; //The length is the same as items.colors
ATPA : T2DPointArray;
I, BX, BY, II, DX, DY, XX, YY, Tol : Integer;
BitmapCheck, TextCheck, DTMCheck : Boolean;
WithdrawP : TPoint;
TB : TBox;

Begin
If Not WaitFunc(@BankScreen, 70, 1300) Then //Just in case
Exit
Else
For I := 0 To High(Items) Do
Begin
Tol := 0;
Repeat
BitmapCheck := FindBitmapToleranceIn(Items[I].BMP, BX, BY, MBX1, MBY1, MBX2, MBY2, Tol);
IncEx(Tol, 5);
Until(BitmapCheck) xOr (Tol > 40);

If Not BitmapCheck Then
Begin
SetArrayLength(ATPA2, High(Items[I].Colors)+1)

For II := 0 To High(Items[I].Colors) Do
FindColorsTolerance(ATPA2[II], Items[I].Colors[II], MBX1, MBY1, MBX2, MBY2, 15);

ATPA2[0] := MergeATPA(ATPA2);
ATPA := SplitTPA(ATPA2[0], 5);

For II := 0 To High(ATPA) Do
Begin
TB := IntToBox(ATPA[II][0].x - 50, ATPA[II][0].y - 50,
ATPA[II][0].x + 50, ATPA[II][0].y + 50);

DTMCheck := DTMRotated(Items[I].DTM, DX, DY, TB.x1, TB.y1, TB.x2, TB.y2);
MMouse(DX, DY, 2, 3);
TextCheck := WaitUpTextMulti(Items[I].UpText, 150+Random(30));
If TextCheck Then Break;
End;
End;

If BitmapCheck Or TextCheck Then
Begin
If BX + BY > 0 Then
MMouse(BX, BY, 2, 3);

TextCheck := WaitUpTextMulti(Items[I].UpText, 1200);
GetMousePos(XX, YY);
Result := TextCheck;

If Result Then
Begin
Items[I].ItemP := Point(XX, YY);
WithDrawP := MSTPointToBankPoint(Point(XX, YY));
Withdraw(WithDrawP.X, WithDrawP.Y, Amount[I]);
{ MSIDebug('MSI_Withdraw', 'Withdrew Amount '+IntToStr(Amount[I])+
' Of Item : ''' +Items[I].Name+'''', Debug_SmallDetails); }
End;
End;
End;
End;

{
Function MSI_GetToBank : Boolean;
Var TPA : Array [0..2] Of TPointArray;
ATPA : T2DPointArray;
I : Integer;

Begin
FindColors(TPA, 62965, MMX1, MMY1, MMX2, MMY2);


End; }

Var Thing : TItem;
Begin
SetupSRL;
With Thing Do
begin
Name := 'Berries';
UpText := ['erri', 'ava'];
ItemP := Point(0, 0);
Stackable := True;
Colors := [1011311, 3702656];
DTM := DTMFromString('78DA63EC63606098C68002F2F3F8C1342394C' +
'F381548CC21A0A60B53CD817D21286A008D26072C');
BMP := BitmapFromString(1, 3, 'beNoTLdsjPW2lRNsUABG2A9Q=');
end;
disguise('d');
MSI_Deposit([Thing], [5]);
disguise('w');
MSI_Withdraw([Thing], [44]);
End.

Make sure you have cavada berries in the inventory and in the bank, as this will deposit and withdraw them.

(I made a really long post about this, but my computer restarted)..:spot:


EDIT: I don't have MSI on my comp atm..

marpis

2009-10-18 11:12:58

From: NaumanAkhlaQ
Edit: Need to know what else to work on for Banking.scar. Kinda run out of ideas :(


You could add banksearch to withdraw, if the item is not found on the 1st tab :)

Naum

2009-10-18 13:58:17

From: marpis
You could add banksearch to withdraw, if the item is not found on the 1st tab :)


Yeah, I thought of that, but that would completely muck up where the actual position in the bank is. Don't worry, ill add scrolling compatibility to it. And also make one inter-depend on the other. This is just a final mock-up :).

Thanks for the reply marpis :). Rep++

Coh3n

2009-10-18 16:49:15

Dude, when I tested this I couldn't believe how well it worked. Flawless! Well, with Cadava berries that is. :p But I'm sure with the right DTM/BMP it would work just the same for other items.

I think adding scrolling is a good idea. However, I don't think it should be priority right now as this is just a F2P scripts to start with (I think) and therefore, almost every item will be visible on the first screen anyway. But I do think this should be added in the future. :)