• 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 [TFS 1.x] Slighty more advanced doors

Nekiro

Legendary OT User
TFS Developer
Joined
Sep 7, 2015
Messages
2,677
Solutions
126
Reaction score
2,112
This script will teleport player to the other side of the door depending on where he currently is to the door (left, right etc.). Additionaly I have added vocation and level check, that's it, very simple script.

Code:
-- written by Nekiro#5727

local config = {
    checkVocation = false,
    vocations = {1, 2, 3, 4, 5}, -- if check vocation

    checkLevel = false,
    level = 100, -- if check level

    doors = { -- list of all doors that will work with this script
        vertical = {1210, 1219},
        horizontal = {1213, 1221},
    },
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local itemId, destination = item:getId()
    if table.contains(config.doors.vertical, itemId) then
        local playerPos, doorPos = player:getPosition(), item:getPosition()
        if table.contains({Position(doorPos.x - 1, doorPos.y, doorPos.z), Position(doorPos.x - 1, doorPos.y - 1, doorPos.z), Position(doorPos.x - 1, doorPos.y + 1, doorPos.z)}, playerPos) then -- player stands left of the door
            destination = Position(doorPos.x + 1, doorPos.y, doorPos.z)
        elseif table.contains({Position(doorPos.x + 1, doorPos.y, doorPos.z), Position(doorPos.x + 1, doorPos.y + 1, doorPos.z), Position(doorPos.x + 1, doorPos.y - 1, doorPos.z)}, playerPos) then -- player stands right of the door
            destination = Position(doorPos.x - 1, doorPos.y, doorPos.z)
        end
    elseif table.contains(config.doors.horizontal, itemId) then
        local playerPos, doorPos = player:getPosition(), item:getPosition()
        if table.contains({Position(doorPos.x, doorPos.y - 1, doorPos.z), Position(doorPos.x - 1, doorPos.y - 1, doorPos.z), Position(doorPos.x + 1, doorPos.y - 1, doorPos.z)}, playerPos) then -- player stands north of the door
            destination = Position(doorPos.x, doorPos.y + 1, doorPos.z)
        elseif table.contains({Position(doorPos.x, doorPos.y + 1, doorPos.z), Position(doorPos.x - 1, doorPos.y + 1, doorPos.z), Position(doorPos.x + 1, doorPos.y + 1, doorPos.z)}, playerPos) then -- player stands south of the door
            destination = Position(doorPos.x, doorPos.y - 1, doorPos.z)
        end
    end

    if not destination then
        return true
    end

    if config.checkVocation and not table.contains(config.vocations, player:getVocation():getId()) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your vocation cannot enter this door.")
        return true
    end

    if config.checkLevel and player:getLevel() < config.level then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Your level is too low.")
        return true
    end

    player:teleportTo(destination, true)
    destination:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end
 
Would be better to set it with an action id right? The only way to register the doors to this code is to add their itemid's into the actions.xml file most of which are already added to the original doors.lua code. So that would cause a problem. However, you can set an action id so both codes will be ran when the door is used.
 
Would be better to set it with an action id right? The only way to register the doors to this code is to add their itemid's into the actions.xml file most of which are already added to the original doors.lua code. So that would cause a problem. However, you can set an action id so both codes will be ran when the door is used.
Yes, if you need to run two code at once for one item id then action ids is what you are looking for. This script is meant to replace classic opening and closing door, that's why it uses item id instead of actions.
 
Yes, if you need to run two code at once for one item id then action ids is what you are looking for. This script is meant to replace classic opening and closing door, that's why it uses item id instead of actions.

hey man, how i make to not teleport front the dor?
just open dor and after close...
 
Back
Top