multiple specific items on an altar

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
Kasarul
Posts: 9
Joined: Tue Oct 09, 2012 1:54 am

multiple specific items on an altar

Post 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!
3socks
Posts: 11
Joined: Sun Nov 04, 2012 11:29 pm

Re: multiple specific items on an altar

Post 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).
Kasarul
Posts: 9
Joined: Tue Oct 09, 2012 1:54 am

Re: multiple specific items on an altar

Post by Kasarul »

This crashes it: i returns a nil value

if i.name == offeringlist[j]
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: multiple specific items on an altar

Post 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.
Kasarul
Posts: 9
Joined: Tue Oct 09, 2012 1:54 am

Re: multiple specific items on an altar

Post 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!
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: multiple specific items on an altar

Post 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"
Kasarul
Posts: 9
Joined: Tue Oct 09, 2012 1:54 am

Re: multiple specific items on an altar

Post by Kasarul »

Works like a charm.

Thank you very much! :D
3socks
Posts: 11
Joined: Sun Nov 04, 2012 11:29 pm

Re: multiple specific items on an altar

Post 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]
Post Reply