Item counter for rooms

Have a question about which MUD client works best with SI? Looking for a free app that lets you log in from your phone? Need help with a complicated script? This is the place.
Post Reply
Visyn
Conclave Representative
Posts: 115
Joined: Sun Dec 01, 2013 4:25 pm
Location: Illinois

Item counter for rooms

Post by Visyn »

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>
galaban
Citizen of Archai
Posts: 25
Joined: Thu Apr 07, 2016 8:05 am

Re: Item counter for rooms

Post by galaban »

There's a room item limit? I need to learn more about that. This will be very useful then, thanks.
Post Reply