Page 1 of 1
Need help with alcove puzzle
Posted: Tue Nov 27, 2012 4:38 pm
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!
Re: Need help with alcove puzzle
Posted: Tue Nov 27, 2012 6:05 pm
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).
Re: Need help with alcove puzzle
Posted: Tue Nov 27, 2012 6:07 pm
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...)
Re: Need help with alcove puzzle
Posted: Tue Nov 27, 2012 6:07 pm
by crisman
You can do it with a code like this, without the counter.
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

But if you have trouble let me know!
Re: Need help with alcove puzzle
Posted: Tue Nov 27, 2012 6:35 pm
by Komag
scripting gods to the rescue!

Re: Need help with alcove puzzle
Posted: Tue Nov 27, 2012 10:00 pm
by smalhavoc
Thanks everyone!