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

Adding doors to global and actions (tfs 1.2)

Joined
Sep 11, 2018
Messages
61
Solutions
1
Reaction score
8
Hello! So I have been trying to add the following doors to make them open and close but I have nothing special (not a level door or quest door or something like that).

Za0HbOI.png


This is what I have added
Lua:
doors = {[26529] = 26533, [26530] = 26533, [26531] = 26534, [26532] = 26534}  

verticalOpenDoors = {26534}

horizontalOpenDoors = {26533}

XML:
   <action fromid="26529" toid="26534" script="other/doors.lua" />

XML:
    <item fromid="26529" toid="26532" article="a" name="monument door">
        <attribute key="type" value="door" />
        <attribute key="blockprojectile" value="1" />
        <attribute key="description" value="It is locked." />
    </item>
        <item fromid="26533" toid="26534" name="monument door">
        <attribute key="type" value="door" />
    </item>

So this is what happens when I use door 26529 (vertical closed door) it opens and turns into 26533 (vertical open door) as it should but when I use it again door 26533 (vertical open door) turns into 26532 (horizontal closed door). Then when I use that one it opens as it should but when I use it again it turns into another open door but vertical.

So basically it goes like:
26529 (horizontal closed door) => 26533 (horizontal open door)
26533 (horizontal open door) => 26532 (vertical closed door)
26532 (vertical closed door) = > 26534 (vertical open door)
26534 (vertical open door) = > 26533 (horizontal open door) and then it loops like that.

Does anyone know what im doing wrong? Im pretty sure I have added everything that I have to add or did I miss something?
 
Solution
Remplace your doors.lua
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if table.contains(questDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(levelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else...
Lua:
doors = {[26529] = 26533, [26530] = 26533, [26531] = 26534, [26532] = 26534, [26533] = 26529}
In other words you need to put all of them there, Horizontal and Vertical are to check if there's a creature in there and when close move that creature.
 
Lua:
doors = {[26529] = 26533, [26530] = 26533, [26531] = 26534, [26532] = 26534, [26533] = 26529}
In other words you need to put all of them there, Horizontal and Vertical are to check if there's a creature in there and when close move that creature.
Thanks for the answer! But that doesn't seem to be working. I have checked other doors before I added mine and for example door 1209 (closed), 1210 (closed) and 1211 (open) have been put like this

Lua:
doors = {[1209] = 1211, [1210] = 1211}

Only the closed doors are added to doors and the open door has been added to verticalOpenDoors and that door works as it should

Lua:
verticalOpenDoors = {1211}
 
Copy paste your actions/scripts/other/doors.lua

You need to either import sprites as TFS does or made an small mod in doors.lua, I recommend the second.
Ah is that the problem? Well I am using the standard door.lua of tfs. I did not know that doors had to be imported a certain way tbh.
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
local itemId = item:getId()
if table.contains(questDoors, itemId) then
if player:getStorageValue(item.actionid) ~= -1 then
item:transform(itemId + 1)
player:teleportTo(toPosition, true)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
end
return true
elseif table.contains(levelDoors, itemId) then
if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
item:transform(itemId + 1)
player:teleportTo(toPosition, true)
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "Only the worthy may pass.")
end
return true
elseif table.contains(keys, itemId) then
if target.actionid > 0 then
if item.actionid == target.actionid and doors[target.itemid] then
target:transform(doors[target.itemid])
return true
end
player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
return true
end
return false
end
if table.contains(horizontalOpenDoors, itemId) or table.contains(verticalOpenDoors, itemId) then
local doorCreature = Tile(toPosition):getTopCreature()
if doorCreature then
toPosition.x = toPosition.x + 1
local query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
if query ~= RETURNVALUE_NOERROR then
toPosition.x = toPosition.x - 1
toPosition.y = toPosition.y + 1
query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
end
if query ~= RETURNVALUE_NOERROR then
player:sendTextMessage(MESSAGE_STATUS_SMALL, query)
return true
end
doorCreature:teleportTo(toPosition, true)
end
if not table.contains(openSpecialDoors, itemId) then
item:transform(itemId - 1)
end
return true
end
if doors[itemId] then
if item.actionid == 0 then
item:transform(doors[itemId])
else
player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
end
return true
end
return false
end
 
Remplace your doors.lua
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if table.contains(questDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(levelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Only the worthy may pass.")
        end
        return true
    elseif table.contains(keys, itemId) then
        if target.actionid > 0 then
            if item.actionid == target.actionid and doors[target.itemid] then
                target:transform(doors[target.itemid])
                return true
            end
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        return false
    end

    if table.contains(horizontalOpenDoors, itemId) or table.contains(verticalOpenDoors, itemId) then
        local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature ~= nil then
            toPosition.x = toPosition.x + 1
            local query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
            if query ~= RETURNVALUE_NOERROR then
                toPosition.x = toPosition.x - 1
                toPosition.y = toPosition.y + 1
                query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
            end

            if query ~= RETURNVALUE_NOERROR then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, query)
                return true
            end

            doorCreature:teleportTo(toPosition, true)
        end

        if doors[itemId] and not table.contains(openSpecialDoors, itemId) then
            item:transform(doors[itemId])
            return true
        elseif not table.contains(openSpecialDoors, itemId) then
            item:transform(itemId - 1)
        end
        return true
    end

    if doors[itemId] then
        if item.actionid >= 0 then
            item:transform(doors[itemId])
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        end
        return true
    end
    return false
end

global.lua
Lua:
doors = {[26529] = 26533, [26533] = 26529, [26531] = 26534, [26534] = 26531}
verticalOpenDoors = {26531}
horizontalOpenDoors = {26529}

There you go
 
Solution
Remplace your doors.lua
Lua:
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    if table.contains(questDoors, itemId) then
        if player:getStorageValue(item.actionid) ~= -1 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
        end
        return true
    elseif table.contains(levelDoors, itemId) then
        if item.actionid > 0 and player:getLevel() >= item.actionid - 1000 then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Only the worthy may pass.")
        end
        return true
    elseif table.contains(keys, itemId) then
        if target.actionid > 0 then
            if item.actionid == target.actionid and doors[target.itemid] then
                target:transform(doors[target.itemid])
                return true
            end
            player:sendTextMessage(MESSAGE_STATUS_SMALL, "The key does not match.")
            return true
        end
        return false
    end

    if table.contains(horizontalOpenDoors, itemId) or table.contains(verticalOpenDoors, itemId) then
        local doorCreature = Tile(toPosition):getTopCreature()
        if doorCreature ~= nil then
            toPosition.x = toPosition.x + 1
            local query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
            if query ~= RETURNVALUE_NOERROR then
                toPosition.x = toPosition.x - 1
                toPosition.y = toPosition.y + 1
                query = Tile(toPosition):queryAdd(doorCreature, bit.bor(FLAG_IGNOREBLOCKCREATURE, FLAG_PATHFINDING))
            end

            if query ~= RETURNVALUE_NOERROR then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, query)
                return true
            end

            doorCreature:teleportTo(toPosition, true)
        end

        if doors[itemId] and not table.contains(openSpecialDoors, itemId) then
            item:transform(doors[itemId])
            return true
        elseif not table.contains(openSpecialDoors, itemId) then
            item:transform(itemId - 1)
        end
        return true
    end

    if doors[itemId] then
        if item.actionid >= 0 then
            item:transform(doors[itemId])
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        end
        return true
    end
    return false
end

global.lua
Lua:
doors = {[26529] = 26533, [26533] = 26529, [26531] = 26534, [26534] = 26531}
verticalOpenDoors = {26531}
horizontalOpenDoors = {26529}

There you go
Worked like a charm! But I have to ask why do I have to add
Code:
verticalOpenDoors = {26531}
horizontalOpenDoors = {26529}
Because these are the closed doors and with all other doors the ones that are opened are added here.
 
Back
Top