Page 5 of 5
Re: Who wants Clickable/Unlockable doors ?
Posted: Fri Nov 28, 2014 5:03 pm
by GoldenShadowGS
Code: Select all
party.party:addConnector("onMove", "script_entity_4", "doorcheck")
function doorcheck(self,dir)
local x = party.x
local y = party.y
for i in party.map:entitiesAt(x,y) do
if string.match(i.id, "bumpdoor") then
if i.facing == dir and self.go.facing == dir then
i.door:open()
end
end
end
if self.go.facing == 0 then
for i in party.map:entitiesAt(x,y-1) do
if string.match(i.id, "bumpdoor") then
revfacing = (i.facing + 2) % 4
if revfacing == dir and self.go.facing == dir then
i.door:open()
end
end
end
end
if self.go.facing == 1 then
for i in party.map:entitiesAt(x+1,y) do
if string.match(i.id, "bumpdoor") then
revfacing = (i.facing + 2) % 4
if revfacing == dir and self.go.facing == dir then
i.door:open()
end
end
end
end
if self.go.facing == 2 then
for i in party.map:entitiesAt(x,y+1) do
if string.match(i.id, "bumpdoor") then
revfacing = (i.facing + 2) % 4
if revfacing == dir and self.go.facing == dir then
i.door:open()
end
end
end
end
if self.go.facing == 3 then
for i in party.map:entitiesAt(x-1,y) do
if string.match(i.id, "bumpdoor") then
revfacing = (i.facing + 2) % 4
if revfacing == dir and self.go.facing == dir then
i.door:open()
end
end
end
end
end
Paste this code into a script entity in your dungeon. All of the doors that you want to open on party bumping it , put "bumpdoor" in its name. For example, "dungeon_door_portcullis_1bumpdoor"
There is not a check to make sure it is actually a door, so don't put the text "bumpdoor" into any entity that is not a door or the game will crash.
The first section is easy. it just checks all of the entities that are at the same tile as the party. If one of them has "bumpdoor" it its ID, then if your move direction and your own facing matches the door's facing, then it opens.
The other conditions are for opening doors from the opposite side. They work the same way, but need to find the tile in front of the player and make sure the door is facing reversed from the party.
Re: Who wants Clickable/Unlockable doors ?
Posted: Fri Nov 28, 2014 5:24 pm
by Aisuu
Its working nicely. Many thx. I dont know what to say more
You go to my credit list
Re: Who wants Clickable/Unlockable doors ?
Posted: Sun Nov 30, 2014 3:28 pm
by MadCatter
GoldenShadowGS wrote: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,
}
While this solves the problem of the party's location relative to the door, unfortunately this still doesn't work. It seems the clickable component created does not function through the door model when it is closed, much like a button.
Also, am I misunderstanding the "sparse" property? I am assuming that it differentiates between solid and gate doors, allowing you to place items through the latter.
Would it be possible to dynamically create a second clickable object at the location of the door, but with a rotation of 180 degrees, that on click toggles the door on the same tile?
(I can probably code this myself, just wondering of there is a better way to do it).
Thanks.
Re: Who wants Clickable/Unlockable doors ?
Posted: Sun Nov 30, 2014 5:13 pm
by GoldenShadowGS
I think sparse allows you to click through the door, but it also makes the door permeable to placing objects through it. Let me do a test
edit: Sparse MUST be true for the doors to open from both sides.
Re: Who wants Clickable/Unlockable doors ?
Posted: Sun Nov 30, 2014 6:59 pm
by GoldenShadowGS
Here is a new script version of the clickable door without define object, you can apply this to any door.
Code: Select all
--Makes door clickable
local d = dungeon_door_wooden_1
d:createComponent("Clickable")
d.clickable:setSize(vec(2.5,2.5,0.3))
d.clickable:setOffset(vec(0,1.3,0))
--d.clickable:setDebugDraw(true)
d.clickable:addConnector("onClick", "script_door_click", "clickabledoor")
d.clickable:setMaxDistance(1)
d.door:setSparse(true)
function clickabledoor(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.controller:toggle()
elseif facing == 0 and x1 == x2 and y1-1 == y2 then
self.go.controller:toggle()
elseif facing == 1 and x1+1 == x2 and y1 == y2 then
self.go.controller:toggle()
elseif facing == 2 and x1 == x2 and y1+1 == y2 then
self.go.controller:toggle()
elseif facing == 3 and x1-1 == x2 and y1 == y2 then
self.go.controller:toggle()
end
end
You have to set sparse to true to be able to click the door from both sides. You can not drop an item through the door anyway if it is clickable. However, if you disable the clickable, then you can optionally disable sparse at that time to make it solid while clickable is off.
Re: Who wants Clickable/Unlockable doors ?
Posted: Sun Nov 30, 2014 7:18 pm
by MadCatter
GoldenShadowGS wrote:I think sparse allows you to click through the door, but it also makes the door permeable to placing objects through it. Let me do a test
edit: Sparse MUST be true for the doors to open from both sides.
Thanks so much for your help, this has been bothering me for ages. Turns out it doesn't matter if you can place items through the door or not, as the clickable component takes priority.
Re: Who wants Clickable/Unlockable doors ?
Posted: Tue Dec 02, 2014 11:49 am
by Doridion
Hum .... just for record, you can easely modify the "clickable" surface smaller ... in my assets, I made these to all the door, but if you just modify the clickable size to 1,1,1 ( for example ) centered on the door ... you'll be able to pass some items through the portcullis