GMCP - counting how many of an item in a room

Post Reply
iron
Posts: 1
Joined: Fri Feb 20, 2015 11:52 pm

GMCP - counting how many of an item in a room

Post by iron »

How would I count multiple items in a room using GMCP and do something different depending on if there were one or two (or more) of them?

Currently I have:

for _, v in pairs(gmcp.Char.Items.List.items) do
if v.name == "a monolith sigil" then
info("A monolith is here!")
end
end

If I am in a room with two monoliths, it will send the info message twice. What I would ideally like to do, however, is to have one info message if there is only one monolith sigil in the room (saying 'Get another sigil!') and a second info message if there are two or more monolith sigils in the room (saying 'All safe here!')

Any help or guidance is much appreciated.

Thanks!

User avatar
Belgarath
Posts: 232
Joined: Fri Jul 26, 2013 7:19 am
Discord: macjabeth#7149

Re: GMCP - counting how many of an item in a room

Post by Belgarath »

This should do it for ya:
Code: [show] | [select all] lua
local c = 0
for k,v in pairs(gmcp.Char.Items.List.Items) do
  if v.name == "a monolity sigil" then
    c = c + 1
  end
end
if c == 1 then
  info("Get another sigil!")
elseif c == 2 then
  info("All safe here!")
end

Post Reply