• 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!

TFS 1.X+ doors how to push or teleport player to the south?

Felipe93

Ghost Member
Joined
Mar 21, 2015
Messages
1,990
Solutions
9
Reaction score
334
Location
Chile
Hello im trying that player be pushed to the south by closing a opened door }

what i've made is to separate certain doors and create a new table inside doors.lua
this pushes the player diagonally
Lua:
     elseif table.contains(horizontalDoors, itemId) then
       local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature then
            toPosition.x = toPosition.x + 1
                toPosition.y = toPosition.y - 1
            --doRelocate(item:getPosition(), item:getPosition():moveRel(1, 0, 0))
            --doRelocate(item:getPosition(), item:getPosition():moveRel(1, 0, 0))
           -- toPosition.x = toPosition.x + 2
            --toPosition.x = toPosition.x - 1
            doorCreature:teleportTo(toPosition, true)
        end

and this pushes player tto the east
Lua:
     elseif table.contains(horizontalDoors, itemId) then
       local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature then
            toPosition.x = toPosition.x + 1
            doorCreature:teleportTo(toPosition, true)
        end

i want players to be pushed to the south, can somebody point me out how to?
Post automatically merged:

solved
toPosition.y = toPosition.y + 1
Post automatically merged:

can't get the script to work please help
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(openVerticalDoors, itemId) then
       local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature then
            toPosition.y = toPosition.y + 1
            doorCreature:teleportTo(toPosition, true)
            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) or table.contains(closedVerticalDoors, itemId) then
        item:transform(itemId + 1)
        return true
    end
    return false
end

local doorTables = {keys, openDoors, closedDoors, lockedDoors, openExtraDoors, closedExtraDoors, openHouseDoors, closedHouseDoors, closedQuestDoors, closedLevelDoors, openVerticalDoors, closedVerticalDoors}
for _, doors in pairs(doorTables) do
    for _, doorId in pairs(doors) do
        door:id(doorId)
    end
end
end
door:register()
need to add an exception for certain doors to push players to the south
Code:
toPosition.y = toPosition.y + 1
Post automatically merged:

tried this no lucky
Code:
local door = Action()
local doorId = 1214

function door.onUse(player, item, fromPosition, target, toPosition, isHotkey)
Lua:
    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)
            return true
            elseif item.itemid == doorId then
            toPosition.y = toPosition.y + 1
            doorCreature:teleportTo(toPosition, true)
        end
 
Last edited:
Lua:
local openOddDoors = {
    [12695] = { locked = 13237, closed = 12692 },
    [12703] = { locked = 13236, closed = 12701 },
    [14635] = { locked = 14634, closed = 14633 },
    [17435] = { locked = 14641, closed = 14640 },
    [26533] = { locked = 26530, closed = 26529 },
    [26534] = { locked = 26532, closed = 26531 },
    [31176] = { locked = 31175, closed = 27559 },
    [31024] = { locked = 31021, closed = 31020 },
    [31025] = { locked = 31023, closed = 31022 },
    [31541] = { locked = 31314, closed = 31314 },
    [31542] = { locked = 31315, closed = 31315 },
    [32691] = { locked = 32705, closed = 32689 },
    [32692] = { locked = 32706, closed = 32690 },
    [32695] = { locked = 32707, closed = 32693 },
    [32696] = { locked = 32708, closed = 32694 },
    [33432] = { locked = 33429, closed = 33428 },
    [33433] = { locked = 33431, closed = 33430 },
    [33493] = { locked = 33490, closed = 33489 },
    [33494] = { locked = 33492, closed = 33491 },
    [34152] = { locked = 34150, closed = 34150 },
    [34153] = { locked = 34151, closed = 34151 },
    [36292] = { locked = 36289, closed = 36288 },
    [36293] = { locked = 36291, closed = 36290 },
    [37596] = { locked = 37593, closed = 37592 },
    [37597] = { locked = 37595, closed = 37594 }, 
    [39119] = { locked = 39116, closed = 39115 },
    [39120] = { locked = 39118, closed = 39117 }
}
local closedOddDoors = { 
    [12692] = { locked = 13237, open = 12695 },
    [12701] = { locked = 13236, open = 12703 },
    [14633] = { locked = 14634, open = 14635 },
    [14640] = { locked = 14641, open = 17435 },
    [26529] = { locked = 26530, open = 26533 },
    [26531] = { locked = 26532, open = 26534 },
    [27559] = { locked = 31175, open = 31176 },
    [31020] = { locked = 31021, open = 31024 },
    [31022] = { locked = 31023, open = 31025 },
    [31314] = { locked = 31314, open = 31541 },
    [31315] = { locked = 31315, open = 31542 },
    [32689] = { locked = 32705, open = 32691 },
    [32690] = { locked = 32706, open = 32692 },
    [32693] = { locked = 32707, open = 32695 },
    [32694] = { locked = 32708, open = 32696 },
    [33428] = { locked = 33429, open = 33432 },
    [33430] = { locked = 33431, open = 33433 },
    [33489] = { locked = 33490, open = 33493 },
    [33491] = { locked = 33492, open = 33494 },
    [34150] = { locked = 34150, open = 34152 },
    [34151] = { locked = 34151, open = 34153 },
    [36288] = { locked = 36289, open = 36292 },
    [36290] = { locked = 36291, open = 36293 },
    [37592] = { locked = 37593, open = 37596 },
    [37594] = { locked = 37595, open = 37597 },
    [39115] = { locked = 39116, open = 39119 },
    [39117] = { locked = 39118, open = 39120 }
}
local lockedOddDoors = {
    [13237] = { closed = 12692, open = 12695 },
    [13236] = { closed = 12701, open = 12703 },
    [14634] = { closed = 14633, open = 14635 },
    [14641] = { closed = 14640, open = 17435 },
    [26530] = { closed = 26529, open = 26533 },
    [26532] = { closed = 26531, open = 26534 },
    [31175] = { closed = 27559, open = 31176 },
    [31021] = { closed = 31020, open = 31024 },
    [31023] = { closed = 31022, open = 31025 },
    [32705] = { closed = 32689, open = 32691 },
    [32706] = { closed = 32690, open = 32692 },
    [32707] = { closed = 32693, open = 32695 },
    [32708] = { closed = 32694, open = 32696 },
    [33429] = { closed = 33428, open = 33432 },
    [33431] = { closed = 33430, open = 33433 },
    [33490] = { closed = 33489, open = 33493 },
    [33492] = { closed = 33491, open = 33494 },
    [36289] = { closed = 36288, open = 36292 },
    [36291] = { closed = 36290, open = 36293 },
    [37593] = { closed = 37592, open = 37596 },
    [37595] = { closed = 37594, open = 37597 },
    [39116] = { closed = 39115, open = 39119 },
    [39118] = { closed = 39117, open = 39120 }
}

local verticalDoors = {1211, 1220, 1224, 1228, 1233, 1238, 1242, 1246, 1251, 1256, 1260, 1540, 3546, 3548, 3550, 3552, 4915, 5083, 5109, 5111, 5113, 5115, 5127, 5129, 5131, 5133, 5142, 5145, 5283, 5285, 5289, 5293, 5516, 5737, 5749, 6194, 6199, 6203, 6207, 6251, 6256, 6260, 6264, 6798, 6802, 6902, 6904, 6906, 6908, 7044, 7046, 7048, 7050, 7055, 8543, 8548, 8552, 8556, 9167, 9172, 9269, 9274, 9274, 9269, 9278, 9282, 10270, 10275, 10279, 10283, 10479, 10481, 10485, 10483, 10786, 12101, 12199, 19851, 19853, 19991, 19993, 20284, 20286, 17238, 13021, 10790, 12103, 12205, 19855, 19995, 20288, 10792, 12105, 12203, 19857, 19997, 20290}
local horizontalDoors = {1214, 1222, 1226, 1230, 1236, 1240, 1244, 1248, 1254, 1258, 1262, 1542, 3537, 3539, 3541, 3543, 4918, 5085, 5100, 5102, 5104, 5106, 5118, 5120, 5122, 5124, 5136, 5139, 5280, 5287, 5291, 5295, 5518, 5734, 5746, 6197, 6201, 6205, 6209, 6254, 6258, 6262, 6266, 6796, 6800, 6893, 6895, 6897, 6899, 7035, 7037, 7039, 7041, 7057, 8546, 8550, 8554, 8558, 9170, 9174, 9272, 9276, 9280, 9284, 10273, 10277, 10281, 10285, 10470, 10472, 10476, 10474, 10777, 12094, 12190, 19842, 19844, 19982, 19984, 20275, 20277, 17236, 18209, 13023, 10781, 12096, 12196, 19846, 19986, 20279, 10783, 12098, 12194, 19848, 19988, 20281}

local positionOffsets = {
    vertical = {
        {x = 1, y = 0}, -- east
        {x = -1, y = 0}, -- west
    },
    horizontal = {
        {x = 0, y = 1}, -- south
        {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, doorId)
    local pos = creature:getPosition()
    local offsets = verticalDoors[doorId] and positionOffsets.vertical or positionOffsets.horizontal
    for _, offset in ipairs(offsets) 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, doorId)
    end
end

local door = Action()

function door.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local transformTo = 0
    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
        if lockedOddDoors[target.itemid] then
            transformTo = lockedOddDoors[target.itemid].open
        else
            transformTo = target.itemid + 2
        end
        if table.contains(openDoors, target.itemid) then
            if openOddDoors[target.itemid] then
                transformTo = openOddDoors[target.itemid].locked
            else
                transformTo = target.itemid - 2
            end
        elseif table.contains(closedDoors, target.itemid) then
            if closedOddDoors[target.itemid] then
                transformTo = closedOddDoors[target.itemid].locked
            else
                transformTo = target.itemid - 1
            end
        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, itemId)
                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
        if openOddDoors[itemId] then
            transformTo = openOddDoors[itemId].closed
        else
            transformTo = itemId - 1
        end
        item:transform(transformTo)
        return true
    elseif table.contains(closedDoors, itemId) or table.contains(closedExtraDoors, itemId) or table.contains(closedHouseDoors, itemId) then
        if closedOddDoors[itemId] then
            transformTo = closedOddDoors[itemId].open
        else
            transformTo = itemId + 1
        end
        item:transform(transformTo)
        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()

how to remove checkoffset so players will be pushed to east no matter what with vertical doors and pushed to south with horizontal door


solved removed offseftposition check and added this also a new table containing horizontaldoors inside doors.lua
Lua:
 elseif table.contains(horizontalDoors, itemId) then
        local horizontalDoors = Tile(toPosition):getTopCreature()
        if horizontalDoors then
            toPosition.y = toPosition.y + 1
            horizontalDoors:teleportTo(toPosition, true)
            end
 
Last edited:
Back
Top