SRL Archive - SRL Suggestions

GetInvSlot(s)DTM


Richard

2012-01-11 20:48:52

For inventory.simba. Two basic functions that just return the inventory slot(s) of the given DTM. Could easily be adapted for BMPs. Not exactly complicated, but was making them for a script, though it could be useful to others:

GetInvSlotsDTM:
(*
GetInvSlotsDTM
~~~~~~~~~~~~~

.. code-block:: pascal

function GetInvSlotsDTM(DTM: Integer): TIntegerArray;

Returns the inventory slots of all occurances of the given DTM.
Returns nothing if not found.

.. note::

by Richard

Example:

.. code-block:: pascal

TIA := GetInvSlotsDTM(OreDTM) then
If Length(TIA) > 0
MMouseItem(TIA[1]);

*)
function GetInvSlotsDTM(DTM: Integer): TIntegerArray;
var
i: Integer;
TPA: TPointArray;
begin
If not FindDTMs(DTM, TPA, MIX1, MIY1, MIX2, MIY2) then
Exit;
SetArrayLength(Result, High(TPA) + 1);
For i := 0 to High(TPA) do
Result[i] := CoordsToItem(TPA[i].x, TPA[i].y);
ClearSameIntegers(Result);
end;

GetInvSlotDTM
(*
GetInvSlotDTM
~~~~~~~~~~~~~

.. code-block:: pascal

function GetInvSlotDTM(DTM: Integer): Integer;

Returns the inventory slot of the given DTM.
Returns nothing if not found.

.. note::

by Richard

Example:

.. code-block:: pascal

i := GetInvSlotDTM(OreDTM);
MMouseItem(i);

*)
function GetInvSlotDTM(DTM: Integer): Integer;
var
x,y: Integer;
begin
If not FindDTM(DTM, x, y, MIX1, MIY1, MIX2, MIY2) then
Exit;
Result := CoordsToItem(x, y);
end;

Kyle Undefined

2012-01-11 21:16:09

Nice, but aren't there already functions to return slot numbers for items?

Richard

2012-01-11 21:18:56

From: Kyle Undefined
Nice, but aren't there already functions to return slot numbers for items?


Not that I could find. There were those for returning all the slots with an item in them, but none for returning the slots of specific items.

Kyle Undefined

2012-01-11 21:20:26

Ah ok, maybe that's what I'm thinking of. Nice work regardless :)

Coh3n

2012-01-11 21:44:16


function GetInvSlotsItem(Item: integer; ItemType: string): TIntegerArray;
var
pts: TPointArray;
i: integer;
begin
pts := itemCoordinates('inv', ItemType, Item, []);

if (length(pts) <= 0) then
exit;

setLength(result, length(pts));
for i := 0 to high(pts) do
result[i] := coordsToItem(pts[i].x, pts[i].y);
end;

function GetInvSlotItem(Item: integer; ItemType: string): integer;
var
x, y: integer;
begin
if (findItemEx(x, y, ItemType, Item, intToBox(MIX1, MIY1, MIX2, MIY2), [])) then
result := coordsToItem(x, y);
end;
For all item types, not just DTMs. ;) See documentation for parameters.

Similar functions are used in MSI (slightly modified to be MSI specific), so I think they're definitely useful.

E: Didn't test those, so they may not work. FindItemEx and ItemCoordinates are in amount.simba.

Richard

2012-01-12 02:41:45

I stand corrected :p I'll close the thread for now.