Page 1 of 2

How do I make a door open, by putting items on alcoves.

Posted: Thu Oct 23, 2014 5:47 pm
by Sorez
Specifically, I want a door to open once I put 3 items on each alcove, which are specific to each alcove, then opening a door once all 3 are put in.

Basically like the rock/sword/scroll puzzle in the main game.

EDIT: This is the last thing I need before I can completely test my map, and publish it.

Re: How do I make a door open, by putting items on alcoves.

Posted: Thu Oct 23, 2014 9:34 pm
by Sorez
Bump, I really just need this one last thing if anyone knows how, so I can finally playtest my map and publish it :P

Re: How do I make a door open, by putting items on alcoves.

Posted: Thu Oct 23, 2014 9:40 pm
by NutJob
Mostly the same way as this.

Re: How do I make a door open, by putting items on alcoves.

Posted: Thu Oct 23, 2014 9:42 pm
by Sorez
NutJob wrote:Mostly the same way as this.
I'm not all that good at scripting sadly, so I don't know how I can set it to 3 alcoves to open a single door. hmm

Re: How do I make a door open, by putting items on alcoves.

Posted: Thu Oct 23, 2014 9:48 pm
by NutJob
Someone may get to it first but I may provide some sample script for you later/tomorrow. I have a puzzle that uses something like this as part of the full puzzle progression... I just don't want to side track myself to much, right now.

Re: How do I make a door open, by putting items on alcoves.

Posted: Thu Oct 23, 2014 9:53 pm
by Sorez
Would love it, if it's of any help, the items I need to put on the alcoves are blue_gem, green_gem, red_gem, for each alcove, to open a dungeon_door_iron. The alcoves are also the dungeon alcoves.

Re: How do I make a door open, by putting items on alcoves.

Posted: Fri Oct 24, 2014 12:37 am
by Leki
Here is what you looking for. Add both functions in script entity and link Alcove to second one.

General function (check if surface contains item)

Code: Select all

function surfaceContains(surface, item)
	for _,i in surface:contents() do
		if i.go.name == item then return true end
	end
end
Riddle example (link alcove/alcoves to this and define conditions). Under if you can add as many alcoves you wish:

Code: Select all

function openRiddleDoor()
	if surfaceContains(myFirstAlcove.surface, "rock") and
		surfaceContains(mySecondAlcove.surface, "dagger") then
			myRiddleDoor.door:open()
	else
			myRiddleDoor.door:close()
	end
end
[/color]

Re: How do I make a door open, by putting items on alcoves.

Posted: Fri Oct 24, 2014 1:19 am
by Mysterious
Awesome Leki. So when the Items are put into the Alcove how do you destroy the items? Thxs for the code :)

EDIT: Ok I figured out how to destroy the 2 Items but the items have to have the names. (rock_3 and dagger_1) but if the names are not correct in the ID's of the item it wont work. So the code needs to destroy any rock or dagger no matter the ID. Here is my version:

Code: Select all

function surfaceContains(surface, item)

for _,i in surface:contents() do
if i.go.name == item then return true 
end
	end
		end



function openRiddleDoor()

if surfaceContains(altar_2.surface, "rock") and
surfaceContains(altar_3.surface, "dagger") then
rock_3:destroy()
dagger_1:destroy()
dungeon_iron_gate_1.door:open()
else
dungeon_iron_gate_1.door:close()
end
	end
I cant use just any old rock or dagger they have to be rock_3 and dagger_1 how can this be changed so it does not matter which rock or dagger you use? Thxs :)

Re: How do I make a door open, by putting items on alcoves.

Posted: Fri Oct 24, 2014 1:36 am
by Sorez
Leki wrote:Here is what you looking for. Add both functions in script entity and link Alcove to second one.

General function (check if surface contains item)

Code: Select all

function surfaceContains(surface, item)
	for _,i in surface:contents() do
		if i.go.name == item then return true end
	end
end
Riddle example (link alcove/alcoves to this and define conditions). Under if you can add as many alcoves you wish:

Code: Select all

function openRiddleDoor()
	if surfaceContains(myFirstAlcove.surface, "rock") and
		surfaceContains(mySecondAlcove.surface, "dagger") then
			myRiddleDoor.door:open()
	else
			myRiddleDoor.door:close()
	end
end
[/color]
So the first one can be not connected to anything, just existing as it's own script in the level?

Thanks so much for this though! Will do it and playtest my map soon :D

Re: How do I make a door open, by putting items on alcoves.

Posted: Fri Oct 24, 2014 2:02 am
by Mysterious
Mysterious wrote:Awesome Leki. So when the Items are put into the Alcove how do you destroy the items? Thxs for the code :)

EDIT: Ok I figured out how to destroy the 2 Items but the items have to have the names. (rock_3 and dagger_1) but if the names are not correct in the ID's of the item it wont work. So the code needs to destroy any rock or dagger no matter the ID. Here is my version:

Code: Select all

function surfaceContains(surface, item)

for _,i in surface:contents() do
if i.go.name == item then return true 
end
	end
		end


function openRiddleDoor()

if surfaceContains(altar_2.surface, "rock") and
surfaceContains(altar_3.surface, "dagger") then
rock_3:destroy()
dagger_1:destroy()
dungeon_iron_gate_1.door:open()
else
dungeon_iron_gate_1.door:close()
end
	end
I cant use just any old rock or dagger they have to be rock_3 and dagger_1 how can this be changed so it does not matter which rock or dagger you use? Thxs :)
Ok I am stumped on this any suggestions?