Log in

View Full Version : CountItems help



sickle
10-15-2012, 01:11 AM
Ok, so this shouldn't be difficult but I am having a trouble. I'm trying to make it count the number of Item1 in the inventory.


CountItem1 := Countitems('dtm',DTMitem1,[]);


I globally declared CountItems1, and DTMitem1 as integers.

But I keep getting 0 as the returned value for the CountItem1.

DTM editor looks perfect in terms of counting the Item1 with DTMitem1.

Le Jingle
10-15-2012, 01:18 AM
Make sure you are declaring the DTMString globally,
Make sure you are not freeing the DTM before finding it,
Make sure you are not setting the DTM after searching the inventory for it,
Here's a working Example for counting raw sharks;


program new;
{$i srl/srl.simba}

var
itemDTM1: integer;

procedure SetupGlobals;
begin
itemDTM1 := DTMFromString('mbQAAAHicY2VgYLBjYmBwAWJLILYGYk8gFm ZkYOADYkkg5gViESCuq6xgiAwLZYiJiGAIDwlmyEhJYeAH6kfH jFgwGAAA5wkHrA==');
end;

procedure FreeGlobals;
begin
FreeDTM(itemDTM1);
end;

function ReturnInvAmount: Integer;
begin
result := CountItems('dtm', itemDTM1, []);
end;

begin
SetupSRL;
SetupGlobals;
AddOnTerminate('FreeGlobals');
Writeln(ReturnInvAmount);
TerminateScript;
end.


Hope this helps,
Lj

sickle
10-16-2012, 02:17 AM
Make sure you are declaring the DTMString globally,
Make sure you are not freeing the DTM before finding it,
Make sure you are not setting the DTM after searching the inventory for it,
Here's a working Example for counting raw sharks;


program new;
{$i srl/srl.simba}

var
itemDTM1: integer;

procedure SetupGlobals;
begin
itemDTM1 := DTMFromString('mbQAAAHicY2VgYLBjYmBwAWJLILYGYk8gFm ZkYOADYkkg5gViESCuq6xgiAwLZYiJiGAIDwlmyEhJYeAH6kfH jFgwGAAA5wkHrA==');
end;

procedure FreeGlobals;
begin
FreeDTM(itemDTM1);
end;

function ReturnInvAmount: Integer;
begin
result := CountItems('dtm', itemDTM1, []);
end;

begin
SetupSRL;
SetupGlobals;
AddOnTerminate('FreeGlobals');
Writeln(ReturnInvAmount);
TerminateScript;
end.


Hope this helps,
Lj

So strange... So I need further help apparently. When I run your thing above, the returned amount is always 0. But when I check my dtm on the dtm editor, they test perfectly fine. What the h am I doing wrong?

riwu
10-16-2012, 02:22 AM
So strange... So I need further help apparently. When I run your thing above, the returned amount is always 0. But when I check my dtm on the dtm editor, they test perfectly fine. What the h am I doing wrong?
I presume you changed the DTM string to your own one?
Also did you regrab the current RS screen to the DTM editor before testing if it still matches?

sickle
10-16-2012, 12:09 PM
I presume you changed the DTM string to your own one?
Also did you regrab the current RS screen to the DTM editor before testing if it still matches?

Problem solved. After all, it was my DTMs that were the culprits. I increased the tolerance a way up (even for the peripheral points touching the black line), and finally it does what it is meant to do. Thanks for the help! :duh:

DemiseScythe
10-16-2012, 12:36 PM
Dumb function to be honest, the way I do it is I find the center cords using a DTM, so the center of the object to be counted is stored in x and y global vars. Then I use something like this:

C := GetMSBankItemAmount(x, y);

Where C is a variable that stores the number of items, that should work for all bank items for as long as they are visible.

If you want an item in your inventory or equipment area, say arrows or feathers aka stackable items, you can count with this:

C := GetAmount(x, y);

and if that is buggy, try making a TBox using the x and y found, so something like this:

TBox := (x-20, y+20, x+20, y-20);

and then using

C := GetAmountBox(TBox);

give that a try and good luck