Page 1 of 5

Who wants Clickable/Unlockable doors ?

Posted: Sat Nov 08, 2014 2:16 am
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:

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 2:18 am
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~

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 2:21 am
by Doridion
Clickable function can easely deactivable ;)

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 2:23 am
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.

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 2:24 am
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

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 2:30 am
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

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 4:26 am
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!

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 4:30 am
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."

=)

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 4:55 am
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

Re: Who want's CLICKABLE doors ?

Posted: Sat Nov 08, 2014 5:01 am
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 =)