I feel bad for almost hijacking your topic, so here is a working code (courtesy of Grimwold -- I'd still be swearing with my door were it not for him and all the other helpful people here, so this code basically isn't mine -- credit to the one who deserves it, I am just a messenger here ; D)
Basically, you'll want the game to check the altars every time the party takes something from them or places something on them. There are a few ways to do this, but the simplest is to connect the altars to a script entity which can then check what the item on the altar is (if any). You won't need a counter, because all the altars are checked every time an item is placed on one of them or taken from one of them.
You'll need three altars for this (I named them hammeraltar1 hammeraltar2 and hammeraltar3, you can call them whatever you want, just be sure to change the names from the script as well), a script entity (name doesn't matter, because you can activate the functions by connecting the altars straight to the script entity -- it might be wise to name it something logical, though.)
JUST MAKE SURE YOU HAVE "activate always" TICKED FROM THE ALTARS' PROPERTIES, AND THE EVENT PART SET TO "any", AND ACTION PART SET TO THE FUNCTION I CALLED "contentcheck". (again, you can name it what you want, just be sure to alter the name in the script as well)
Sorry for yelling, but this was the reason I was stuck for a long time. With activate always the altar will trigger the function also when an item is removed from it -- necessary because we want the door to close if a hammer is removed.
You'll also need the secret door you want to open, I named it hammerdoor. Same applies -- name it what you want, but make sure the script has the same name.
Here is the complete code, I will go through it line by line afterwards:
Code: Select all
function hammercheck(altar)
for i in altar:containedItems() do
if i.name == "ogre_hammer" then
return true
end
end
return false
end
function contentcheck()
if hammercheck(hammeraltar1) and hammercheck(hammeraltar2) and hammercheck(hammeraltar3) then
hammerdoor:open()
else
hammerdoor:close()
end
end
function hammercheck(altar)
-- this function will be used to determine what items are on the altar and if our desired item is there, as follows
for i in altar:containedItems() do
-- this just means that the game will go through all the items on the altar
if i.name == "ogre_hammer" then
-- this means that if one of the items is called ogre_hammer, the next will happen
return true
-- this will stop the loop and give true, "positive" result if the ogre_hammer is on the altar - the contentcheck function will use this information
end
end
return false
-- if an ogre_hammer was not on the altar, this will end the function and return a false "negative" result. Again the other function will use this to decide if it opens the door or closes it
end
function contentcheck()
-- this function will "use" the previous function on the altars you have in your map, and if all the altars give a positive result (the hammer is there), it will open the door
if hammercheck(hammeraltar1) and hammercheck(hammeraltar2) and hammercheck(hammeraltar3) then
-- this checks the altars one at a time, if all the altars give the "true" result the next will happen
hammerdoor:open()
-- this happens, the door opens; if it is already open, it will stay open.
else
-- If not, (all the altars didn't have a hammer)
hammerdoor:close()
-- this happens. This way if the party removes a hammer, the door will close immediately; if it is already closed, it will stay closed.
end
end
I hope I explained it clear enough, I tried to do so because I personally had much trouble understanding this script, not because it was unclear, but because certain scripting principles were unclear to me.