SRL Archive - Reflection Development

BankContainsMulti and BankContainsMultiEx


Gu3st...

2009-06-06 11:47:07

It is like BankContains(); but uses a TBankSlotArray instead of TBankSlot.
It may be useful when searching for the next axe the played can use
E.G The script has a function to enable switching of axes/hatchets whenever the woodcutting level allows it.
I had to make this to get my own script to work :P

{*******************************************************************************
function BankContainsMulti(BSA : TBankSlotArray; var Index : Integer) : Boolean;
By: Zyt3x
Description: Searches the bank for all the items containing the parameters placed
inside BSA, returns the first item found at Index number and True.
*******************************************************************************}
function BankContainsMulti(BSA : TBankSlotArray; var Index : Integer) : Boolean;
var
I, H : Integer;
begin
Result := False;
H := High(BSA);
for I := 0 to H do
if BankContains(BSA[i], Index) then
begin
Result := True;
Exit;
end;
end;

{*******************************************************************************
function BankContainsMultiEx(BSA : TBankSlotArray; var Index : TIntegerArray) : Boolean;
By: Zyt3x
Description: Searches the bank for all the items containing the parameters placed
inside BSA, returns the Index numbers and True.
*******************************************************************************}
function BankContainsMultiEx(BSA : TBankSlotArray; var Index : TIntegerArray) : Boolean;
var
I, H : Integer;
begin
Result := False;
SetLength(Index, 1);
H := High(BSA);
for I := 0 to H do
if BankContains(BSA[i], Index[High(Index)]) then
begin
SetLength(Index, High(Index)+2);
Result := True;
end;
SetLength(Index, High(Index));
end;

EDIT: There is also a bug in the current BankContains(); Here is the fix:
function BankContains(BS : TBankSlot; var Index : Integer) : Boolean;

var
Main, ItemObj, TheBytes, I, II : Integer;

begin
Result := False;
if not R_BankScreen then
Exit;

Main := GetInterface(762, 81);

for I := 0 to 495 do
begin
ItemObj := SmartGetFieldArrayObject(Main, InterfaceChildren, I);
for II := 0 to 3 do
begin
case II of
0 : if BS.ID > 0 then
Result := SmartGetFieldInt(ItemObj, BankItemID) = BS.ID;
1 : if BS.Stack > 0 then
Result := SmartGetFieldInt(ItemObj, BankItemStackSize) = BS.Stack;
2 : if BS.Index > 0 then
Result := SmartGetFieldInt(ItemObj, BankItemIndex) = BS.Index;
3 : if BS.Name <> '' then
begin
TheBytes := SmartGetFieldObject(ItemObj, BankItemName);
Result := Pos(LowerCase(BS.Name), LowerCase(StringFromString(TheBytes))) <> 0;
SmartFreeObject(TheBytes);
end;
end;
if Result then
Break;
end;
if Result then
begin
Index := SmartGetFieldInt(ItemObj, BankItemIndex);
SmartFreeObject(ItemObj);
Break;
end;
SmartFreeObject(ItemObj);
end;

SmartFreeObject(Main);
end;

Shuttleu

2009-06-06 12:12:14

what was the bug?

~shut

Gu3st...

2009-06-06 12:19:57

From: Shuttleu
what was the bug?

~shut

The bug was "SetLength(Result, 495);", and Result is a boolean :p

Kasi

2009-06-06 13:41:37

hey is this gonna be added to the reflection includes?

Gu3st...

2009-06-06 14:21:31

From: pur3b100d
hey is this gonna be added to the reflection includes?

Yes, I think so. They are useful and they are working. :)

mormonman

2009-06-06 15:21:51

Committed.