Results 1 to 6 of 6

Thread: CountItems help

  1. #1
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default CountItems help

    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.

    Simba Code:
    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.

  2. #2
    Join Date
    Feb 2012
    Location
    Wonderland
    Posts
    1,988
    Mentioned
    41 Post(s)
    Quoted
    272 Post(s)

    Default

    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;

    Simba Code:
    program new;
    {$i srl/srl.simba}

    var
      itemDTM1: integer;

    procedure SetupGlobals;
    begin
      itemDTM1 := DTMFromString('mbQAAAHicY2VgYLBjYmBwAWJLILYGYk8gFmZkYOADYkkg5gViESCuq6xgiAwLZYiJiGAIDwlmyEhJYeAH6kfHjFgwGAAA5wkHrA==');
    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

  3. #3
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by Le Jingle View Post
    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;

    Simba Code:
    program new;
    {$i srl/srl.simba}

    var
      itemDTM1: integer;

    procedure SetupGlobals;
    begin
      itemDTM1 := DTMFromString('mbQAAAHicY2VgYLBjYmBwAWJLILYGYk8gFmZkYOADYkkg5gViESCuq6xgiAwLZYiJiGAIDwlmyEhJYeAH6kfHjFgwGAAA5wkHrA==');
    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?

  4. #4
    Join Date
    Jan 2012
    Posts
    2,568
    Mentioned
    35 Post(s)
    Quoted
    356 Post(s)

    Default

    Quote Originally Posted by sickle View Post
    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?

  5. #5
    Join Date
    Mar 2012
    Posts
    182
    Mentioned
    0 Post(s)
    Quoted
    1 Post(s)

    Default

    Quote Originally Posted by riwu View Post
    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!

  6. #6
    Join Date
    Nov 2011
    Posts
    1,268
    Mentioned
    17 Post(s)
    Quoted
    217 Post(s)

    Default

    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

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •