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

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
Sorez
Posts: 73
Joined: Fri Aug 23, 2013 9:26 pm

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

Post 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.
User avatar
Sorez
Posts: 73
Joined: Fri Aug 23, 2013 9:26 pm

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

Post 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
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

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

Post by NutJob »

Mostly the same way as this.
User avatar
Sorez
Posts: 73
Joined: Fri Aug 23, 2013 9:26 pm

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

Post 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
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

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

Post 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.
User avatar
Sorez
Posts: 73
Joined: Fri Aug 23, 2013 9:26 pm

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

Post 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.
User avatar
Leki
Posts: 550
Joined: Wed Sep 12, 2012 3:49 pm

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

Post 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]
I'm the Gate I'm the Key.
Dawn of Lore
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

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

Post 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 :)
User avatar
Sorez
Posts: 73
Joined: Fri Aug 23, 2013 9:26 pm

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

Post 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
User avatar
Mysterious
Posts: 226
Joined: Wed Nov 06, 2013 8:31 am

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

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