SRL Archive - Research & Development Lounge

function GetInventory : TStringArray;


Da 0wner

2009-05-25 12:03:43

Gets the inventory of the player :D.
It's pretty noob right now :(. I suck at Reflection, just started learning it :p.

function GetInventory : TStringArray;
var
i, ii, iii, h, hh, Inv : integer;
s : string;
Box : TBox;
IDs : TIntegerArray;
begin
Inv := GetInterface(149, 0);

for i := 0 to 28 do
begin
h := GetArrayLength(IDs) + 1;
SetArrayLength(IDs, h);
IDs[i] := SmartGetFieldArrayInt(Inv, InventoryItemIDs, i);
if IDs[i] = 0 then
Continue;
hh := GetArrayLength(Result) + 1;
SetArrayLength(Result, hh);
if h <> 1 then
begin
for ii := 0 to high(IDs) do
begin
if IDs[h - 1] = IDs[h - 2] then
begin
Result[hh - 1] := Result[hh - 2];
iii := 1;
break;
end;
end;
end;
if iii = 1 then
begin
iii := 0;
Continue;
end;
s := GetPage('http://itemdb-rs.runescape.com/viewitem.ws?obj=' + IntToStr(IDs[i] - 1));
Result[hh - 1] := between('<div class="subsectionHeader">' + chr(10), '</div>', s);
delete(Result[hh - 1], pos(chr(10), Result[hh - 1]), 1);
if Result[hh - 1] = '' then
begin
if i + 1 = 29 then
MMouseItem(28)
else
MMouseItem(i + 1);
Wait(150 + random(150));
Result[hh - 1] := between(' ', ' /', GetUpText);
end;
end;
SmartFreeObject(Inv);
h := high(result) - 1;
Writeln('There are ' + IntToStr(h + 1) + ' items in your inventory.');
for i := 0 to h do
Writeln('Inventory slot ' + IntToStr(i) + ' contains ' + Result[i] + '.');
end;

Returns it in a TStringArray.

It detects duplicate items, i.e you have 28 shrimps it will get the first shrimp and detect all the other ones and set them to shrimp without getting the page (to make it faster).

It also attempts to get the name of items not in the Grand Exchange database (mime gloves, etc.).

That might fail though. I'm sure this can be shortened by a lot but really I am noob at Reflection :p.

Quickmarch

2009-05-25 14:35:35

Maybe make it return a type, such as:


type
TInvItem = record
Name: String;
Amount: Integer;
InvSpot: Integer;
...
end;
TInvItemArray = array of TInvItem;

Da 0wner

2009-05-25 14:40:03

Meh, I have no clue why I made this. I might update it later though XD.

Shuttleu

2009-05-25 14:58:28

isn't there an easier way than to get the id then search it on the rs site?

~shut

Da 0wner

2009-05-25 15:06:22

Maybe, but like I said, I'm not good with Reflection :(.

Nava2

2009-05-27 06:51:02

Check in my Bank Evaluator, there is a php page that RuneScript uses, parse that. Its much much faster. About 1/1000th the chars to parse through. :)

Credits to Harry for that find btw. :)

Da 0wner

2009-05-27 06:54:36

Alright then, I will edit it soon.

I looked at it, and you cannot search by ID, so how can i use this?

Nava2

2009-05-27 16:50:05

My bad. :)