Bad Boy JH
2011-04-06 08:21:37
when stuff started to mess with withdrawing, i made this, should still work, but modifying to suit standards. Its a month old, it was for the scripting contest.
function R_GetTabStartYPoints: TIntegerArray;
{R_GetTablStartYPoints - Gets the Relative Points of the Text "Tab X"
in the bank screen, helps to determine which tab an item is on}
var
I: Integer;
begin
SetLength(Result, 8);
for I := 2 to 9 do
begin
if R_BankTabExists(I) then
Result[i-2] := GetInterfaceComponentRelativeY(Interface_Bank, I + 64) else
Break;
end;
SetLength(Result, I-3);
end;
function R_WhichTabIsItemOn(ItemID: Integer; SwitchToTab: Boolean): Integer;
{R_WhichTabIsItemOn - Returns the Tab that an the item with ID "ItemID" is on"}
var
I: Integer;
BankItem: TBankItem;
BankPoint: TPoint;
Ys: TIntegerArray;
begin
R_BankTab(1);
if not R_ItemExistsInBank(ItemID, BankItem) then
Exit;
BankPoint := R_GetBankItemRelPoint(BankItem.Slot);
Ys := R_GetTabStartYPoints;
for I := 0 to High(Ys) do
if Ys[I] > BankPoint.y + GetInterfaceComponentRelativeY(INTERFACE_BANK, INTERFACE_BANK_SLOTS) then
Break;
Result := I + 1;
if SwitchToTab then
R_BankTab(Result);
end;
function R_ItemOnCurrentTab(ID: Integer): Boolean;
{R_ItemOnCurrent Tab Returns True if the item with
the specified ID is on the current Tab}
var
BankItem: TBankItem;
begin
if not R_ItemExistsInBank(ID, BankItem) then
Exit;
if R_CurrentBankTab <> 1 then
Result := R_GetBankItemRelPoint(BankItem.Slot) <> Point(0, 0) else
Result := R_GetBankItemRelPoint(BankItem.Slot).y + GetInterfaceComponentRelativeY(INTERFACE_BANK, INTERFACE_BANK_SLOTS) < GetInterfaceComponentRelativeY(Interface_Bank, 68);
end;
function R_WithdrawItemID(ID: Integer; var Tab: Integer; Amount: Integer): Boolean;
{R_WithdrawItemID - Originally My work, but broke when the Free Trade and
Wilderness update occoured, has been fixed to use the above procedures}
var
ItemBox: TBox;
RelPoint: TPoint;
BankItem: TBankItem;
Mark, InvCou, CountTime: Integer;
begin
if not R_ItemExistsInBank(ID, BankItem) then
Exit;
if Tab = 0 then
begin
if R_ItemOnCurrentTab(ID) then
Tab := R_CurrentBankTab else
Tab := R_WhichTabIsItemOn(ID, True);
end else begin
R_BankTab(Tab);
if not R_ItemOnCurrentTab(ID) then
Tab := R_WhichTabIsItemOn(ID, True);
end;
{The rest of this function is from the reflection include, most of this function
was infact my work, but mormonman has fixed it up and made it easier to read}
//this then gets the box of the Item we want to withdraw.
RelPoint := R_GetBankItemRelPoint(BankItem.Slot);
ItemBox.x1 := RelPoint.x + GetInterfaceComponentRelativeX(INTERFACE_BANK, INTERFACE_BANK_SLOTS) + 4;
ItemBox.y1 := RelPoint.y + GetInterfaceComponentRelativeY(INTERFACE_BANK, INTERFACE_BANK_SLOTS) + 4;
ItemBox.x2 := ItemBox.x1 + GetChildComponentWidth(INTERFACE_BANK, INTERFACE_BANK_SLOTS, BankItem.Slot);
ItemBox.y2 := ItemBox.y1 + GetChildComponentHeight(INTERFACE_BANK, INTERFACE_BANK_SLOTS, BankItem.Slot);
if Amount = 1 then
begin
MouseBox(ItemBox.x1, ItemBox.y1, ItemBox.x2, ItemBox.y2, 1);
Result := True;
Exit;
end;
MouseBox(ItemBox.x1, ItemBox.y1, ItemBox.x2, ItemBox.y2, 2);
MarkTime(CountTime);
InvCou := R_CountItem(ID);
if Amount = 0 then
Result := R_ChooseOption('Withdraw-All ' + BankItem.Name) else
if Amount = -1 then
Result := R_ChooseOption('Withdraw-All but one ' + BankItem.Name) else
if OptionExists('Withdraw-' + IntToStr(Amount)) then
Result := R_ChooseOption('Withdraw-' + IntToStr(Amount) + ' ' + BankItem.Name)
else
begin
if R_ChooseOption('Withdraw-X ' + BankItem.Name) then
begin
MarkTime(Mark);
while not ReadyToTypeBank do
begin
Wait(RandomRange(100, 250));
if (TimeFromMark(Mark) > 10000) then
begin
Result := False;
Exit;
end;
end;
Wait(1000 + Random(1000));
TypeSend(IntToStr(Amount));
Result := True;
end;
end;
if not Result then
begin
Exit;
end;
//failsafe
while (R_CountItem(BankItem.ID) = InvCou) do
begin
if (TimeFromMark(CountTime) > 8000) then
begin
Result := False;
Exit;
end;
Wait(500);
end;
end;
function R_WithdrawLogs: Boolean;
//this is an example of how to use it,
//R_ReturnLogID just returned an ID of a log (obviously)
//and Players[CurrentPlayer].Integers[LogTab] is the last tab the logs were on, my code tends to be fairly straight forward and idiot proof...
begin
Result := R_WithdrawItemID(R_ReturnLogID(Players[CurrentPlayer].Integers[WhichLog]), Players[CurrentPlayer].Integers[LogTab], 0);
end;