[phpBB Debug] PHP Warning: in file [ROOT]/viewtopic.php on line 2067: Undefined array key "author"
[phpBB Debug] PHP Warning: in file [ROOT]/viewtopic.php on line 2067: Undefined array key "author"
http://www.shatteredisles.com • Item counter for rooms
Page 1 of 1

Item counter for rooms

Posted: Mon Apr 18, 2016 1:26 am
by
This trigger will count the items in the room, including items stored in containers and group them together using the EXAM command. This is helpful for making sure that you don't go over your room item limit.

Code: Select all

<triggers>
  <trigger
   enabled="y"
   group="exam"
   match="(.*?)You notice (.+?)\.$"
   omit_from_output="y"
   regexp="y"
   send_to="14"
   sequence="100"
  >
  <send>-- Display room description and items

ColourNote ("lightgray", "black", "%1\\n\\nIn this room:")

-- Split the items into a table of items and strip the commas and leading space from each

local items = utils.split ("%2", ",")
  for i, v in ipairs (items) do
    items [i] = v:sub (2)
  end -- for

-- Calcualate a count of each item

local counts = {}
  for _, v in ipairs (items) do
    counts [v] = (counts [v] or 0) + 1
  end -- for

-- Display every item with a running count

  for key, value in ipairs (items) do
    print (key, value)
  end -- for

-- Display each item with its quantity

  for k, v in pairs (counts) do
    ColourNote ("lightgray", "black", ("%i %s"):format (v, k))
  end -- for
</send>
  </trigger>
</triggers>

Re: Item counter for rooms

Posted: Mon Apr 18, 2016 6:25 am
by
There's a room item limit? I need to learn more about that. This will be very useful then, thanks.