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
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.