SRL Archive - SRL Archives

Withdraw functions bugged? :(


Nava2

2008-09-02 17:38:33

Here are the withdraw functions I'm using. They are MODIFIED SRL, but they are better, IMO. They are the same where the error is happening.

Read the following code, then look at what I get in my debug box.

{*******************************************************************************
procedure Withdraw(Col, Row, Amount: Integer);
by: Starblaster100, Town, Wizzup? and Nava2
Description: Withdraws Amount at Column/Row.
*******************************************************************************}

function WithdrawMod(col, row, Amount: Integer): boolean;

Var
ResInt, I : Integer;
BBox: TBox;

begin
FixBank;
//FixBankTab;
Result := false;
ResInt := InvCount;
BBox := BankIndexToMSBox(BankPointToBankIndex(Point(Col, Row)));
Writeln('Index: ' + IntToStr(BankPointToBankIndex(Point(Col, Row))));
case Amount of
0: begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);
ChooseOption('Withdraw-All');
end;
1: begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 1);
Wait(RandomRange(50, 150));
end;
else
begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);
if not ChooseOption('Withdraw-' +IntToStr(Amount)) then
begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);
if (ChooseOption('Withdraw-X')) then
begin
Wait(RandomRange(700, 1200));
TypeSend(IntToStr(Amount));
end;
end;
end;
end;
while ResInt =< InvCount do
begin
if I > 200 then break;
Wait(RandomRange(100, 150));
Inc(i);
Status('Waiting for RS to withdraw items.');
end;
Result := ResInt < InvCount;
end;


{*******************************************************************************
function WithdrawItem(Ident: integer; IdentType: string; var Index: integer; Amount: integer; UpText: TStringArray; Tol: TIntegerArray): boolean;
By: Nava2
Sections by: WT-Fakawi / Sumilion
Description: Withdraws an item from the bank by using "Ident" with tol[0]
as color tolerance, tol[1] as contour tolerance in case of bmp masks. Valid IdentTypes are :
bmp, mask, color, dtm.
Index: The Bank Index where the item is found, must be a variable. Speeds up future withdraws.
Amount: Amount to withdraw from bank.
UpText: The Uptext which the function checks for.
*******************************************************************************}

function WithdrawItem(Ident: integer; IdentType: string; var Index: integer; Amount: integer; UpText: TStringArray; Tol: TIntegerArray): boolean;

var
x1, y1, coltol, contol : integer;
BPoint : TPoint;
BankBox : TBox;
F, Found : boolean;

label
Start;

begin
{Written by WT-Fakawi / Sumilion, from this line to {end}
case LowerCase(IdentType) of
'bmpmask', 'bitmapmask', 'bmp mask', 'bitmap mask', 'mask':
try
begin
coltol := tol[0];
contol := tol[1];
end;
except
srl_Warn('WithdrawItem', 'Tol was incorrect', warn_AllVersions);
Exit;
end;
'dtm': begin end; //I guess this is a check to make sure its a valid identifier?
'bmp', 'bitmap', 'color':
try
coltol := tol[0];
except
srl_Warn('WithdrawItem', 'Tol was incorrect', warn_AllVersions);
Exit;
end;
else begin
srl_Warn('WithdrawItem', 'Invalid identifier type: ' + IdentType, warn_AllVersions);
Exit;
end;
end;
{End}
if (Index = 0) then
begin
Start:
for Index := 1 to 50 do
begin
BankBox := BankIndexToMSBox(Index);
case LowerCase(IdentType) of
'bmp', 'bitmap': F := FindBitmapSpiralTolerance(Ident, x1, y1, BankBox.x1, BankBox.y1, BankBox.x2, BankBox.y2, coltol);
'bmpmask', 'bitmapmask', 'bmp mask', 'bitmap mask', 'mask': F :=FindBitmapMaskTolerance(Ident, x1, y1, BankBox.x1, BankBox.y1, BankBox.x2, BankBox.y2, coltol, contol);
'color': F := FindColorTolerance(x1, y1, Ident, BankBox.x1, BankBox.y1, BankBox.x2, BankBox.y2, coltol);
'dtm': F := FindDtm(Ident, x1, y1, BankBox.x1, BankBox.y1, BankBox.x2, BankBox.y2);
end;
if F then
begin
MMouse(x1, y1, 4, 4);
Wait(100+random(50));
if IsUpTextMultiCustom(UpText) then
begin
Writeln('Found Item at Bank Slot ' + IntToStr(Index) + '.');
Found := true;
break;
end else
Writeln('Found Incorrect Item, Moving to new Bank Spot.');
end;
end;
end else
begin
BankBox := BankIndexToMSBox(Index);
MouseBox(BankBox.x1, BankBox.y1, BankBox.x2, BankBox.y2, 3);
Wait(100+random(50));
if IsUpTextMultiCustom(UpText) then
Found := true
else
begin
Writeln('Item Moved from Bank Slot ' + IntToStr(Index) + ', checking bank again.');
GoTo Start;
end;
end;
Wait(200+random(150));
if Found then
begin
BPoint := MSTPointToBankPoint(Point(x1, y1));
Writeln('Col: ' + IntToStr(BPoint.x) + ' Row: ' + IntToStr(BPoint.y));
Result := WithdrawMod(BPoint.x, BPoint.y, Amount);
DTMPoint := Point(x1, y1);
end else
begin
Index := 0;
Writeln('Could not Find ' + IdentType + ' in Bank.');
end;
end;

Found Incorrect Item, Moving to new Bank Spot.
Found Incorrect Item, Moving to new Bank Spot.
Found Incorrect Item, Moving to new Bank Spot.
Found Item at Bank Slot 20. <- Index where item ACTUALLY is
Col: 9 Row: 1 <- Bank point where it is.
Index: 9 <- where the withdraw function finds it.

So, I think there is a bug, and the Col - 1, Row - 1 should be removed. :)

That is all. I think its a bug in the new SRL as I haven't come across it pre-rev 24.

Anyways. I also want to put my withdraw function up for denied or accepted.

Either way, let me know if you find a different error.

Cheers.

Narcle

2008-09-03 06:20:33

Well your WithdrawMod won't work that way… I know what your doing cause I did it in my smelter and couple other scripts I have.

This is how I do it, and I'll explain why you have to do it this way and why there is a problem with it as well.
procedure MyWithdraw(col, row, Amount: Integer);

Var
BBox: TBox;

begin
FixBank;
FixBankTab;
BBox := BankIndexToMSBox(BankPointToBankIndex(Point(Col - 1, Row - 1)));
If Amount = 1 Then
Begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 1);
Wait(RandomRange(50, 150));
End
Else
Begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);
if (Amount = 5) or (Amount = 10) then
ChooseOption('Withdraw-' +IntToStr(Amount))
else if Amount = 0 then
ChooseOption('Withdraw-All')
else
if Not ChooseOption('Withdraw-' +IntToStr(Amount)) then //If you fail to click it, it'll try to ChooseOption a box that isn't there (thats what yours does)
begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);//So here I re-mouse the box that was used from before to bring the Choose Option window
if (ChooseOption('Withdraw-X')) then
begin
Wait(1000 + Random(100));
TypeSend(IntToStr(Amount));
end;
end;
End;
end;

As you can see you have to mouse the item that you moused before. Since if ChooseOption fails it moves the mouse away and the Option Box closes.

However there is one flaw in this. For either of us. If you say try to withdraw "9" of an item, and the last remembered item was "999" It will click that, because the text is in it, but it doesn't consider the numbers after it.

I think this could be fixed by added a space in the "Not ChooseOption('Withdraw-' +IntToStr(Amount) + ' ')" However this will only work if the ReadText function in ChooseOption includes spaces after and before a read text that it does. I'll have to look and maybe test it.

@Your other function, I didn't read into in depth but its for using bmps etc. for withdrawing from bank right?

Nava2

2008-09-03 08:16:28

All I was really worried about was the Col - 1, Row - 1, but thanks narcle for the advice. Here is my improved version, with your fix and some of my own.

function WithdrawMod(col, row, Amount: Integer): boolean;

Var
ResInt, I : Integer;
BBox: TBox;

begin
FixBank;
//FixBankTab;
Result := false;
ResInt := InvCount;
BBox := BankIndexToMSBox(BankPointToBankIndex(Point(Col, Row)));
Writeln('Index: ' + IntToStr(BankPointToBankIndex(Point(Col, Row))));
case Amount of
0: begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);
ChooseOption('Withdraw-All');
end;
1: begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 1);
Wait(RandomRange(50, 150));
end;
else
begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);
if not ChooseOption('Withdraw-' +IntToStr(Amount)) then
begin
MouseBox(BBox.X1 + 5, BBox.Y1 + 5, BBox.X2 - 5, BBox.Y2 - 5, 2);
if (ChooseOption('Withdraw-X')) then
begin
Wait(RandomRange(700, 1200));
TypeSend(IntToStr(Amount));
end;
end;
end;
end;
while ResInt =< InvCount do
begin
if I > 200 then break;
Wait(RandomRange(100, 150));
Inc(i);
Status('Waiting for RS to withdraw items.');
end;
Result := ResInt < InvCount;
end;

E: The other function was just trying to show the whole problem. But yeah, it will withdraw an item from the bank with any of the identifiers.