Who wants Clickable/Unlockable doors ?

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
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Who wants Clickable/Unlockable doors ?

Post by Doridion »

After many, and many and many tests and hair less, I got it !! LoG 1 dreams are reallity with LoG2. Doors will be henceforth clickables !!!

1 - Clickable door

I give you the definition trick ;)

For original LoG2 models doors :

Code: Select all

defineObject{
	name = "my_clickable_door",
        baseObject = "[color=#40FFBF][name of the door you want to use][/color]",
	components = {
		{
			class = "Door",
         sparse = true,
			killPillars = true,
		},
		{
			class = "Clickable",
			maxDistance = 1,
         -- offset vector is the point where begin the clickable box
			offset = vec(0,1.3,0),
         -- size is the size of our clickable box
			size = vec(2.5,2.5,0.3),
			onClick = function(self)
				self.go.door:toggle()
			end
		},
		{
			class = "Controller",
			onOpen = function(self, name)
				self.go.door:open()
			end,
			onClose = function(self)
				self.go.door:close()
			end,
			onToggle = function(self)
				self.go.door:toggle()
			end,
		},
	},
	placement = "wall",
	editorIcon = 124,
}
For custom models doors :
SpoilerShow

Code: Select all

defineObject{
	name = "my_clickable_door",
	components = {
    {
      class = "Model",
      model = "mod_assets/models/env/my_door_model.fbx",
	},
    {
      class = "Model",
	  name = "frame",
      model = "mod_assets/models/env/my_frame_model.fbx",
	},
	{
		class = "Door",
		sparse = true,
		killPillars = true,
    },
		{
			class = "Clickable",
			maxDistance = 1,
         -- offset vector is the point where begin the clickable box
			offset = vec(0,1.3,0),
         -- size is the size of our clickable box
			size = vec(2.5,2.5,0.3),
			onClick = function(self)
				self.go.door:toggle()
			end
		},
		{
			class = "Controller",
			onOpen = function(self, name)
				self.go.door:open()
			end,
			onClose = function(self)
				self.go.door:close()
			end,
			onToggle = function(self)
				self.go.door:toggle()
			end,
		},
	},
	placement = "wall",
	editorIcon = 124,
}
Don't forget, if the door model is custom or special, to add debugDraw = true property to you clickable class, to see the clickable box and changing the offset and size vector to adapt to your model.

2 - Unlocking clickable door without lock item or attached script
SpoilerShow

Code: Select all

defineObject{
	name = "my_clickable_door",
   baseObject = "[color=#40FFBF][name of the door you want to use][/color]",
	components = {
	{
		class = "Door",
		sparse = true,
		killPillars = true,
    },
	{
		class = "Clickable",
		maxDistance = 1,
		offset = vec(0,1.3,0),
		size = vec(2.5,2.5,0.3),
		onClick = function(self)
			local used_item = getMouseItem()
			if self.go.lock:getOpenedBy() == ("" or nil) then
				self.go.door:toggle()
			else
				if used_item == nil then
					hudPrint("Door is locked ")
				elseif used_item.go.item:hasTrait("key") then
					if self.go.lock:getOpenedBy() == used_item.go.name then
						self.go.door:open()
						self.go.lock:setOpenedBy("")
						setMouseItem(nil)
						hudPrint("Door is unlocked")
					else
						hudPrint("Not the right key")
					end
				else
					hudPrint("You must open the door with a key")
				end
			end
		end
	},
	{
		class = "Controller",
		onOpen = function(self, name)
			self.go.door:open()
		end,
		onClose = function(self)
			self.go.door:close()
		end,
		onToggle = function(self)
			self.go.door:toggle()
		end,
	},
	{
		class = "Lock",
	},
  },
  placement = "wall",
  editorIcon = 128,
}
I explain how it simply works :
1 - In the editor, just put the door on your map, locking her directly in the door's components like the lock items, place the key somewhere in your map.
2 - Test your party, go taking the key, go in front off the locked door, click on the key, click on the door and ... it's open ;)

And that's it ! Go modding pretty doors now :mrgreen:
Last edited by Doridion on Sun Nov 09, 2014 1:06 am, edited 15 times in total.
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Who want's CLICKABLE doors ?

Post by NutJob »

Nice work, and I'll be sure to check it out later tonight and may use it a few times when a door is not part of some stupid puzzle of mine. ~cheers~
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Who want's CLICKABLE doors ?

Post by Doridion »

Clickable function can easely deactivable ;)
Grimfan
Posts: 369
Joined: Wed Jan 02, 2013 7:48 am

Re: Who want's CLICKABLE doors ?

Post by Grimfan »

Actually if this were combined with Skuggs swinging doors from his town tileset you would probably have the most sought-after custom object in LOG 1 or 2 history.
User avatar
MadCatter
Posts: 34
Joined: Mon Nov 03, 2014 5:02 am
Location: Southampton, UK

Re: Who want's CLICKABLE doors ?

Post by MadCatter »

This looks perfect for use with the house doors i'm planning. Previously i just had them open when you stand next to them, but this is a much better solution. Thanks :D
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Who want's CLICKABLE doors ?

Post by Doridion »

Grimfan wrote:Actually if this were combined with Skuggs swinging doors from his town tileset you would probably have the most sought-after custom object in LOG 1 or 2 history.
Thanks Grimfan, really glad of this compliment ^^ Since i dreamt of these clickable doors :D
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Who want's CLICKABLE doors ?

Post by Lark »

Hey, this is really cool! You're amazing! Did I miss the model files somewhere? I just got my first model working, sort of. It took me two days when you could have done it in 2 minutes, but I'm learning! Thanks Doridion!
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Who want's CLICKABLE doors ?

Post by NutJob »

The problem I do have with clickable doors (not your creation, your code, or you) is continuity, being doors can have a plethora of ways to interact with. It would be kind of funny, though, a player not being able to progress, solely due, to not knowing the door was clickable (after opening several other doors with keys, pull chains, puzzle completion, monster onDie event, etc).

"Help I can't get past the room with two torches by the door!"

"Oh!, just click it."

=)
User avatar
Lark
Posts: 178
Joined: Wed Sep 19, 2012 4:23 pm
Location: Springfield, MO USA

Re: Who want's CLICKABLE doors ?

Post by Lark »

You just have to train the users. Hints, clues, hang a sign that says "click me". :) A door you could just run into that opened would be cool too! Too much to learn and do. -Lark
NutJob
Posts: 426
Joined: Sun Oct 19, 2014 6:35 pm

Re: Who want's CLICKABLE doors ?

Post by NutJob »

Lark wrote:You just have to train the users. Hints, clues, hang a sign that says "click me". :) A door you could just run into that opened would be cool too! Too much to learn and do. -Lark
Not very immersive though if in-game content has to tell the "player" what the character can do... then again this is more puzzle game then anything, so yeah.

Pull my finger to find out what's under my chair.

Edit: missing critical words =)
Last edited by NutJob on Sat Nov 08, 2014 5:20 am, edited 1 time in total.
Post Reply