• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua help me with door script for tfs 7.72

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,990
Solutions
9
Reaction score
334
Location
Chile
Hey can you make a working script for tfs 1.5?



i have modified my door script so it push players in front of the door even if there is an item in front of it this work good for verticals doors but not for horizontal doors player are being pushed to the east instead of the south so @pink_panther gave me this script but it's not working

Lua:
--local verticalDoors = {

    --[1210] = 1211,

  --  [1213] = 1214,

--}



local horizontalDoors = {

    [1213] = 1214,

   -- [1210] = 1211

}

print("Door onStepOut")

function onStepOut(creature, item, fromPosition, toPosition)

    --local door = verticalDoors[item:getId()]

    --if door then

        --doRelocate(item:getPosition(), item:getPosition():moveRel(1, 0, 0))

        --item:transform(door)

       -- item:decay()

     --   return true

   -- end

   

    local door = horizontalDoors[item:getId()]

    if door then

       -- doRelocate(item:getPosition(), item:getPosition():moveRel(0, 1, 0))

       doRelocate(item:getPosition(), item:getPosition():moveRel(1, 0, 0))

        item:transform(door)

        item:decay()

        return true

    end

end

Code:
    <!-- horizontal doors -->

        <movevent event="StepOut" itemid="1213" script="vertical_horizontal_doors.lua"/>

    <movevent event="StepOut" itemid="1214" script="vertical_horizontal_doors.lua"/>

i converted it to revscript but is not working either

Code:
local verticalHorizontalDoors = MoveEvent()

verticalHorizontalDoors:type("stepout")

local verticalDoors = {

    [1210] = 1211,

}



local horizontalDoors = {

    [1213] = 1214,

}



--function onStepOut(creature, item, fromPosition, toPosition)

function verticalHorizontalDoors.onStepOut(creature, item, position, fromPosition)

    local door = verticalDoors[item:getId()]

    if door then

        doRelocate(item:getPosition(), item:getPosition():moveRel(1, 0, 0))

        item:transform(door)

        item:decay()

        return true

    end

   

    door = horizontalDoors[item:getId()]

    if door then

        doRelocate(item:getPosition(), item:getPosition():moveRel(0, 1, 0))

        item:transform(door)

        item:decay()

        return true

    end

end



verticalHorizontalDoors:register()



could you make a working script to fix this problem please?

this is my doors revscript / actions
Lua:
local door = Action()

function door.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if table.contains(closedQuestDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 or player:getGroup():getAccess() then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(closedLevelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - actionIds.levelDoor or player:getGroup():getAccess() then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Only the worthy may pass.")
        end
        return true
    elseif table.contains(keys, itemId) then
        local tile = Tile(toPosition)
        if not tile then
            return false
        end
        target = tile:getTopVisibleThing()
        if target.actionid == 0 then
            return false
        end
        if table.contains(keys, target.itemid) then
            return false
        end
        if not table.contains(openDoors, target.itemid) and not table.contains(closedDoors, target.itemid) and not table.contains(lockedDoors, target.itemid) then
            return false
        end
        if item.actionid ~= target.actionid then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        local transformTo = target.itemid + 2
        if table.contains(openDoors, target.itemid) then
            transformTo = target.itemid - 2
        elseif table.contains(closedDoors, target.itemid) then
            transformTo = target.itemid - 1
        end
        target:transform(transformTo)
        return true
    elseif table.contains(lockedDoors, itemId) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        return true
    elseif table.contains(openDoors, itemId) or table.contains(openExtraDoors, itemId) or table.contains(openHouseDoors, itemId) then
       local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature then
            toPosition.x = toPosition.x + 1
            doorCreature:teleportTo(toPosition, true)
        end
    
        item:transform(itemId - 1)
        return true
    elseif table.contains(closedDoors, itemId) or table.contains(closedExtraDoors, itemId) or table.contains(closedHouseDoors, itemId) then
        item:transform(itemId + 1)
        return true
    end
    return false
end

local doorTables = {keys, openDoors, closedDoors, lockedDoors, openExtraDoors, closedExtraDoors, openHouseDoors, closedHouseDoors, closedQuestDoors, closedLevelDoors}
for _, doors in pairs(doorTables) do
    for _, doorId in pairs(doors) do
        door:id(doorId)
    end
end
door:register()
 
Last edited:
elseif table.contains(openDoors, itemId) or table.contains(openExtraDoors, itemId) or table.contains(openHouseDoors, itemId) then
local doorCreature = Tile(toPosition):getTopCreature()
if doorCreature then
toPosition.x = toPosition.x + 1
doorCreature:teleportTo(toPosition, true)

--if item.itemid == doorId then
local doorIds = items[itemEx.itemid]
if doorIds then
toPosition.y = toPosition.y + 1
doorCreature:teleportTo(toPosition, true)
end
end
have edited this but it does not work
 
Lua:
local positionOffsets = {
    {x = 1, y = 0}, -- east
    {x = 0, y = 1}, -- south
    {x = -1, y = 0}, -- west
    {x = 0, y = -1}, -- north
}

--[[
When closing a door with a creature in it findPushPosition will find the most appropriate
adjacent position following a prioritization order.
The function returns the position of the first tile that fulfills all the checks in a round.
The function loops trough east -> south -> west -> north on each following line in that order.
In round 1 it checks if there's an unhindered walkable tile without any creature.
In round 2 it checks if there's a tile with a creature.
In round 3 it checks if there's a tile blocked by a movable tile-blocking item.
In round 4 it checks if there's a tile blocked by a magic wall or wild growth.
]]
local function findPushPosition(creature, round)
    local pos = creature:getPosition()
    for _, offset in ipairs(positionOffsets) do
        local offsetPosition = Position(pos.x + offset.x, pos.y + offset.y, pos.z)
        local tile = Tile(offsetPosition)
        if tile then
            local creatureCount = tile:getCreatureCount()
            if round == 1 then
                if tile:queryAdd(creature) == RETURNVALUE_NOERROR and creatureCount == 0 then
                    if not tile:hasFlag(TILESTATE_PROTECTIONZONE) or (tile:hasFlag(TILESTATE_PROTECTIONZONE) and creature:canAccessPz()) then
                        return offsetPosition
                    end
                end
            elseif round == 2 then
                if creatureCount > 0 then
                    if not tile:hasFlag(TILESTATE_PROTECTIONZONE) or (tile:hasFlag(TILESTATE_PROTECTIONZONE) and creature:canAccessPz()) then
                        return offsetPosition
                    end
                end
            elseif round == 3 then
                local topItem = tile:getTopDownItem()
                if topItem then
                    if topItem:getType():isMovable() then
                        return offsetPosition
                    end
                end
            else
                if tile:getItemById(ITEM_MAGICWALL) or tile:getItemById(ITEM_WILDGROWTH) then
                    return offsetPosition
                end
            end
        end
    end
    if round < 4 then
        return findPushPosition(creature, round + 1)
    end
end

local door = Action()

function door.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if table.contains(closedQuestDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(closedLevelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - actionIds.levelDoor then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Only the worthy may pass.")
        end
        return true
    elseif table.contains(keys, itemId) then
        local tile = Tile(toPosition)
        if not tile then
            return false
        end
        target = tile:getTopVisibleThing()
        if target.actionid == 0 then
            return false
        end
        if table.contains(keys, target.itemid) then
            return false
        end
        if not table.contains(openDoors, target.itemid) and not table.contains(closedDoors, target.itemid) and not table.contains(lockedDoors, target.itemid) then
            return false
        end
        if item.actionid ~= target.actionid then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        local transformTo = target.itemid + 2
        if table.contains(openDoors, target.itemid) then
            transformTo = target.itemid - 2
        elseif table.contains(closedDoors, target.itemid) then
            transformTo = target.itemid - 1
        end
        target:transform(transformTo)
        return true
    elseif table.contains(lockedDoors, itemId) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        return true 
    elseif table.contains(openDoors, itemId) or table.contains(openExtraDoors, itemId) or table.contains(openHouseDoors, itemId) then
        local creaturePositionTable = {}
        local doorCreatures = Tile(toPosition):getCreatures()
        if doorCreatures and #doorCreatures > 0 then
            for _, doorCreature in pairs(doorCreatures) do
                local pushPosition = findPushPosition(doorCreature, 1)
                if not pushPosition then
                    player:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
                    return true
                end
                table.insert(creaturePositionTable, {creature = doorCreature, position = pushPosition})
            end
            for _, tableCreature in ipairs(creaturePositionTable) do
                tableCreature.creature:teleportTo(tableCreature.position, true)
            end
        end
  
        item:transform(itemId - 1)
        return true 
    elseif table.contains(closedDoors, itemId) or table.contains(closedExtraDoors, itemId) or table.contains(closedHouseDoors, itemId) then
        item:transform(itemId + 1)
        return true
    end
    return false
end

local doorTables = {keys, openDoors, closedDoors, lockedDoors, openExtraDoors, closedExtraDoors, openHouseDoors, closedHouseDoors, closedQuestDoors, closedLevelDoors}
for _, doors in pairs(doorTables) do
    for _, doorId in pairs(doors) do
        door:id(doorId)
    end
end
door:register()
(replace your doors.lua, no need to touch anything with movements)
ps. im not an author of this script, just found in some data packs that i have on my pc.
 
Lua:
local positionOffsets = {
    {x = 1, y = 0}, -- east
    {x = 0, y = 1}, -- south
    {x = -1, y = 0}, -- west
    {x = 0, y = -1}, -- north
}

--[[
When closing a door with a creature in it findPushPosition will find the most appropriate
adjacent position following a prioritization order.
The function returns the position of the first tile that fulfills all the checks in a round.
The function loops trough east -> south -> west -> north on each following line in that order.
In round 1 it checks if there's an unhindered walkable tile without any creature.
In round 2 it checks if there's a tile with a creature.
In round 3 it checks if there's a tile blocked by a movable tile-blocking item.
In round 4 it checks if there's a tile blocked by a magic wall or wild growth.
]]
local function findPushPosition(creature, round)
    local pos = creature:getPosition()
    for _, offset in ipairs(positionOffsets) do
        local offsetPosition = Position(pos.x + offset.x, pos.y + offset.y, pos.z)
        local tile = Tile(offsetPosition)
        if tile then
            local creatureCount = tile:getCreatureCount()
            if round == 1 then
                if tile:queryAdd(creature) == RETURNVALUE_NOERROR and creatureCount == 0 then
                    if not tile:hasFlag(TILESTATE_PROTECTIONZONE) or (tile:hasFlag(TILESTATE_PROTECTIONZONE) and creature:canAccessPz()) then
                        return offsetPosition
                    end
                end
            elseif round == 2 then
                if creatureCount > 0 then
                    if not tile:hasFlag(TILESTATE_PROTECTIONZONE) or (tile:hasFlag(TILESTATE_PROTECTIONZONE) and creature:canAccessPz()) then
                        return offsetPosition
                    end
                end
            elseif round == 3 then
                local topItem = tile:getTopDownItem()
                if topItem then
                    if topItem:getType():isMovable() then
                        return offsetPosition
                    end
                end
            else
                if tile:getItemById(ITEM_MAGICWALL) or tile:getItemById(ITEM_WILDGROWTH) then
                    return offsetPosition
                end
            end
        end
    end
    if round < 4 then
        return findPushPosition(creature, round + 1)
    end
end

local door = Action()

function door.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if table.contains(closedQuestDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(closedLevelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - actionIds.levelDoor then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Only the worthy may pass.")
        end
        return true
    elseif table.contains(keys, itemId) then
        local tile = Tile(toPosition)
        if not tile then
            return false
        end
        target = tile:getTopVisibleThing()
        if target.actionid == 0 then
            return false
        end
        if table.contains(keys, target.itemid) then
            return false
        end
        if not table.contains(openDoors, target.itemid) and not table.contains(closedDoors, target.itemid) and not table.contains(lockedDoors, target.itemid) then
            return false
        end
        if item.actionid ~= target.actionid then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        local transformTo = target.itemid + 2
        if table.contains(openDoors, target.itemid) then
            transformTo = target.itemid - 2
        elseif table.contains(closedDoors, target.itemid) then
            transformTo = target.itemid - 1
        end
        target:transform(transformTo)
        return true
    elseif table.contains(lockedDoors, itemId) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        return true
    elseif table.contains(openDoors, itemId) or table.contains(openExtraDoors, itemId) or table.contains(openHouseDoors, itemId) then
        local creaturePositionTable = {}
        local doorCreatures = Tile(toPosition):getCreatures()
        if doorCreatures and #doorCreatures > 0 then
            for _, doorCreature in pairs(doorCreatures) do
                local pushPosition = findPushPosition(doorCreature, 1)
                if not pushPosition then
                    player:sendCancelMessage(RETURNVALUE_NOTENOUGHROOM)
                    return true
                end
                table.insert(creaturePositionTable, {creature = doorCreature, position = pushPosition})
            end
            for _, tableCreature in ipairs(creaturePositionTable) do
                tableCreature.creature:teleportTo(tableCreature.position, true)
            end
        end
 
        item:transform(itemId - 1)
        return true
    elseif table.contains(closedDoors, itemId) or table.contains(closedExtraDoors, itemId) or table.contains(closedHouseDoors, itemId) then
        item:transform(itemId + 1)
        return true
    end
    return false
end

local doorTables = {keys, openDoors, closedDoors, lockedDoors, openExtraDoors, closedExtraDoors, openHouseDoors, closedHouseDoors, closedQuestDoors, closedLevelDoors}
for _, doors in pairs(doorTables) do
    for _, doorId in pairs(doors) do
        door:id(doorId)
    end
end
door:register()
(replace your doors.lua, no need to touch anything with movements)
ps. im not an author of this script, just found in some data packs that i have on my pc.
thanks but that is not what i want or looking for because in this case if there is an item or something in front of the door the player will, be pushed back and i want that the player will be pushed in front of the door no matter what if there is a blocking path item or not
Lua:
local door = Action()
local doorIds = {1214}

function door.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if table.contains(closedQuestDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 or player:getGroup():getAccess() then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(closedLevelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - actionIds.levelDoor or player:getGroup():getAccess() then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Only the worthy may pass.")
        end
        return true
    elseif table.contains(keys, itemId) then
        local tile = Tile(toPosition)
        if not tile then
            return false
        end
        target = tile:getTopVisibleThing()
        if target.actionid == 0 then
            return false
        end
        if table.contains(keys, target.itemid) then
            return false
        end
        if not table.contains(openDoors, target.itemid) and not table.contains(closedDoors, target.itemid) and not table.contains(lockedDoors, target.itemid) then
            return false
        end
        if item.actionid ~= target.actionid then
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        local transformTo = target.itemid + 2
        if table.contains(openDoors, target.itemid) then
            transformTo = target.itemid - 2
        elseif table.contains(closedDoors, target.itemid) then
            transformTo = target.itemid - 1
        end
        target:transform(transformTo)
        return true
    elseif table.contains(lockedDoors, itemId) then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        return true
    elseif table.contains(openDoors, itemId) or table.contains(openExtraDoors, itemId) or table.contains(openHouseDoors, itemId) then
       local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature then
            toPosition.x = toPosition.x + 1
            doorCreature:teleportTo(toPosition, true)
        
            --if item.itemid == doorId then
            local doorIds = items[itemEx.itemid]
    if doorIds then
            toPosition.y = toPosition.y + 1
            doorCreature:teleportTo(toPosition, true)
        end
        end
    
        item:transform(itemId - 1)
        return true
    elseif table.contains(closedDoors, itemId) or table.contains(closedExtraDoors, itemId) or table.contains(closedHouseDoors, itemId) then
        item:transform(itemId + 1)
        return true
    end
    return false
end

local doorTables = {keys, openDoors, closedDoors, lockedDoors, openExtraDoors, closedExtraDoors, openHouseDoors, closedHouseDoors, closedQuestDoors, closedLevelDoors}
for _, doors in pairs(doorTables) do
    for _, doorId in pairs(doors) do
        door:id(doorId)
    end
end
door:register()
have this and have tried other ways too but haven't had success yet
 
Back
Top