Need help with alcove puzzle

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
smalhavoc
Posts: 3
Joined: Tue Nov 27, 2012 4:22 pm

Need help with alcove puzzle

Post by smalhavoc »

Have a room with six alcoves, each containing an item. Secret door opens only when each item has been traded for something similar. Example:

Alcove 6 (itemPuzzleAlcove6) contains Cuirass of Valor. When traded for a Plate Cuirass the following script allows a counter to decrement:

function itemPuzzle()
for i in itemPuzzleAlcove6:containedItems() do
if i.name == "plate_cuirass" then
counter_3:decrement()
break
end
end
end

When the counter decrements 6 times, the door opens, thus the player is ideally to trade with the items in each alcove. Unfortunately, all I have to do is remove and replace the Plate Cuirass 5 times and the door will also open. I am very new to scripting so I'm sure there is an obvious solution, but I'm not sure how to make the coutner increment when the Plate Cuirass (and only the Plate Cuirass) is removed. Thanks in advance for any help!
Ancylus
Posts: 50
Joined: Thu Oct 11, 2012 5:54 pm

Re: Need help with alcove puzzle

Post by Ancylus »

I think the simplest way to do this is removing the counter entirely and simply checking for the correct items in all the alcoves whenever an item is added. If you want to check only one alcove each time, you could create a variable for each alcove that tells whether the correct item was there on the previous check, then decrementing the counter only if the item is there when it previously wasn't and incrementing it in the opposite case (and of course updating the variable as needed).
User avatar
Grimwold
Posts: 511
Joined: Thu Sep 13, 2012 11:45 pm
Location: A Dungeon somewhere in the UK

Re: Need help with alcove puzzle

Post by Grimwold »

I set up a similar puzzle in my test dungeon with 4 altars and the 4 pieces of Chitin armour. To script it I made use of the containsItem() function that Petri provided in this alcove thread - viewtopic.php?f=14&t=3083

Mine is a modular version, so you can list any number of alcoves and, in the same order, the same number of items to check for. You will also need a counter set to the number of alcoves you are checking. I called mine alcove_counter

Code: Select all

-- This function returns true if the entity contains a given item.
-- It works for any entity that implements the containedItems() method.
function containsItem(entity, item)
  for i in entity:containedItems() do
    if i.name == item then
      return true
    end
  end
-- if we get here the item was not found
  return false
end


function alcoveItemCheck()
  local item_check = {
    alcoves = {altar_1,altar_2,altar_3,altar_4}, 
    items = {"chitin_boots", "chitin_greaves", "chitin_mail", "chitin_mask"}}
  range = math.min(#item_check["alcoves"],#item_check["items"])
  for i = 1,range do
    if containsItem(item_check["alcoves"][i], item_check["items"][i]) then
      alcove_counter:decrement()
    end
  end
-- if we get to here and the counter is not 0 we reset the counter
  if alcove_counter:getValue() ~= 0 then
    alcove_counter:reset()
  end
end
Set all your alcoves to "activate always" and connect them to this alcoveItemCheck() function with event "any"


EDIT - hmmm. I could actually spawn a counter on-the-fly using the number of items in the alcove/item array.. then there would be no need for the user to manually add a counter to his dungeon... just paste the script, edit it, and add the connectors (or even.. add connectors on the fly...)
Last edited by Grimwold on Tue Nov 27, 2012 6:22 pm, edited 1 time in total.
User avatar
crisman
Posts: 305
Joined: Sat Sep 22, 2012 9:23 pm
Location: Italy

Re: Need help with alcove puzzle

Post by crisman »

You can do it with a code like this, without the counter.
SpoilerShow

Code: Select all

function sacrifice()

if alcove1:getItemCount() ~= 1 or
alcove2:getItemCount() ~= 1 or
alcove3:getItemCount() ~= 1 then
	Door:close()
	return
end

for i in alcove1:containedItems() do
	if i.name ~= "item1" then
		gemDoor:close()
		return
	end
end

for i in alcove2:containedItems() do
	if i.name ~= "item2" then
		gemDoor:close()
		return
	end
end

for i in alcove3:containedItems() do
	if i.name ~= "item3" then
		gemDoor:close()
		return
	end
end

Door:open()

end
this is only for 3 altars, I hope you can handle it for 6 of them! ;)
Shouldn't be too complicated modify it for your needs :D
But if you have trouble let me know!
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Need help with alcove puzzle

Post by Komag »

scripting gods to the rescue! :mrgreen:
Finished Dungeons - complete mods to play
smalhavoc
Posts: 3
Joined: Tue Nov 27, 2012 4:22 pm

Re: Need help with alcove puzzle

Post by smalhavoc »

Thanks everyone!
Post Reply