Page 1 of 1

Completing Demon Eye Gem Sockets for Door Unlock

Posted: Sun Jan 06, 2013 11:38 pm
by RareMystery
We're new to Grimrock modding and lua script. With the help of the modding references we have completed some of this puzzle, but can't quite finish it.

We have placed a "daemon_head_eye_slots" object in our room with a "dungeon_door_iron" that we wish to open when a red gem is placed in both sockets of the demon head. We added the following script to the objects.lua file to create the sockets and added the sockets to the demon head in the editor.

_________________________________________________________
-- This file has been generated by Dungeon Editor 1.3.6

-- TODO: place your custom dungeon object definitions here

defineObject{
name = "eye_socket_left_red",
class = "Alcove",
anchorPos = vec(0.21, 1.58, -0.45),
targetPos = vec(0.2, 1.65, -0.45),
targetSize = vec(0.1, 0.1, 0.1),
placement = "wall",
onInsertItem = function(self, item)
return item.name == "red_gem" and

self:getItemCount() == 0
end,
editorIcon = 92,
}

defineObject{
name = "eye_socket_right_red",
class = "Alcove",
anchorPos = vec(-0.21, 1.58, -0.45),
targetPos = vec(-0.2, 1.65, -0.45),
targetSize = vec(0.1, 0.1, 0.1),
placement = "wall",
onInsertItem = function(self, item)
return item.name == "red_gem" and

self:getItemCount() == 0
end,
editorIcon = 92,
}
_________________________________________________________

Now we just need to check that 2 red gems are present to unlock the door, but we're not sure if this code gets added in the objects.lua file or in the editor, and the exact code to use. Anyone able to help with this? Thanks in advance.

Re: Completing Demon Eye Gem Sockets for Door Unlock

Posted: Sun Jan 06, 2013 11:47 pm
by msyblade
Welcome! What u want is a "Counter" , set it to 2 then connect each socket to it to decrement on activate and increment on deactivate :) no coding required! :lol:

Re: Completing Demon Eye Gem Sockets for Door Unlock

Posted: Mon Jan 07, 2013 12:26 am
by Komag
yeah, it's sort of ironic that you did the complex hard part first! The last thing is to just link the counter to open the door on activate (and close on deactivate if you want)

Re: Completing Demon Eye Gem Sockets for Door Unlock

Posted: Mon Jan 07, 2013 1:15 am
by RareMystery
Awesome feedback. Thanks so much for the quick replies! Door is functioning as intended.

Re: Completing Demon Eye Gem Sockets for Door Unlock

Posted: Mon Feb 04, 2013 8:20 pm
by wolfee
Hi guys. Is there a reason why the daemon_head_eye_slots _x would only work with blue gems? I first tried with green gems and could never get it to work, then for kicks I tried blue gems and it worked. Then on a lower level I reused the same setup but with red gems and it failed again. Switched it back to blue gems and it works! Are the gems only supposed to work for certain slots? For example I have a daemon mouth slot that works with a green gem, but green gems don't work for eyes. Thanks for any info.

Re: Completing Demon Eye Gem Sockets for Door Unlock

Posted: Mon Feb 04, 2013 8:36 pm
by Komag
Yes, you'll want to download the asset pack and then you can take a look at the object and item script files yourself to see why. Here is the part about the eye sockets (which are alcoves without models) from the objects.lua file:

Code: Select all

defineObject{
	name = "eye_socket_left",
	class = "Alcove",
	anchorPos = vec(0.21, 1.58, -0.45),
	targetPos = vec(0.2, 1.65, -0.45),
	targetSize = vec(0.1, 0.1, 0.1),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "blue_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
}

defineObject{
	name = "eye_socket_right",
	class = "Alcove",
	anchorPos = vec(-0.21, 1.58, -0.45),
	targetPos = vec(-0.2, 1.65, -0.45),
	targetSize = vec(0.1, 0.1, 0.1),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "blue_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
}
As you can see they both have an "onInsertItem" hook defined. With that hook, if it returns "false" the insertion will not happen. The code in this case is:

Code: Select all

return item.name == "blue_gem" and self:getItemCount() == 0
That means to "return" whether the code after that is true or false. This code has an "and" so both parts have to be true for the whole thing to be true.

Code: Select all

item.name == "blue_gem"
and

Code: Select all

self:getItemCount() == 0
In order for the blue gem part to be true it just has to be the blue gem. That means any other item will return a false
In order for the item count part to be true it has to be 0, in other words, nothing is already in the alcove.

If either situation is false, then the whole thing is false, so it gets a "return false" for the onInsertItem hook, and thus the item does not get inserted.

You can easily set up your own custom alcoves to accept or reject whatever you want. You can use regular alcoves if you want, and only allow special items or only reject a certain weapon or only hold up to three items or whatever you want.

You just write a new object definition in the objects.lua file within your own dungeon directory (Owner/Documents/Almost Human/dungeons/yourdungeon/mod_assets/scripts/), something like this would now take green gems instead of blue ones:

Code: Select all

defineObject{
	name = "eye_socket_left_green",
	class = "Alcove",
	anchorPos = vec(0.21, 1.58, -0.45),
	targetPos = vec(0.2, 1.65, -0.45),
	targetSize = vec(0.1, 0.1, 0.1),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "green_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
}

defineObject{
	name = "eye_socket_right_green",
	class = "Alcove",
	anchorPos = vec(-0.21, 1.58, -0.45),
	targetPos = vec(-0.2, 1.65, -0.45),
	targetSize = vec(0.1, 0.1, 0.1),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "green_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
}
Then be sure to "reload" your dungeon in the editor so it will read the source files again, and voila, you can place the green sockets as you wish. :)

Re: Completing Demon Eye Gem Sockets for Door Unlock

Posted: Tue Feb 05, 2013 10:20 pm
by crisman
Not sure if it can help, but if you want a multi-purpose socket (which accept all the gem of all colors, I use it a lot for my puzzles :D), you may want this code (It's just for the mouth socket, but you can use it also for the eyes).

Code: Select all

cloneObject{
            name = "mouth_socket_multigem",
            baseObject = "mouth_socket",
            onInsertItem = function (self, item)
                         local a, b = string.find (item.name, "_gem")
                         return a ~= nil and b == string.len(item.name) and self:getItemCount() == 0 
                         end,
}