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

RevScripts close doors tp on magic walls

Solution

I have added this behaviour in 1.4.2 but magic walls get destroyed, the items on the floor dont, by the c++ source code, check it out

In data\global.lua you need to set where to push the player depending on the open door (unless doors having a facing attribute? i'm new here) I've done 3 doors for you:
Lua:
openDoorsPush={
    [5100]={x = 0, y = 1}, -- push south
    [5109]={x = 1, y = 0}, -- push east
    [6251]={x = 1, y = 0}, -- push east
}
In data\scripts\actions\others\doors.lua code block lines 107-122 set this:
Code:
        local creaturePositionTable = {}
        local doorCreatures = Tile(toPosition):getCreatures()
        if doorCreatures and #doorCreatures > 0 then

            if...
Test
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()
 
  1. TFS 1.5 is development version (as it's latest master version since ~3 years), do you mean real latest masterbranch version or some ~2 years old downgrade based on it?
  2. If you could explain what was the oldTibia behavior (which one is considered old)
    1. Example: Tibiantis - reversed old Tibia project - discussion thread (https://otland.net/threads/tibiantis-reversed-old-tibia-project-discussion-thread.267116/page-37#post-2661804)
  3. So which doors exactly are bugged, do you see any pattern: horizontal or vertical doors maybe?
 
Last edited:
TFS 1.5 is development version (as it's latest master version since ~3 years), do you mean real latest masterbranch version or some ~2 years old downgrade based on it?
old downgrade based on it
If you could explain what was the oldTibia behavior (which one is considered old)
8.6 and older
downgrade doors
push now.gif
0.4 doors
old push.gif
So which doors exactly are bugged, do you see any pattern: horizontal or vertical doors maybe?
i use the doors script and table added to global no edits
Lua:
openDoors = {
    1211, 1214, 1233, 1236, 1251, 1254, 3546, 3537, 4915, 4918, 5100, 5109, 5118, 5127, 5136, 5139, 5142,
    5145, 5280, 5283, 5734, 5737, 6194, 6197, 6251, 6254, 6893, 6902, 7035, 7044, 8543, 8546, 9167, 9170,
    9269, 9272, 10270, 10273, 10470, 10479, 10777, 10786, 12094, 12101, 12190, 12199
}
closedDoors = {
    1210, 1213, 1232, 1235, 1250, 1253, 3536, 3545, 4914, 4917, 5099, 5108, 5117, 5126, 5135, 5138, 5141,
    5144, 5279, 5282, 5733, 5736, 6193, 6196, 6250, 6253, 6892, 6901, 7034, 7043, 8542, 8545, 9166, 9169,
    9268, 9271, 10269, 10272, 10766, 10785, 10469, 10478, 12093, 12100, 12189, 12198
}
lockedDoors = {
    1209, 1212, 1231, 1234, 1249, 1252, 3535, 3544, 4913, 4916, 5098, 5107, 5116, 5125, 5134, 5137, 5140,
    5143, 5278, 5281, 5732, 5735, 6192, 6195, 6249, 6252, 6891, 6900, 7033, 7042, 8541, 8544, 9165, 9168,
    9267, 9270, 10268, 10271, 10468, 10477, 10775, 10784, 12092, 12099, 12188, 12197
}

openExtraDoors = {
    1540, 1542, 6796, 6798, 6800, 6802, 7055, 7057
}
closedExtraDoors = {
    1539, 1541, 6795, 6797, 6799, 6801, 7054, 7056
}

openHouseDoors = {
    1220, 1222, 1238, 1240, 3539, 3548, 5083, 5085, 5102, 5111, 5120, 5129, 5285, 5287, 5516, 5518, 6199,
    6201, 6256, 6258, 6895, 6904, 7037, 7046, 8548, 8550, 9172, 9174, 9274, 9276, 10275, 10277, 10472, 10481
}
closedHouseDoors = {
    1219, 1221, 1237, 1239, 3538, 3547, 5082, 5084, 5101, 5110, 5119, 5128, 5284, 5286, 5515, 5517, 6198,
    6200, 6255, 6257, 6894, 6903, 7036, 7045, 8547, 8549, 9171, 9173, 9273, 9275, 10274, 10276, 10471, 10480
}

--[[ (Not currently used, but probably useful to keep up to date)
openQuestDoors = {
    1224, 1226, 1242, 1244, 1256, 1258, 3543, 3552, 5106, 5115, 5124, 5133, 5289, 5291, 5746, 5749, 6203,
    6205, 6260, 6262, 6899, 6908, 7041, 7050, 8552, 8554, 9176, 9178, 9278, 9280, 10279, 10281, 10476, 10485,
    10783, 10792, 12098, 12105, 12194, 12203
}
]]--
closedQuestDoors = {
    1223, 1225, 1241, 1243, 1255, 1257, 3542, 3551, 5105, 5114, 5123, 5132, 5288, 5290, 5745, 5748, 6202,
    6204, 6259, 6261, 6898, 6907, 7040, 7049, 8551, 8553, 9175, 9177, 9277, 9279, 10278, 10280, 10475, 10484,
    10782, 10791, 12097, 12104, 12193, 12202
}

--[[ (Not currently used, but probably useful to keep up to date)
openLevelDoors = {
    1228, 1230, 1246, 1248, 1260, 1262, 3541, 3550, 5104, 5113, 5122, 5131, 5293, 5295, 6207, 6209, 6264,
    6266, 6897, 6906, 7039, 7048, 8556, 8558, 9180, 9182, 9282, 9284, 10283, 10285, 10474, 10483, 10781,
    10790, 12096, 12103, 12196, 12205
}
]]--
closedLevelDoors = {
    1227, 1229, 1245, 1247, 1259, 1261, 3540, 3549, 5103, 5112, 5121, 5130, 5292, 5294, 6206, 6208, 6263,
    6265, 6896, 6905, 7038, 7047, 8555, 8557, 9179, 9181, 9281, 9283, 10282, 10284, 10473, 10482, 10780,
    10789, 12095, 12102, 12195, 12204
}
 
push now.gif
work like this in tfs 1.5 official too same behavior.
 
old downgrade based on it
The Nekiro TFS 1.5 has been discontinued. I recommend that you follow the latest updates and developments in your source code through the commits. I'm not sure which ones have already been resolved. Here's the link from Sarah that I recommend.
GitHub - MillhioreBT/forgottenserver-downgrade (https://github.com/MillhioreBT/forgottenserver-downgrade)


There's another issue that you need to correct in your source code. Take a look here.
 

I have added this behaviour in 1.4.2 but magic walls get destroyed, the items on the floor dont, by the c++ source code, check it out

In data\global.lua you need to set where to push the player depending on the open door (unless doors having a facing attribute? i'm new here) I've done 3 doors for you:
Lua:
openDoorsPush={
    [5100]={x = 0, y = 1}, -- push south
    [5109]={x = 1, y = 0}, -- push east
    [6251]={x = 1, y = 0}, -- push east
}
In data\scripts\actions\others\doors.lua code block lines 107-122 set this:
Code:
        local creaturePositionTable = {}
        local doorCreatures = Tile(toPosition):getCreatures()
        if doorCreatures and #doorCreatures > 0 then

            if openDoorsPush[itemId] ~= nil then -- push the player oldschool
                local tileToLandOn=Tile(Position(toPosition.x + openDoorsPush[itemId].x, toPosition.y + openDoorsPush[itemId].y, toPosition.z))
                for _, doorCreature in pairs(doorCreatures) do
                    doorCreature:move(tileToLandOn,1)
                end
            else -- use the 1.4.2 behaviour
                for _, doorCreature in pairs(doorCreatures) do
                    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)
                end
            end
        end
 
        item:transform(itemId - 1)
        return true

testtt.png
 
Solution
I have added this behaviour in 1.4.2 but magic walls get destroyed, the items on the floor dont, by the c++ source code, check it out

In data\global.lua you need to set where to push the player depending on the open door (unless doors having a facing attribute? i'm new here) I've done 3 doors for you:
Lua:
openDoorsPush={
    [5100]={x = 0, y = 1}, -- push south
    [5109]={x = 1, y = 0}, -- push east
    [6251]={x = 1, y = 0}, -- push east
}
In data\scripts\actions\others\doors.lua code block lines 107-122 set this:
Code:
        local creaturePositionTable = {}
        local doorCreatures = Tile(toPosition):getCreatures()
        if doorCreatures and #doorCreatures > 0 then

            if openDoorsPush[itemId] ~= nil then -- push the player oldschool
                local tileToLandOn=Tile(Position(toPosition.x + openDoorsPush[itemId].x, toPosition.y + openDoorsPush[itemId].y, toPosition.z))
                for _, doorCreature in pairs(doorCreatures) do
                    doorCreature:move(tileToLandOn,1)
                end
            else -- use the 1.4.2 behaviour
                for _, doorCreature in pairs(doorCreatures) do
                    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)
                end
            end
        end
 
        item:transform(itemId - 1)
        return true

View attachment 82306
thx it worked
 
I have added this behaviour in 1.4.2 but magic walls get destroyed, the items on the floor dont, by the c++ source code, check it out

In data\global.lua you need to set where to push the player depending on the open door (unless doors having a facing attribute? i'm new here) I've done 3 doors for you:
Lua:
openDoorsPush={
    [5100]={x = 0, y = 1}, -- push south
    [5109]={x = 1, y = 0}, -- push east
    [6251]={x = 1, y = 0}, -- push east
}
In data\scripts\actions\others\doors.lua code block lines 107-122 set this:
Code:
        local creaturePositionTable = {}
        local doorCreatures = Tile(toPosition):getCreatures()
        if doorCreatures and #doorCreatures > 0 then

            if openDoorsPush[itemId] ~= nil then -- push the player oldschool
                local tileToLandOn=Tile(Position(toPosition.x + openDoorsPush[itemId].x, toPosition.y + openDoorsPush[itemId].y, toPosition.z))
                for _, doorCreature in pairs(doorCreatures) do
                    doorCreature:move(tileToLandOn,1)
                end
            else -- use the 1.4.2 behaviour
                for _, doorCreature in pairs(doorCreatures) do
                    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)
                end
            end
        end
 
        item:transform(itemId - 1)
        return true

View attachment 82306
tried this but when the door gets closed the players seems to be like teleported to the next sqm instead of being pushed. is there a way to fix this?
 
Back
Top