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

Action Doors on Steroids TFS 1.2

Itutorial

Legendary OT User
Joined
Dec 23, 2014
Messages
2,334
Solutions
68
Reaction score
1,012
This code can replace your doors.lua

Why use this? You can set up the doors aid to check for quest, vocation, and level.

In the original door.lua code, quest doors would be accessible as long as the players storage (defined by the doors aid) is not nil then they can enter the door. With this code you can define certain times that the player can enter during the quest.

NOTE: Only actual quest doors can be used for a quest door.

There is no need to edit your actions.xml Just replace this code and set up your tables in the code for your needs. Enjoy =)

Lua:
local questDoors = {
    [1000] = {questValues = {5, 6}}
}
local vocationDoors = {
    [1000] = {vocs = {1, 2, 3, 4}}
}
local levelDoors = {
    [1000] = {levelMin = 50, levelMax = nil}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local voc = vocationDoors(itemAid)
    local level = levelDoors(itemAid)
   
    -- VOCATION DOORS --
    if voc and not isInArray(voc.vocs, player:getVocation():getId()) then
        local text = "Only "
            for i = 1, #voc.vocs do
                local VOC = Vocation(voc.vocs[i])
                if VOC then
                    text = text..""..VOC:getName()..", "
                end
            end
            text = text.." can enter here."
        return player:sendTextMessage(MESSAGE_INFO_DESCR, text)
    end
   
    -- LEVEL DOORS --
    if level then
        if level.levelMax ~= nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." - "..level.levelMax.." can enter here.")
        else
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." and higher can enter here.")
        end
    end
   
    -- QUEST DOORS --
    if isInArray(questDoors, itemId) then
        local quest = questDoors[item:getActionId()]
            if not quest then return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.") end
           
            if player:getStorageValue(item:getActionId()) ~= nil and isInArray(quest.questValues, player:getStorageValue(item:getActionId())) then
                item:transform(itemId + 1)
                player:teleportTo(toPosition, true)
            else
                return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
            end
    end
   
    if isInArray(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 isInArray(horizontalOpenDoors, itemId) or isInArray(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 not isInArray(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
 
Ahh, mod replace with this please.

Lua:
local questDoors = {
    [1000] = {questValues = {5, 6}}
}
local vocationDoors = {
    [1000] = {vocs = {1, 2, 3, 4}}
}
local levelDoors = {
    [1000] = {levelMin = 50, levelMax = nil}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local voc = vocationDoors(item:getActionId())
    local level = levelDoors(item:getActionId())
    local questDoor = questDoors(item:getActionId())
   
    -- VOCATION DOORS --
    if voc and not isInArray(voc.vocs, player:getVocation():getId()) then
        local text = "Only "
            for i = 1, #voc.vocs do
                local VOC = Vocation(voc.vocs[i])
                if VOC then
                    text = text..""..VOC:getName()..", "
                end
            end
            text = text.." can enter here."
        return player:sendTextMessage(MESSAGE_INFO_DESCR, text)
    end
   
    -- LEVEL DOORS --
    if level then
        if level.levelMax ~= nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." - "..level.levelMax.." can enter here.")
        else
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." and higher can enter here.")
        end
    end
   
    -- QUEST DOORS --
    if isInArray(questDoors, itemId) then
        local quest = questDoors[item:getActionId()]
            if not quest then return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.") end
           
            if player:getStorageValue(item:getActionId()) ~= nil and isInArray(quest.questValues, player:getStorageValue(item:getActionId())) then
                item:transform(itemId + 1)
                player:teleportTo(toPosition, true)
            else
                return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
            end
    end
   
    if isInArray(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 isInArray(horizontalOpenDoors, itemId) or isInArray(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 not isInArray(openSpecialDoors, itemId) then
            item:transform(itemId - 1)
        end
        return true
    end
    if doors[itemId] then
        if item.actionid == 0 or voc or level or questDoor then
            item:transform(doors[itemId])
        else
            player:sendTextMessage(MESSAGE_INFO_DESCR, "It is locked.")
        end
        return true
    end
    return false
end
 
Why not to make it just one single table instead of three?
 
Like this:

Lua:
local DoorAids = {
    [1000] = {questValues = {5, 6}, vocs = {1, 2, 3, 4}, levelMin = 50, levelMax = nil}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local DOOR = DoorAids[item:getActionId()]
   
    -- VOCATION DOORS --
    if DOOR and DOOR.vocs and not isInArray(DOOR.vocs, player:getVocation():getId()) then
        local text = "Only "
            for i = 1, #DOOR.vocs do
                local VOC = Vocation(DOOR.vocs[i])
                if VOC then
                    text = text..""..VOC:getName()..", "
                end
            end
            text = text.." can enter here."
        return player:sendTextMessage(MESSAGE_INFO_DESCR, text)
    end
   
    -- LEVEL DOORS --
    if DOOR and DOOR.levelMin or DOOR.levelMax then
        if DOOR.levelMin ~= nil and DOOR.levelMax ~= nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." - "..level.levelMax.." can enter here.")
        elseif DOOR.levelMin == nil and DOOR.levelMax ~= nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." and lower can enter here.")
        elseif DOOR.levelMin ~= nil and DOOR.levelMax == nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." and higher can enter here.")
        end
    end
   
    -- QUEST DOORS --
    if isInArray(questDoors, itemId) then
        if not DOOR or not DOOR.questValues then return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.") end
           
        if player:getStorageValue(item:getActionId()) ~= nil and isInArray(DOOR.questValues, player:getStorageValue(item:getActionId())) then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
            return true
        else
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
        end
    end
   
    if isInArray(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 isInArray(horizontalOpenDoors, itemId) or isInArray(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 not isInArray(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
 
Yep.
Although, storage value is never nil, so the check is kinda pointless. If it's not used it's -1.
You could also add some custom conditions for even better customization, like premium or item doors(checks for items).
 
I will probably do that.

Checking for nil and -1 is the same thing in the instance that you are checking the database for a storage that doesn't exist yet.
 
Lua:
if cid:getStorageValue(8807) == nil then cid:say('If you can see this, im gonna eat my toe nail.', TALKTYPE_SAY) elseif cid:getStorageValue(8807) == -1 then cid:getPosition():sendMagicEffect(CONST_ME_FIREWORK_RED) return true end
Run this then and make a screenshot. It's impossible to return a nil.
 
You are right, I thought TFS was set up to read the both as the same. I fixed it.

Lua:
local DoorAids = {
    [1000] = {questValues = {5, 6}, vocs = {1, 2, 3, 4}, levelMin = 50, levelMax = nil, premium = false, removeItems = false, items = {{1111, 1}, {1111, 1}}}
}
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId = item:getId()
    local DOOR = DoorAids[item:getActionId()]
   
   
    if DOOR and DOOR.premium then
        if player:getPremiumDays() < 1 then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "You must be premium to enter here.")
        end
    end
   
    if DOOR and DOOR.items then
        local text = "Items Required: "
        local hasItems = true
        for i = 1, #DOOR.items do
            local ITEM = ItemType(DOOR.items[i][1])
                if player:getItemCount(DOOR.items[i][1]) < DOOR.items[i][2] then
                    hasItems = false
                    text = text..""..DOOR.items[i][2].." "..ITEM:getName()..", "
                else
                    text = text..""..DOOR.items[i][2].." "..ITEM:getName()..", "
                end
        end
        if not hasItems then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, text)
        else
            for i = 1, #DOOR.items do
                player:removeItem(DOOR.items[i][1], DOOR.items[i][2])
            end
        end
    end
   
    -- VOCATION DOORS --
    if DOOR and DOOR.vocs and not isInArray(DOOR.vocs, player:getVocation():getId()) then
        local text = "Only "
            for i = 1, #DOOR.vocs do
                local VOC = Vocation(DOOR.vocs[i])
                if VOC then
                    text = text..""..VOC:getName()..", "
                end
            end
            text = text.." can enter here."
        return player:sendTextMessage(MESSAGE_INFO_DESCR, text)
    end
   
    -- LEVEL DOORS --
    if DOOR and DOOR.levelMin or DOOR.levelMax then
        if DOOR.levelMin ~= nil and DOOR.levelMax ~= nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." - "..level.levelMax.." can enter here.")
        elseif DOOR.levelMin == nil and DOOR.levelMax ~= nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." and lower can enter here.")
        elseif DOOR.levelMin ~= nil and DOOR.levelMax == nil then
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "Only levels "..level.levelMin.." and higher can enter here.")
        end
    end
   
    -- QUEST DOORS --
    if isInArray(questDoors, itemId) then
        if not DOOR or not DOOR.questValues then return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.") end
           
        if player:getStorageValue(item:getActionId()) ~= -1 and isInArray(DOOR.questValues, player:getStorageValue(item:getActionId())) then
            item:transform(itemId + 1)
            player:teleportTo(toPosition, true)
            return true
        else
            return player:sendTextMessage(MESSAGE_INFO_DESCR, "The door seems to be sealed against unwanted intruders.")
        end
    end
   
    if isInArray(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 isInArray(horizontalOpenDoors, itemId) or isInArray(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 not isInArray(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
 
Back
Top