Page 1 of 1

multiple specific items on an altar

Posted: Sun Nov 04, 2012 11:55 pm
by Kasarul
hello!
I parsed through the check items in an alcove thread and messed around with some of the scripts but i cannot get the outcome i desire.

What i am looking for is an altar that requires 6 specific items be placed upon it to open a door.

I tried this script:

Code: Select all

function altarCheck()
  local offeringlist = { "golden_chalice", "golden_orb", "golden_dragon" }
  if offeringaltar:getItemCount() == 0
  then
    offeringdoor:close()
  else
    for j=1,3 do
      for i in offeringaltar:containedItems() do
        if i.name == offeringlist[j]
        then
          offeringdoor:open()
          return
        end
      end
    end
    offeringdoor:close()
  end
end
but it opens the door when any one of the three items is placed upon it. I need all three items to be placed on the altar in order for the door to open.
I apologize if I'm a bit slow in getting the script to do my bidding but it i just can't it to work!

All help is greatly appreciated. My dungeon is nearly complete, just need a few more tweaks and fixes!

Re: multiple specific items on an altar

Posted: Mon Nov 05, 2012 12:30 am
by 3socks

Code: Select all

function altarContainsItem(item)
   local offeringlist = { "golden_chalice", "golden_orb", "golden_dragon" }
   for j=1,3 do
           if i.name == offeringlist[j]
           then
             return true
           end
   end
   return false
end

function altarCheck()
  if offeringaltar:getItemCount() == 0
  then
    offeringdoor:close()
  else
      for i in offeringaltar:containedItems() do
         if not altarContainsItem(i)
         then
           offeringdoor:close()
           return
         end
      end
      offeringdoor:open()
  end
end
What about this? I haven't tested it though.

You had a mistake there. You call offeringdoor:open() if any item is on altar (that's why it's enough to have there only one).

Re: multiple specific items on an altar

Posted: Mon Nov 05, 2012 12:34 am
by Kasarul
This crashes it: i returns a nil value

if i.name == offeringlist[j]

Re: multiple specific items on an altar

Posted: Mon Nov 05, 2012 12:34 am
by crisman
Try adding a counter in the for loop. The script you wrote indeed check if there is at least one item in the offeringList. Adding a counter you are sure you can open it with 6 of those items.
You may want to try this script, but I haven't tested, so I'm note sure it will work at the first try! I've also tweaked it a little bit! :)

Code: Select all

function altarCheck()
  local offeringlist = { "golden_chalice", "golden_orb", "golden_dragon" }
local n = 0
  if offeringaltar:getItemCount() == 6 then
    for j=1,3 do
      for i in offeringaltar:containedItems() do
        if i.name == offeringlist[j]
        then
         n = n + 1
        end
     end
   end
end
if n == 6 then
          offeringdoor:open()
else
 offeringdoor:close()
end
end
EDIT: I've tested and it works.

Re: multiple specific items on an altar

Posted: Mon Nov 05, 2012 12:49 am
by Kasarul
Would you mind telling me how you set it up?
I'm still not getting it to work!

Boy I feel dumb, lol!

Re: multiple specific items on an altar

Posted: Mon Nov 05, 2012 12:52 am
by crisman
Oh, probably you have to check the "activate always" option of the altar!
Be also sure to connect the altar to the script as action: "any"

Re: multiple specific items on an altar

Posted: Mon Nov 05, 2012 12:57 am
by Kasarul
Works like a charm.

Thank you very much! :D

Re: multiple specific items on an altar

Posted: Mon Nov 05, 2012 11:39 am
by 3socks
Kasarul wrote:This crashes it: i returns a nil value

if i.name == offeringlist[j]
It's a typo, item instead of i should be there.

Code: Select all

if item.name == offeringlist[j]