MadCatter wrote:Has anyone figured out how to make the door clickable from both sides? It's a big problem if you close the door from the inside and get locked in. Also, I don't know if this was deliberate, but maxDistance = 1 means the player can activate the door from 1 block away, maxDistance = 0 means they have to be next to it.
You can always do a work around.
Only one facing can be true for any given door(0,1,2,3). So the only two valid tiles that can toggle the door is when the party is standing on the tile the door is placed, or the adjacent one the door is facing.
Code: Select all
defineObject{
name = "my_clickable_door",
baseObject = "dungeon_door_portcullis",
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)
local x1 = self.go.x
local y1 = self.go.y
local x2 = party.x
local y2 = party.y
local facing = self.go.facing
if x1 == x2 and y1 == y2 then
self.go.door:toggle()
elseif facing == 0 and x1 == x2 and y1-1 == y2 then
self.go.door:toggle()
elseif facing == 1 and x1+1 == x2 and y1 == y2 then
self.go.door:toggle()
elseif facing == 2 and x1 == x2 and y1+1 == y2 then
self.go.door:toggle()
elseif facing == 3 and x1-1 == x2 and y1 == y2 then
self.go.door:toggle()
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,
},
},
placement = "wall",
editorIcon = 124,
}