SRL Archive - Help

Quick Question About Inventory Management


skidude6200

2012-03-01 11:39:28

Hey everyone,

I'm in the beginning stages of scripting and need to know a bit about inventory management. I'm currently working on an impling catcher that works within the confines of the Al-Kharid resource dungeon.

Lets say that I wanted to be able to loot the less valuable jars within the dungeon and drop whatever was inside (you can't just release the imp without getting the drop as this results in destroying the jar) to prolong trips. The only way I can think of to make this work is to create 100+ DTMs, one for each possible loot in the lower-level jars. Other than being rather time consuming, would this actually work? Alternatively, is there a way to drop everything in the inventory that doesn't match one of my pre-defined DTMs?

Any help you can give would be great.

masterBB

2012-03-01 11:42:05

From: skidude6200
Hey everyone,

I'm in the beginning stages of scripting and need to know a bit about inventory management. I'm currently working on an impling catcher that works within the confines of the Al-Kharid resource dungeon.

Lets say that I wanted to be able to loot the less valuable jars within the dungeon and drop whatever was inside (you can't just release the imp without getting the drop as this results in destroying the jar) to prolong trips. The only way I can think of to make this work is to create 100+ DTMs, one for each possible loot in the lower-level jars. Other than being rather time consuming, would this actually work? Alternatively, is there a way to drop everything in the inventory that doesn't match one of my pre-defined DTMs?

Any help you can give would be great.


Yes that is possible, you can also do a uptext check of every item in your inventory. But if you want to use DTMs, just loop through your inventory, slot by slot, and if not recognized drop it.

Kyle Undefined

2012-03-01 11:52:13

No need for that many DTMs, just create one for the Jar and loop through the slots, if the jar isn't in that slot and there's an item in there, drop it. Much easier.

skidude6200

2012-03-01 11:53:07

The reason I was thinking of doing individual DTMs is that it would recognize junk without the need for constant inventory cycling. Could I have 100 DTMs set without performance issues? If I used individual functions for each type of jar I'd only need to search for about 10-20 in the same procedure if that makes a difference.

Kyle Undefined

2012-03-01 11:56:21

You would only need to check the inventory after you loot the jar, so it wouldn't be constant, and 100 DTMs is way too many.

skidude6200

2012-03-01 11:58:30

I guess that does make more sense. I know that with uptext cycling the mouse would actually be engaged going slot to slot… If the client was searching for an item that wasn't a jar it could do so without mouse movement correct?

masterBB

2012-03-01 11:59:16

I'm writing an example.

Kyle Undefined

2012-03-01 12:03:23

It would work like so:


procedure ScanInv();
var
i, x, y, DTM : Integer;
invB : TBox;
begin
DTM := DTMFromString('');
for i := 1 to 28 do
begin
invB := InvBox(i);
if(ExistsItem(i))then
begin
if(not(FindDTM(DTM, x, y, invB.X1, invB.Y1, invB.X2, invB.Y2)))then
DropItem(i);
end;
end;
FreeDTM(DTM);
end;

skidude6200

2012-03-01 12:06:23

Awesome, thanks a lot :)

masterBB

2012-03-01 12:06:33

function loadAllTheDTMs:Array of Integer;
begin
setLength(Result,3);
Result[0] := DTMFromString('aegaaeg');
Result[1] := DTMFromString('aegaaeg');
Result[2] := DTMFromString('aegaaeg');
end;

procedure freeAllTheDtms(AllTheDTMs:Array of Integer);
var
i,hi:Integer;
begin
hi := High(AllTheDTMs);
for i := 0 to hi do
FreeDTM(AllTheDTMs[i]);
end;

procedure CheckInv;
var
i,x,y:Integer;
AllTheDTMs:Array of Integer;
begin
loadAllTheDTMs;
for i := 1 to 28 do
begin
invB := InvBox(i);
if(ExistsItem(i))then
begin
if(not(FindDTM(AllTheDTMs[i], x, y, invB.X1, invB.Y1, invB.X2, invB.Y2)))then
DropItem(i);
end;
end;
freeAllTheDtms;
end;

skidude6200

2012-03-01 12:07:33

Hah, master's code answered my next question before I could ask it ;)

Thanks again guys.

Kyle Undefined

2012-03-01 12:09:25

Haha, master, our code is almost the same :p

masterBB

2012-03-01 12:09:52

From: skidude6200
Hah, master's code answered my next question before I could ask it ;)

Thanks again guys.


I can watch in the future :P.

But I posted wrong code, fixed:
program CheckForThoseJars;


function loadAllTheDTMs:Array of Integer;
begin
setLength(Result,3);
Result[0] := DTMFromString('aegaaeg');
Result[1] := DTMFromString('aegaaeg');
Result[2] := DTMFromString('aegaaeg');
end;

procedure freeAllTheDtms(AllTheDTMs:Array of Integer);
var
i,hi:Integer;
begin
hi := High(AllTheDTMs);
for i := 0 to hi do
FreeDTM(AllTheDTMs[i]);
end;

procedure CheckInv;
var
i,j,x,y,hi:Integer;
AllTheDTMs:Array of Integer;
begin
AllTheDTMs := loadAllTheDTMs;
hi := High(AllTheDTMs);
for i := 1 to 28 do
begin
invB := InvBox(i);
if(ExistsItem(i))then
begin
for j := 0 to hi do
if(not(FindDTM(AllTheDTMs[j], x, y, invB.X1, invB.Y1, invB.X2, invB.Y2)))then
DropItem(i);
end;
end;
freeAllTheDtms(AllTheDTMs);
end;

Kyle Undefined

2012-03-01 12:11:13

master, you forgot something ;)


AllTheDTMs := loadAllTheDTMs;
hi := High(AllTheDTMs);

masterBB

2012-03-01 12:11:56

From: Kyle Undefined
master, you forgot something ;)


AllTheDTMs := loadAllTheDTMs;
hi := High(AllTheDTMs);


Let's hope no one sees it :P

I'm sleeping :P

Kyle Undefined

2012-03-01 12:13:19

Haha, one more thing :p


freeAllTheDtms(AllTheDTMs);

masterBB

2012-03-01 12:14:11

From: Kyle Undefined
Haha, one more thing :p


freeAllTheDtms(AllTheDTMs);


I ninja'd you, check the last edit time :P

Kyle Undefined

2012-03-01 12:15:24

Haha, nice. :D