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

Solved Elevator Script Help

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
829
Solutions
123
Reaction score
655
Location
United States
For TFS 1.1:

Having a few issues with an elevator script I've been working on.

First, I can't figure out how to make this part recognize the tiles and only let the player use the elevator if he is standing on those tiles. (Located in first part of script, line 12-15)

Second, I have a text animation through do creature say when you arrive at the floor but it only works half the time, it probably is because I couldn't correctly call multiple items in the tables either. (Located in the second part of the script, lines 24-50)

Lua:
function onUse(cid, words, position, Toposition)
    local player = Player(cid)
    local playerPos = getPlayerPosition(cid)
    local modal = ModalWindow (1901, "Depot Elevator", "Choose a floor:")
    local tilePos =  {
        {x=1232, y=1043, z=7},
        {x=1232, y=1043, z=6},
        {x=1232, y=1043, z=5},
        {x=1232, y=1043, z=4}
    }
  
    if Tile(playerPos) ~= Tile(tilePos) then
        doPlayerSendTextMessage(cid.uid, 18, "You must be inside the elevator.")
        return false
    end
  
    modal:addChoice(1, "Ground Floor")
    modal:addChoice(2, "Floor 1")
    modal:addChoice(3, "Floor 2")
    modal:addChoice(4, "Floor 3")
    if modal:getId() == 1901 then
    modal:addButton(3, "Select")
    modal:addButton(4, "Cancel")
    end
 
    modal:sendToPlayer(player)
    return true
end

Lua:
local pos1 = {x=1232, y=1043, z=7}
local pos2 = {x=1232, y=1043, z=6}
local pos3 = {x=1232, y=1043, z=5}
local pos4 = {x=1232, y=1043, z=4}
local ding1 = {x=1231, y=1043, z=7}
local ding2 = {x=1231, y=1043, z=6}  
local ding3 = {x=1231, y=1043, z=5}  
local ding4 = {x=1231, y=1043, z=4}

local function removeWall1 (p1, itemId)
    local gate1 = getTileItemById(p1, 9486)
    if gate1 then
        doRemoveItem(gate1.uid,1)
        end  
end

local function removeWall2 (p2, itemId)
    local gate2 = getTileItemById(p2, 9486)
    if gate2 then
        doRemoveItem(gate2.uid,1)
        end  
end

local function onDing1(cid)
     local player = Player(cid)
     if player then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, nil, Position(ding1))
     end
end

local function onDing2(cid)
     local player = Player(cid)
     if player then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, nil, Position(ding2))
     end
end

local function onDing3(cid)
     local player = Player(cid)
     if player then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, nil, Position(ding3))
     end
end

local function onDing4(cid)
     local player = Player(cid)
     if player then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, nil, Position(ding4))
     end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    local p1 = getPlayerPosition(cid)
        p1.x = p1.x + 1
        p1.y = p1.y + 1
    local p2 = getPlayerPosition(cid)
        p2.y = p2.y + 1  
      
    if modalWindowId == 1901 and buttonId ~= 3 then
    return false
    end
    if modalWindowId == 1901 and choiceId == 1 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at the ground floor.")
    addEvent(doTeleportThing, 1000, cid.uid, pos1, true)
    addEvent(onDing1, 1000, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 2 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 1.")
    addEvent(doTeleportThing, 1000, cid.uid, pos2, true)
    addEvent(onDing2, 1000, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 3 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 2.")
    addEvent(doTeleportThing, 1000, cid.uid, pos3, true)
    addEvent(onDing3, 1000, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 4 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 3.")
    addEvent(doTeleportThing, 1000, cid.uid, pos4, true)
    addEvent(onDing4, 1000, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
end
 
Last edited:
Solution
Are you running Linux?
Lua:
local modalWindowTargetId = 1901
local elevatorConfig = {
    [1] = { -- choiceID matched with modal window
        position = Position(1232, 1043, 7), -- position to teleport per floor
        dingPos = Position(1231, 1043, 7), -- position of switch  on each floor where ding displays on arrival
        msg = "You have arrived at the ground floor.",
    },
    [2] = {
        position = Position(1232, 1043, 6),
        dingPos = Position(1231, 1043, 6),
        msg = "You have arrived at Floor 1.",
    },
    [3] = {
        position = Position(1232, 1043, 5),
        dingPos = Position(1231, 1043, 5),
        msg = "You have arrived at Floor 2.",
    },
    [4] = {
        position = Position(1232, 1043, 4)...
Updated:

Reworked and have the ding part working, but still cannot figure out how to make it send the text message only when in standing on tilePos positions.

Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    local playerPos = getPlayerPosition(player)
    local modal = ModalWindow (1901, "Depot Elevator", "Choose a floor:")
    local tilePos =  {
        {x=1232, y=1043, z=7},
        {x=1232, y=1043, z=6},
        {x=1232, y=1043, z=5},
        {x=1232, y=1043, z=4}
    }

    if playerPos ~= Position(isInArray(tilePos)) then
        doPlayerSendTextMessage(player, 18, "You must be inside the elevator.")
        return false
    end
   
    modal:addChoice(1, "Ground Floor")
    modal:addChoice(2, "Floor 1")
    modal:addChoice(3, "Floor 2")
    modal:addChoice(4, "Floor 3")
    if modal:getId() == 1901 then
    modal:addButton(3, "Select")
    modal:addButton(4, "Cancel")
    end
  
    modal:sendToPlayer(player)
    return true
end

Lua:
local pos1 = {x=1232, y=1043, z=7}
local pos2 = {x=1232, y=1043, z=6}
local pos3 = {x=1232, y=1043, z=5}
local pos4 = {x=1232, y=1043, z=4}
local ding1 = {x=1231, y=1043, z=7}
local ding2 = {x=1231, y=1043, z=6}   
local ding3 = {x=1231, y=1043, z=5}   
local ding4 = {x=1231, y=1043, z=4}

local function removeWall1 (p1, itemId)
    local gate1 = getTileItemById(p1, 9486)
    if gate1 then
        doRemoveItem(gate1.uid,1)
        end   
end

local function removeWall2 (p2, itemId)
    local gate2 = getTileItemById(p2, 9486)
    if gate2 then
        doRemoveItem(gate2.uid,1)
        end   
end

local function onDing(cid)
     local player = Player(cid)
     if player then
        if getPlayerPosition(cid) == Position(pos1) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding1))
        end       
        if getPlayerPosition(cid) == Position(pos2) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding2))
        end       
        if getPlayerPosition(cid) == Position(pos3) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding3))
        end       
        if getPlayerPosition(cid) == Position(pos4) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding4))
        end
     end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    local p1 = getPlayerPosition(cid)
        p1.x = p1.x + 1
        p1.y = p1.y + 1
    local p2 = getPlayerPosition(cid)
        p2.y = p2.y + 1
       
    if modalWindowId == 1901 and buttonId ~= 3 then
    return false
    end
    if modalWindowId == 1901 and choiceId == 1 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at the ground floor.")
    addEvent(doTeleportThing, 1000, cid.uid, pos1, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 2 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 1.")
    addEvent(doTeleportThing, 1000, cid.uid, pos2, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 3 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 2.")
    addEvent(doTeleportThing, 1000, cid.uid, pos3, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 4 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 3.")
    addEvent(doTeleportThing, 1000, cid.uid, pos4, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
end
 
Updated:

Reworked and have the ding part working, but still cannot figure out how to make it send the text message only when in standing on tilePos positions.

Lua:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    local playerPos = getPlayerPosition(player)
    local modal = ModalWindow (1901, "Depot Elevator", "Choose a floor:")
    local tilePos =  {
        {x=1232, y=1043, z=7},
        {x=1232, y=1043, z=6},
        {x=1232, y=1043, z=5},
        {x=1232, y=1043, z=4}
    }

    if playerPos ~= Position(isInArray(tilePos)) then
        doPlayerSendTextMessage(player, 18, "You must be inside the elevator.")
        return false
    end
  
    modal:addChoice(1, "Ground Floor")
    modal:addChoice(2, "Floor 1")
    modal:addChoice(3, "Floor 2")
    modal:addChoice(4, "Floor 3")
    if modal:getId() == 1901 then
    modal:addButton(3, "Select")
    modal:addButton(4, "Cancel")
    end
 
    modal:sendToPlayer(player)
    return true
end

Lua:
local pos1 = {x=1232, y=1043, z=7}
local pos2 = {x=1232, y=1043, z=6}
local pos3 = {x=1232, y=1043, z=5}
local pos4 = {x=1232, y=1043, z=4}
local ding1 = {x=1231, y=1043, z=7}
local ding2 = {x=1231, y=1043, z=6}  
local ding3 = {x=1231, y=1043, z=5}  
local ding4 = {x=1231, y=1043, z=4}

local function removeWall1 (p1, itemId)
    local gate1 = getTileItemById(p1, 9486)
    if gate1 then
        doRemoveItem(gate1.uid,1)
        end  
end

local function removeWall2 (p2, itemId)
    local gate2 = getTileItemById(p2, 9486)
    if gate2 then
        doRemoveItem(gate2.uid,1)
        end  
end

local function onDing(cid)
     local player = Player(cid)
     if player then
        if getPlayerPosition(cid) == Position(pos1) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding1))
        end      
        if getPlayerPosition(cid) == Position(pos2) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding2))
        end      
        if getPlayerPosition(cid) == Position(pos3) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding3))
        end      
        if getPlayerPosition(cid) == Position(pos4) then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(ding4))
        end
     end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    local p1 = getPlayerPosition(cid)
        p1.x = p1.x + 1
        p1.y = p1.y + 1
    local p2 = getPlayerPosition(cid)
        p2.y = p2.y + 1
      
    if modalWindowId == 1901 and buttonId ~= 3 then
    return false
    end
    if modalWindowId == 1901 and choiceId == 1 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at the ground floor.")
    addEvent(doTeleportThing, 1000, cid.uid, pos1, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 2 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 1.")
    addEvent(doTeleportThing, 1000, cid.uid, pos2, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 3 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 2.")
    addEvent(doTeleportThing, 1000, cid.uid, pos3, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 4 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 3.")
    addEvent(doTeleportThing, 1000, cid.uid, pos4, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
end

Please don't mix legacy and meta code, just becomes messy :p
Lua:
if playerPos ~= Position(isInArray(tilePos)) then

Okay so playerPos is a userdata value (Position)
Same goes with tilePos, but isInArray returns a boolean value(true/false)
So when you are doing is comparing a position userdata with a position userdata that contains a boolean value = wrong
Try doing this:
In your tilePos array, use Position(x, y, z) insted of {x = , y = , z = }
And then use this;
Lua:
if playerPos ~= tilePos then

You can update the rest of the script with this file; forgottenserver/compat.lua at master · otland/forgottenserver · GitHub
Just use ctrl+f then enter the function name and see what it returns, use that function.
Ex doPlayerAddHealth(cid, x) => player:addHealth(x)
 
I didn't fix anything, I just made it easier to read.
Code:
elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
  
    tilePositions = {   -- elevator positions
        {x=1232, y=1043, z=7},
        {x=1232, y=1043, z=6},
        {x=1232, y=1043, z=5},
        {x=1232, y=1043, z=4}
    },
  
    elevatorT = {
        [1] = {                                 -- choiceID matched with modal window
            position = {x=1232, y=1043, z=7},   -- explain what is that positions
            dingPos = {x=1231, y=1043, z=7},    -- explain what is that positions
            msg = "You have arrived at the ground floor.",
          
        },
        [2] = {
            position = {x=1232, y=1043, z=6},
            dingPos = {x=1231, y=1043, z=6},
            msg = "You have arrived at Floor 1.",
        },
        [3] = {
            position = {x=1232, y=1043, z=5},
            dingPos = {x=1231, y=1043, z=5},
            msg = "You have arrived at Floor 2.",
        },
        [4] = {
            position = {x=1232, y=1043, z=4},
            dingPos = {x=1231, y=1043, z=4},
            msg = "You have arrived at Floor 3.",
        }
    },
    errorMsg_elevator = "You must be inside the elevator.".
}

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = Player(cid)

    if not player then return print("player is missing in elevator script") end
    if not Position(isInArray(elevatorConf.tilePositions, getPlayerPosition(player))) then return false, doPlayerSendTextMessage(player, 18, elevatorConf.errorMsg_elevator) end
local mwT = elevatorConf.modalWindow
local modal = ModalWindow (mwT.mwID, mwT.name, mwT.title)
 
    for choiceID, choiceText in pairs(mwT.choiceT) do modal:addChoice(choiceID, choiceText) end
    for buttonID, buttonText in pairs(mwT.buttonT) do modal:addChoice(buttonID, buttonText) end
    return modal:sendToPlayer(player)
end

local function onDing(playerID, position, dingPos)
local player = Player(playerID)
  
    if not player then return end
    if getPlayerPosition(player) ~= Position(position) then return end -- are you sure you can compare userdatas like that? You might need to compare the x, y and z value instead (At least thats what I do)
    player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(dingPos))
end

local function removeWall(wallPos, wallID)
local item = getTileItemById(wallPos, wallID)

    if not item then return end
    doRemoveItem(item.uid, 1)
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= elevatorConf.modalWindow.mwID then return end
    if buttonId == 2 then return end -- make sure you "cancel" is matching with buttonID
local elevatorT = getElevatorT(choiceId)
  
    if not elevatorT then return print("player was able to choose elevator choice what does not exist: "..choiceId) end
local playerPos = getPlayerPosition(cid)
local pos1 = {x = playerPos.x+1, y = playerPos.y+1, z = playerPos.z}
local pos2 = {x = playerPos.x, y = playerPos.y+1, z = playerPos.z}
local playerID = cid.uid

    addEvent(doCreateItem, 1, 9486, 1, pos1)
    addEvent(doCreateItem, 500, 9486, 1, pos2)
    addEvent(doPlayerSendTextMessage, 1000, playerID, 18, elevatorT.msg)
    addEvent(doTeleportThing, 1000, playerID, elevatorT.position, true)
    addEvent(onDing, 1100, playerID, elevatorT.position, elevatorT.dingPos)
    addEvent(removeWall, 2000, pos1, 9486)
    addEvent(removeWall, 1500, pos2, 9486)
    return true
end

function getElevatorT(choiceID) return elevatorConf.elevatorT[choiceID] end
 
Thanks for you replying guys, thanks for the advice trying my best now not to mix code, can't really use your edit @whitevo because the first part of the script is in creature events for the module window and the other is in actions for the action id on the elevator button. Currently with this new set up the ding still is wrong, it's sending it to cid instead of the position I want, and also now in tilePos only the first position is registering. All the dings are on seperate floors so what im trying to figure out is how to check ALL the positions in tilePos and if you're not standing on any of those 4 tiles then the script will send player text saying you must be inside the elevator.

Currently have it like this:

Code:
local pos1 = Position(1232, 1043, 7)
local pos2 = Position(1232, 1043, 6)
local pos3 = Position(1232, 1043, 5)
local pos4 = Position(1232, 1043, 4)
local ding1 = Position(1231, 1043, 7)
local ding2 = Position(1231, 1043, 6)   
local ding3 = Position(1231, 1043, 5)   
local ding4 = Position(1231, 1043, 4)

local function removeWall1 (p1, itemId)
    local gate1 = getTileItemById(p1, 9486)
    if gate1 then
        doRemoveItem(gate1.uid,1)
        end   
end

local function removeWall2 (p2, itemId)
    local gate2 = getTileItemById(p2, 9486)
    if gate2 then
        doRemoveItem(gate2.uid,1)
        end   
end

local function onDing(cid)
     local player = Player(cid)
     if player then
        if player:getPosition(cid) == pos1 then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, true, ding1)
        end       
        if player:getPosition(cid) == pos2 then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, true, ding2)
        end       
        if player:getPosition(cid) == pos3 then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, true, ding3)
        end       
        if player:getPosition(cid) == pos4 then
         player:say("*ding*", TALKTYPE_MONSTER_SAY, true, ding4)
        end
     end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    local p1 = getPlayerPosition(cid)
        p1.x = p1.x + 1
        p1.y = p1.y + 1
    local p2 = getPlayerPosition(cid)
        p2.y = p2.y + 1
       
    if modalWindowId == 1901 and buttonId ~= 3 then
    return false
    end
    if modalWindowId == 1901 and choiceId == 1 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at the ground floor.")
    addEvent(doTeleportThing, 1000, cid.uid, pos1, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 2 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 1.")
    addEvent(doTeleportThing, 1000, cid.uid, pos2, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 3 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 2.")
    addEvent(doTeleportThing, 1000, cid.uid, pos3, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
    if modalWindowId == 1901 and choiceId == 4 then
    addEvent(doCreateItem, 1, 9486, 1, p1)
    addEvent(doCreateItem, 500, 9486, 1, p2)
    addEvent(doPlayerSendTextMessage, 1000, cid.uid, 18, "You have arrived at Floor 3.")
    addEvent(doTeleportThing, 1000, cid.uid, pos4, true)
    addEvent(onDing, 1100, cid.uid)
    addEvent(removeWall2, 1500, p2, 9486)
    addEvent(removeWall1, 2000, p1, 9486)
    return true
    end
end

Code:
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    local playerPos = getPlayerPosition(player)
    local modal = ModalWindow (1901, "Depot Elevator", "Choose a floor:")
    local tilePos = 
        Position(1232, 1043, 7),
        Position(1232, 1043, 6),
        Position(1232, 1043, 5),
        Position(1232, 1043, 4)
   

    if player then
        if playerPos ~= tilePos then
            player:sendTextMessage(18, "You must be inside the elevator.")
            return false
        end
    end
   
    modal:addChoice(1, "Ground Floor")
    modal:addChoice(2, "Floor 1")
    modal:addChoice(3, "Floor 2")
    modal:addChoice(4, "Floor 3")
    if modal:getId() == 1901 then
    modal:addButton(3, "Select")
    modal:addButton(4, "Cancel")
    end
  
    modal:sendToPlayer(player)
    return true
end
 
EDITED-- Didn't read it properly
All the dings are on seperate floors so what im trying to figure out is how to check ALL the positions in tilePos and if you're not standing on any of those 4 tiles then the script will send player text saying you must be inside the elevator.
Maybe something like this?

Code:
local function isOnElevator(playerPos)
    local tilePos = {
    [1] = Position(1232, 1043, 7),
    [2] = Position(1232, 1043, 6),
    [3] = Position(1232, 1043, 5),
    [4] = Position(1232, 1043, 4)
}

    for i = 1, #tilePos do
        if playerPos == tilePos[i] then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    local playerPos = getPlayerPosition(player)
    local modal = ModalWindow (1901, "Depot Elevator", "Choose a floor:")
 
    if player then
        if isOnElevator(playerPos) then
            modal:addChoice(1, "Ground Floor")
            modal:addChoice(2, "Floor 1")
            modal:addChoice(3, "Floor 2")
            modal:addChoice(4, "Floor 3")
              
            if modal:getId() == 1901 then
                modal:addButton(3, "Select")
                modal:addButton(4, "Cancel")
            end
            
            modal:sendToPlayer(player)
        else
            player:sendTextMessage(18, "You must be inside the elevator.")
        end
    end
    return true
end
 
Last edited:
you can use my code its the same code as yours just less redundant stuff and easier to config and read.
simply divide the functions to corresponding scripts.

I don't scripts for lower TFS versions than 1.x so don't know what your global functions do, hence not the man to fix it, but others have easier time to spot it if they see less code.
 
EDITED-- Didn't read it properly

Maybe something like this?

Code:
local function isOnElevator(playerPos)
    local tilePos = {
    [1] = Position(1232, 1043, 7),
    [2] = Position(1232, 1043, 6),
    [3] = Position(1232, 1043, 5),
    [4] = Position(1232, 1043, 4)
}

    for i = 1, #tilePos do
        if playerPos == tilePos[i] then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    local playerPos = getPlayerPosition(player)
    local modal = ModalWindow (1901, "Depot Elevator", "Choose a floor:")
 
    if player then
        if isOnElevator(playerPos) then
            modal:addChoice(1, "Ground Floor")
            modal:addChoice(2, "Floor 1")
            modal:addChoice(3, "Floor 2")
            modal:addChoice(4, "Floor 3")
             
            if modal:getId() == 1901 then
                modal:addButton(3, "Select")
                modal:addButton(4, "Cancel")
            end
           
            modal:sendToPlayer(player)
        else
            player:sendTextMessage(18, "You must be inside the elevator.")
        end
    end
    return true
end


Tested and moved some things around, but its opening the modal window no matter what. :/ But this seem to be along the lines of what is needed in this script, does the I stand for anything or is it just a filler here? Also would pairs or ipairs be something to use here?

you can use my code its the same code as yours just less redundant stuff and easier to config and read.
simply divide the functions to corresponding scripts.

I don't scripts for lower TFS versions than 1.x so don't know what your global functions do, hence not the man to fix it, but others have easier time to spot it if they see less code.
Oh, okay ill mess with it. Appreciate the help bro.
 
Last edited by a moderator:
Tested and moved some things around, but its opening the modal window no matter what. :/ But this seem to be along the lines of what is needed in this script, does the I stand for anything or is it just a filler here? Also would pairs or ipairs be something to use here?
You could use ipairs too...
lua-users wiki: For Tutorial

Try adding isOnElevator(playerPos) == true
 
Current set up, both problems still exist, tried adding what @Beto06 suggested, but now with set to true neither return without the error message, and with false it will open with any tile still.

Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    tilePositions = {   -- elevator positions
        Position(1232, 1043, 7),
        Position(1232, 1043, 6),
        Position(1232, 1043, 5),
        Position(1232, 1043, 4)
    },
    errorMsg_elevator = "You must be inside the elevator."
}

--local function isOnElevator(playerPos)
--   local tilePos = {
--    [1] = Position(1232, 1043, 7),
--    [2] = Position(1232, 1043, 6),
--    [3] = Position(1232, 1043, 5),
--    [4] = Position(1232, 1043, 4)
--}
--
--   for i = 1, #tilePos do
--      if playerPos == tilePos[i] then
--            return true
--        end
--    end
--    return false
--end
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = Player(cid)
    if not player then return print("player is missing in elevator script") end
    if not Position(isInArray(elevatorConf.tilePositions, getPlayerPosition(player))) then return false, doPlayerSendTextMessage(player, 18, elevatorConf.errorMsg_elevator) end
local mwT = elevatorConf.modalWindow
local modal = ModalWindow (mwT.mwID, mwT.name, mwT.title)
--    if isOnElevator(playerPos) == true then
        for choiceID, choiceText in pairs(mwT.choiceT) do modal:addChoice(choiceID, choiceText) end
        for buttonID, buttonText in pairs(mwT.buttonT) do modal:addButton(buttonID, buttonText) end
        return modal:sendToPlayer(player)
--    end
end

Code:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    elevatorT = {
        [1] = {                                 -- choiceID matched with modal window
            position = Position(1232, 1043, 7),   -- position to teleport per floor
            dingPos = Position(1231, 1043, 7),    -- position of switch  on each floor where ding displays on arrival
            msg = "You have arrived at the ground floor.",
        
        },
        [2] = {
            position = Position(1232, 1043, 6),
            dingPos = Position(1231, 1043, 6),
            msg = "You have arrived at Floor 1.",
        },
        [3] = {
            position = Position(1232, 1043, 5),
            dingPos = Position(1231, 1043, 5),
            msg = "You have arrived at Floor 2.",
        },
        [4] = {
            position = Position(1232, 1043, 4),
            dingPos = Position(1231, 1043, 4),
            msg = "You have arrived at Floor 3.",
        }
    },
}
local function onDing(playerID, position, dingPos)
local player = Player(playerID)
    if not player then return end
    if player:getPosition() ~= Position(position) then return end -- are you sure you can compare userdatas like that? You might need to compare the x, y and z value instead (At least thats what I do)
    player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(dingPos))
end
local function removeWall(wallPos, wallID)
local item = getTileItemById(wallPos, wallID)
    if not item then return end
    doRemoveItem(item.uid, 1)
end
function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= elevatorConf.modalWindow.mwID then return end
    if buttonId == 2 then return end
local elevatorT = getElevatorT(choiceId)
    if not elevatorT then return print("player was able to choose elevator choice which does not exist: "..choiceId) end
local playerPos = getPlayerPosition(cid)
local pos1 = {x = playerPos.x+1, y = playerPos.y+1, z = playerPos.z}
local pos2 = {x = playerPos.x, y = playerPos.y+1, z = playerPos.z}
local playerID = cid.uid
    addEvent(doCreateItem, 1, 9486, 1, pos1)
    addEvent(doCreateItem, 500, 9486, 1, pos2)
    addEvent(doPlayerSendTextMessage, 1000, playerID, 18, elevatorT.msg)
    addEvent(doTeleportThing, 1000, playerID, elevatorT.position, true)
    addEvent(onDing, 1010, playerID, elevatorT.position, elevatorT.dingPos)
    addEvent(removeWall, 2000, pos1, 9486)
    addEvent(removeWall, 1500, pos2, 9486)
    return true
end
function getElevatorT(choiceID) return elevatorConf.elevatorT[choiceID] end
 
I didn't fix anything, I just made it easier to read.
Code:
elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
 
    tilePositions = {   -- elevator positions
        {x=1232, y=1043, z=7},
        {x=1232, y=1043, z=6},
        {x=1232, y=1043, z=5},
        {x=1232, y=1043, z=4}
    },
 
    elevatorT = {
        [1] = {                                 -- choiceID matched with modal window
            position = {x=1232, y=1043, z=7},   -- explain what is that positions
            dingPos = {x=1231, y=1043, z=7},    -- explain what is that positions
            msg = "You have arrived at the ground floor.",
         
        },
        [2] = {
            position = {x=1232, y=1043, z=6},
            dingPos = {x=1231, y=1043, z=6},
            msg = "You have arrived at Floor 1.",
        },
        [3] = {
            position = {x=1232, y=1043, z=5},
            dingPos = {x=1231, y=1043, z=5},
            msg = "You have arrived at Floor 2.",
        },
        [4] = {
            position = {x=1232, y=1043, z=4},
            dingPos = {x=1231, y=1043, z=4},
            msg = "You have arrived at Floor 3.",
        }
    },
    errorMsg_elevator = "You must be inside the elevator.".
}

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = Player(cid)

    if not player then return print("player is missing in elevator script") end
    if not Position(isInArray(elevatorConf.tilePositions, getPlayerPosition(player))) then return false, doPlayerSendTextMessage(player, 18, elevatorConf.errorMsg_elevator) end
local mwT = elevatorConf.modalWindow
local modal = ModalWindow (mwT.mwID, mwT.name, mwT.title)
 
    for choiceID, choiceText in pairs(mwT.choiceT) do modal:addChoice(choiceID, choiceText) end
    for buttonID, buttonText in pairs(mwT.buttonT) do modal:addChoice(buttonID, buttonText) end
    return modal:sendToPlayer(player)
end

local function onDing(playerID, position, dingPos)
local player = Player(playerID)
 
    if not player then return end
    if getPlayerPosition(player) ~= Position(position) then return end -- are you sure you can compare userdatas like that? You might need to compare the x, y and z value instead (At least thats what I do)
    player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(dingPos))
end

local function removeWall(wallPos, wallID)
local item = getTileItemById(wallPos, wallID)

    if not item then return end
    doRemoveItem(item.uid, 1)
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= elevatorConf.modalWindow.mwID then return end
    if buttonId == 2 then return end -- make sure you "cancel" is matching with buttonID
local elevatorT = getElevatorT(choiceId)
 
    if not elevatorT then return print("player was able to choose elevator choice what does not exist: "..choiceId) end
local playerPos = getPlayerPosition(cid)
local pos1 = {x = playerPos.x+1, y = playerPos.y+1, z = playerPos.z}
local pos2 = {x = playerPos.x, y = playerPos.y+1, z = playerPos.z}
local playerID = cid.uid

    addEvent(doCreateItem, 1, 9486, 1, pos1)
    addEvent(doCreateItem, 500, 9486, 1, pos2)
    addEvent(doPlayerSendTextMessage, 1000, playerID, 18, elevatorT.msg)
    addEvent(doTeleportThing, 1000, playerID, elevatorT.position, true)
    addEvent(onDing, 1100, playerID, elevatorT.position, elevatorT.dingPos)
    addEvent(removeWall, 2000, pos1, 9486)
    addEvent(removeWall, 1500, pos2, 9486)
    return true
end

function getElevatorT(choiceID) return elevatorConf.elevatorT[choiceID] end

Haha just NO :D
One liner if statments ... ugh... :D

You could use ipairs too...
lua-users wiki: For Tutorial

Try adding isOnElevator(playerPos) == true
When it comes to Lua(and most other languages they use boolean values in if statments, if a function returns true then the statment will be executed.
== true is there for not needed at all, same with false (just use if not .. then) btw that will also make sure the value isn't nil.

Current set up, both problems still exist, tried adding what @Beto06 suggested, but now with set to true neither return without the error message, and with false it will open with any tile still.

Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    tilePositions = {   -- elevator positions
        Position(1232, 1043, 7),
        Position(1232, 1043, 6),
        Position(1232, 1043, 5),
        Position(1232, 1043, 4)
    },
    errorMsg_elevator = "You must be inside the elevator."
}

--local function isOnElevator(playerPos)
--   local tilePos = {
--    [1] = Position(1232, 1043, 7),
--    [2] = Position(1232, 1043, 6),
--    [3] = Position(1232, 1043, 5),
--    [4] = Position(1232, 1043, 4)
--}
--
--   for i = 1, #tilePos do
--      if playerPos == tilePos[i] then
--            return true
--        end
--    end
--    return false
--end
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
local player = Player(cid)
    if not player then return print("player is missing in elevator script") end
    if not Position(isInArray(elevatorConf.tilePositions, getPlayerPosition(player))) then return false, doPlayerSendTextMessage(player, 18, elevatorConf.errorMsg_elevator) end
local mwT = elevatorConf.modalWindow
local modal = ModalWindow (mwT.mwID, mwT.name, mwT.title)
--    if isOnElevator(playerPos) == true then
        for choiceID, choiceText in pairs(mwT.choiceT) do modal:addChoice(choiceID, choiceText) end
        for buttonID, buttonText in pairs(mwT.buttonT) do modal:addButton(buttonID, buttonText) end
        return modal:sendToPlayer(player)
--    end
end

Code:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    elevatorT = {
        [1] = {                                 -- choiceID matched with modal window
            position = Position(1232, 1043, 7),   -- position to teleport per floor
            dingPos = Position(1231, 1043, 7),    -- position of switch  on each floor where ding displays on arrival
            msg = "You have arrived at the ground floor.",
       
        },
        [2] = {
            position = Position(1232, 1043, 6),
            dingPos = Position(1231, 1043, 6),
            msg = "You have arrived at Floor 1.",
        },
        [3] = {
            position = Position(1232, 1043, 5),
            dingPos = Position(1231, 1043, 5),
            msg = "You have arrived at Floor 2.",
        },
        [4] = {
            position = Position(1232, 1043, 4),
            dingPos = Position(1231, 1043, 4),
            msg = "You have arrived at Floor 3.",
        }
    },
}
local function onDing(playerID, position, dingPos)
local player = Player(playerID)
    if not player then return end
    if player:getPosition() ~= Position(position) then return end -- are you sure you can compare userdatas like that? You might need to compare the x, y and z value instead (At least thats what I do)
    player:say("*ding*", TALKTYPE_MONSTER_SAY, false, Position(dingPos))
end
local function removeWall(wallPos, wallID)
local item = getTileItemById(wallPos, wallID)
    if not item then return end
    doRemoveItem(item.uid, 1)
end
function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= elevatorConf.modalWindow.mwID then return end
    if buttonId == 2 then return end
local elevatorT = getElevatorT(choiceId)
    if not elevatorT then return print("player was able to choose elevator choice which does not exist: "..choiceId) end
local playerPos = getPlayerPosition(cid)
local pos1 = {x = playerPos.x+1, y = playerPos.y+1, z = playerPos.z}
local pos2 = {x = playerPos.x, y = playerPos.y+1, z = playerPos.z}
local playerID = cid.uid
    addEvent(doCreateItem, 1, 9486, 1, pos1)
    addEvent(doCreateItem, 500, 9486, 1, pos2)
    addEvent(doPlayerSendTextMessage, 1000, playerID, 18, elevatorT.msg)
    addEvent(doTeleportThing, 1000, playerID, elevatorT.position, true)
    addEvent(onDing, 1010, playerID, elevatorT.position, elevatorT.dingPos)
    addEvent(removeWall, 2000, pos1, 9486)
    addEvent(removeWall, 1500, pos2, 9486)
    return true
end
function getElevatorT(choiceID) return elevatorConf.elevatorT[choiceID] end

Once again, you can't compare a Positon userdata value and a boolean value (what you are doing)
Lua:
if not Position(isInArray(elevatorConf.tilePositions, getPlayerPosition(player))) then

What you are trying to see if there is a position at the position true, try opening your map editor at the position "true" or even false or nil for that matter.
 
Was something simple of course, I forgot to add "local playerPos = getPlayerPosition(cid)", the "you must be in the elevator" part is now working. Still can't figure out the ding part yet but will continue to try.

Hopefully last update:
Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    tilePositions = {   -- elevator positions
        Position(1232, 1043, 7),
        Position(1232, 1043, 6),
        Position(1232, 1043, 5),
        Position(1232, 1043, 4)
    },
    errorMsg_elevator = "You must be inside the elevator."
}

local function isOnElevator(playerPos)
   local tilePos = {
    [1] = Position(1232, 1043, 7),
    [2] = Position(1232, 1043, 6),
    [3] = Position(1232, 1043, 5),
    [4] = Position(1232, 1043, 4)
}
   for i = 1, #tilePos do
      if playerPos == tilePos[i] then
            return true
        end
    end
   return false
end
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    local playerPos = getPlayerPosition(cid)
    local mwT = elevatorConf.modalWindow
    local modal = ModalWindow (mwT.mwID, mwT.name, mwT.title)
    if not player then
        return print("player is missing in elevator script")
    end
 
    if not isOnElevator(playerPos) then
        player:sendTextMessage(18, elevatorConf.errorMsg_elevator)
        return false
    end
    for choiceID, choiceText in pairs(mwT.choiceT) do
        modal:addChoice(choiceID, choiceText)
    end
 
    for buttonID, buttonText in pairs(mwT.buttonT) do
        modal:addButton(buttonID, buttonText)
    end
    return
    modal:sendToPlayer(player)
end

Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    elevatorT = {
        [1] = {                                 -- choiceID matched with modal window
            position = Position(1232, 1043, 7),   -- position to teleport per floor
            dingPos = Position(1231, 1043, 7),    -- position of switch  on each floor where ding displays on arrival
            msg = "You have arrived at the ground floor.",
        
        },
        [2] = {
            position = Position(1232, 1043, 6),
            dingPos = Position(1231, 1043, 6),
            msg = "You have arrived at Floor 1.",
        },
        [3] = {
            position = Position(1232, 1043, 5),
            dingPos = Position(1231, 1043, 5),
            msg = "You have arrived at Floor 2.",
        },
        [4] = {
            position = Position(1232, 1043, 4),
            dingPos = Position(1231, 1043, 4),
            msg = "You have arrived at Floor 3.",
        }
    },
}
local function onDing(playerID, position, dingPos)
local player = Player(playerID)
    if not player then
        return
    end
   
    if player:getPosition() ~= Position(position) then
        return
    end -- are you sure you can compare userdatas like that? You might need to compare the x, y and z value instead (At least thats what I do)
    player:say("*ding*", TALKTYPE_MONSTER_SAY, false, dingPos)
end
local function removeWall(wallPos, wallID)
    local item = getTileItemById(wallPos, wallID)
    if not item then
        return
    end
    doRemoveItem(item.uid, 1)
end

function getElevatorT(choiceID)
    return elevatorConf.elevatorT[choiceID]
end
function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    local playerPos = getPlayerPosition(cid)
    local pos1 = {x = playerPos.x+1, y = playerPos.y+1, z = playerPos.z}
    local pos2 = {x = playerPos.x, y = playerPos.y+1, z = playerPos.z}
    local elevatorT = getElevatorT(choiceId)
    local playerID = cid.uid

    if modalWindowId ~= elevatorConf.modalWindow.mwID then
        return
    end
   
    if buttonId == 2 then
        return
    end
    if not elevatorT then
        return print("player was able to choose elevator choice which does not exist: "..choiceId)
    end
    addEvent(doCreateItem, 1, 9486, 1, pos1)
    addEvent(doCreateItem, 500, 9486, 1, pos2)
    addEvent(doPlayerSendTextMessage, 1000, playerID, 18, elevatorT.msg)
    addEvent(doTeleportThing, 1000, playerID, elevatorT.position, true)
    addEvent(onDing, 1010, playerID, elevatorT.position, elevatorT.dingPos)
    addEvent(removeWall, 2000, pos1, 9486)
    addEvent(removeWall, 1500, pos2, 9486)
    return true
end
 
Was something simple of course, I forgot to add "local playerPos = getPlayerPosition(cid)", the "you must be in the elevator" part is now working. Still can't figure out the ding part yet but will continue to try.

Hopefully last update:
Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    tilePositions = {   -- elevator positions
        Position(1232, 1043, 7),
        Position(1232, 1043, 6),
        Position(1232, 1043, 5),
        Position(1232, 1043, 4)
    },
    errorMsg_elevator = "You must be inside the elevator."
}

local function isOnElevator(playerPos)
   local tilePos = {
    [1] = Position(1232, 1043, 7),
    [2] = Position(1232, 1043, 6),
    [3] = Position(1232, 1043, 5),
    [4] = Position(1232, 1043, 4)
}
   for i = 1, #tilePos do
      if playerPos == tilePos[i] then
            return true
        end
    end
   return false
end
function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local player = Player(cid)
    local playerPos = getPlayerPosition(cid)
    local mwT = elevatorConf.modalWindow
    local modal = ModalWindow (mwT.mwID, mwT.name, mwT.title)
    if not player then
        return print("player is missing in elevator script")
    end
 
    if not isOnElevator(playerPos) then
        player:sendTextMessage(18, elevatorConf.errorMsg_elevator)
        return false
    end
    for choiceID, choiceText in pairs(mwT.choiceT) do
        modal:addChoice(choiceID, choiceText)
    end
 
    for buttonID, buttonText in pairs(mwT.buttonT) do
        modal:addButton(buttonID, buttonText)
    end
    return
    modal:sendToPlayer(player)
end

Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    elevatorT = {
        [1] = {                                 -- choiceID matched with modal window
            position = Position(1232, 1043, 7),   -- position to teleport per floor
            dingPos = Position(1231, 1043, 7),    -- position of switch  on each floor where ding displays on arrival
            msg = "You have arrived at the ground floor.",
       
        },
        [2] = {
            position = Position(1232, 1043, 6),
            dingPos = Position(1231, 1043, 6),
            msg = "You have arrived at Floor 1.",
        },
        [3] = {
            position = Position(1232, 1043, 5),
            dingPos = Position(1231, 1043, 5),
            msg = "You have arrived at Floor 2.",
        },
        [4] = {
            position = Position(1232, 1043, 4),
            dingPos = Position(1231, 1043, 4),
            msg = "You have arrived at Floor 3.",
        }
    },
}
local function onDing(playerID, position, dingPos)
local player = Player(playerID)
    if not player then
        return
    end
  
    if player:getPosition() ~= Position(position) then
        return
    end -- are you sure you can compare userdatas like that? You might need to compare the x, y and z value instead (At least thats what I do)
    player:say("*ding*", TALKTYPE_MONSTER_SAY, false, dingPos)
end
local function removeWall(wallPos, wallID)
    local item = getTileItemById(wallPos, wallID)
    if not item then
        return
    end
    doRemoveItem(item.uid, 1)
end

function getElevatorT(choiceID)
    return elevatorConf.elevatorT[choiceID]
end
function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    local playerPos = getPlayerPosition(cid)
    local pos1 = {x = playerPos.x+1, y = playerPos.y+1, z = playerPos.z}
    local pos2 = {x = playerPos.x, y = playerPos.y+1, z = playerPos.z}
    local elevatorT = getElevatorT(choiceId)
    local playerID = cid.uid

    if modalWindowId ~= elevatorConf.modalWindow.mwID then
        return
    end
  
    if buttonId == 2 then
        return
    end
    if not elevatorT then
        return print("player was able to choose elevator choice which does not exist: "..choiceId)
    end
    addEvent(doCreateItem, 1, 9486, 1, pos1)
    addEvent(doCreateItem, 500, 9486, 1, pos2)
    addEvent(doPlayerSendTextMessage, 1000, playerID, 18, elevatorT.msg)
    addEvent(doTeleportThing, 1000, playerID, elevatorT.position, true)
    addEvent(onDing, 1010, playerID, elevatorT.position, elevatorT.dingPos)
    addEvent(removeWall, 2000, pos1, 9486)
    addEvent(removeWall, 1500, pos2, 9486)
    return true
end
Did you try if player:getPosition() ~= position then?
 
Give these a try;
Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    tilePositions = { -- elevator positions
        Position(1232, 1043, 7),
        Position(1232, 1043, 6),
        Position(1232, 1043, 5),
        Position(1232, 1043, 4)
    }
}

local function isOnElevator(position)
    for i = 1, #tilePositions do
        if position == tilePositions[i] then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local modalConfig = elevatorConf.modalWindow
    local modal = ModalWindow(modalConfig.mwID, modalConfig.name, modalConfig.title)

    local player = Player(cid)
    if not isOnElevator(player:getPosition()) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You must be inside the elevator.")
        return false
    end

    for choiceID, choiceText in pairs(modalConfig.choiceT) do
        modal:addChoice(choiceID, choiceText)
    end

    for buttonID, buttonText in pairs(modalConfig.buttonT) do
        modal:addButton(buttonID, buttonText)
    end

    return modal:sendToPlayer(player)
end

Lua:
local modalWindow = {
    mwID = 1901,
    name = "Depot Elevator",
    title = "Choose a floor:",
    choiceT = {
        "Ground Floor",
        "Floor 1",
        "Floor 2",
        "Floor 3",
    },
    buttonT = {
        "Select",
        "Cancel",
    }
}
   
local elevatorConfig = {
    [1] = { -- choiceID matched with modal window
        position = Position(1232, 1043, 7), -- position to teleport per floor
        dingPos = Position(1231, 1043, 7), -- position of switch  on each floor where ding displays on arrival
        msg = "You have arrived at the ground floor.",
   
    },
    [2] = {
        position = Position(1232, 1043, 6),
        dingPos = Position(1231, 1043, 6),
        msg = "You have arrived at Floor 1.",
    },
    [3] = {
        position = Position(1232, 1043, 5),
        dingPos = Position(1231, 1043, 5),
        msg = "You have arrived at Floor 2.",
    },
    [4] = {
        position = Position(1232, 1043, 4),
        dingPos = Position(1231, 1043, 4),
        msg = "You have arrived at Floor 3.",
    }
}

local function onDing(playerID, position, dingPos)
    local player = Player(playerID)
    if player and player:getPosition() == position then
        player:say("*ding*", TALKTYPE_MONSTER_SAY, false, dingPos)
    end
end

local function removeWall(wallPosition, wallId)
    local tile = Tile(wallPosition)
    local item = tile and tile:getItemById(wallId)
    if item then
        item:remove()
    end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= modalWindow.mwID then
        return
    end

    if buttonId == 2 then
        return
    end

    local elevatorConfig = elevatorConfig[choiceID]
    if not elevatorConfig then
        return print("player was able to choose elevator choice which does not exist: " .. choiceId)
    end

    local player = Player(cid)
    local playerPos = player:getPosition()
    local positionA = Position(playerPos.x + 1, playerPos.y + 1, playerPos.z)
    local positionB = Position(playerPos.x, playerPos.y + 1, playerPos.z)
    local playerId = player:getId()

    Game.createItem(9486, 1, positionA)
    addEvent(function (positionB) Game.createItem(9486, 1, positionB) end, 500, positionB)
    addEvent(function (playerId, msg) local player = Player(cid) player ~= nil and player:sendTextMessage(MESSAGE_STATUS_WARNING, msg) end, 1000, playerId, elevatorConfig.msg)
    addEvent(function (playerId, position) local player = Player(cid) player ~= nil and player:teleportTo(position) end, 1000 playerId, elevatorConfig.position)
    addEvent(onDing, 1010, playerId, elevatorConfig.position, elevatorConfig.dingPos)
    addEvent(removeWall, 2000, positionA, 9486)
    addEvent(removeWall, 1500, positionB, 9486)

    return true
end
 
Give these a try;
Lua:
local elevatorConf = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choiceT = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        buttonT = {
            "Select",
            "Cancel",
        }
    },
    tilePositions = { -- elevator positions
        Position(1232, 1043, 7),
        Position(1232, 1043, 6),
        Position(1232, 1043, 5),
        Position(1232, 1043, 4)
    }
}

local function isOnElevator(position)
    for i = 1, #tilePositions do
        if position == tilePositions[i] then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local modalConfig = elevatorConf.modalWindow
    local modal = ModalWindow(modalConfig.mwID, modalConfig.name, modalConfig.title)

    local player = Player(cid)
    if not isOnElevator(player:getPosition()) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You must be inside the elevator.")
        return false
    end

    for choiceID, choiceText in pairs(modalConfig.choiceT) do
        modal:addChoice(choiceID, choiceText)
    end

    for buttonID, buttonText in pairs(modalConfig.buttonT) do
        modal:addButton(buttonID, buttonText)
    end

    return modal:sendToPlayer(player)
end

Lua:
local modalWindow = {
    mwID = 1901,
    name = "Depot Elevator",
    title = "Choose a floor:",
    choiceT = {
        "Ground Floor",
        "Floor 1",
        "Floor 2",
        "Floor 3",
    },
    buttonT = {
        "Select",
        "Cancel",
    }
}
  
local elevatorConfig = {
    [1] = { -- choiceID matched with modal window
        position = Position(1232, 1043, 7), -- position to teleport per floor
        dingPos = Position(1231, 1043, 7), -- position of switch  on each floor where ding displays on arrival
        msg = "You have arrived at the ground floor.",
  
    },
    [2] = {
        position = Position(1232, 1043, 6),
        dingPos = Position(1231, 1043, 6),
        msg = "You have arrived at Floor 1.",
    },
    [3] = {
        position = Position(1232, 1043, 5),
        dingPos = Position(1231, 1043, 5),
        msg = "You have arrived at Floor 2.",
    },
    [4] = {
        position = Position(1232, 1043, 4),
        dingPos = Position(1231, 1043, 4),
        msg = "You have arrived at Floor 3.",
    }
}

local function onDing(playerID, position, dingPos)
    local player = Player(playerID)
    if player and player:getPosition() == position then
        player:say("*ding*", TALKTYPE_MONSTER_SAY, false, dingPos)
    end
end

local function removeWall(wallPosition, wallId)
    local tile = Tile(wallPosition)
    local item = tile and tile:getItemById(wallId)
    if item then
        item:remove()
    end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= modalWindow.mwID then
        return
    end

    if buttonId == 2 then
        return
    end

    local elevatorConfig = elevatorConfig[choiceID]
    if not elevatorConfig then
        return print("player was able to choose elevator choice which does not exist: " .. choiceId)
    end

    local player = Player(cid)
    local playerPos = player:getPosition()
    local positionA = Position(playerPos.x + 1, playerPos.y + 1, playerPos.z)
    local positionB = Position(playerPos.x, playerPos.y + 1, playerPos.z)
    local playerId = player:getId()

    Game.createItem(9486, 1, positionA)
    addEvent(function (positionB) Game.createItem(9486, 1, positionB) end, 500, positionB)
    addEvent(function (playerId, msg) local player = Player(cid) player ~= nil and player:sendTextMessage(MESSAGE_STATUS_WARNING, msg) end, 1000, playerId, elevatorConfig.msg)
    addEvent(function (playerId, position) local player = Player(cid) player ~= nil and player:teleportTo(position) end, 1000 playerId, elevatorConfig.position)
    addEvent(onDing, 1010, playerId, elevatorConfig.position, elevatorConfig.dingPos)
    addEvent(removeWall, 2000, positionA, 9486)
    addEvent(removeWall, 1500, positionB, 9486)

    return true
end

Code:
Lua Script Error: [Action Interface]
data/actions/scripts/other/teleport_window.lua:onUse
data/actions/scripts/other/teleport_window.lua:26: attempt to get length of global 'tilePositions' (a nil value)
stack traceback:
        [C]: in function '__len'
        data/actions/scripts/other/teleport_window.lua:26: in function 'isOnElevator'
        data/actions/scripts/other/teleport_window.lua:39: in function <data/actions/scripts/other/teleport_window.lua:34>

Code:
[Warning - Event::checkScript] Can not load script: scripts/teleport_window.lua
data/creaturescripts/scripts/teleport_window.lua:78: '=' expected near '~='

Tried to tweak to get past these, I get that it's probably better to call the function inside the addevent but dont really understand what you're doing when you go from player ~= nil to player:sendText with only an and statement. Tried what @Beto06 suggested and also pulled the onDing from this script into mine and still both are sending text to cid.

Actually now seems to be working well like this:

EDIT: Working but only half the time. :(

Lua:
local function onDing(playerID, position, dingPos)
    local player = Player(playerID)
    if player and player:getPosition() == position then
        player:say("*ding*", TALKTYPE_MONSTER_SAY, nil, false, dingPos)
    end
end

Lua:
addEvent(onDing, 1010, playerID, elevatorT.position, elevatorT.dingPos)
 
Last edited by a moderator:
Actually now seems to be working well like this:

EDIT: Working but only half the time. :(

Lua:
local function onDing(playerID, position, dingPos)
    local player = Player(playerID)
    if player and player:getPosition() == position then
        player:say("*ding*", TALKTYPE_MONSTER_SAY, nil, false, dingPos)
    end
end

Lua:
addEvent(onDing, 1010, playerID, elevatorT.position, elevatorT.dingPos)

The player has to be standing on the correct position, try to below:
Lua:
local function onDing(playerID, position, dingPos)

Add this;
Lua:
print("test")

Then check your console if test is getting printed but ding isn't.

Also; Rules for the Support board
#2
 
Actually now seems to be working well like this:

EDIT: Working but only half the time. :(

Lua:
local function onDing(playerID, position, dingPos)
    local player = Player(playerID)
    if player and player:getPosition() == position then
        player:say("*ding*", TALKTYPE_MONSTER_SAY, nil, false, dingPos)
    end
end

Lua:
addEvent(onDing, 1010, playerID, elevatorT.position, elevatorT.dingPos)
Maybe put onDing first and then teleport player? I think this is the problem
 
About the errors, forgot to change a variable name :p
Lua:
local elevatorConfig = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choice = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        button = {
            "Select",
            "Cancel",
        }
    },
}

local tilePositions = { -- elevator positions
    Position(1232, 1043, 7),
    Position(1232, 1043, 6),
    Position(1232, 1043, 5),
    Position(1232, 1043, 4)
}

local function isOnElevator(position)
    for i = 1, #tilePositions do
        if position == tilePositions[i] then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local modalConfig = elevatorConfig.modalWindow
    local modal = ModalWindow(modalConfig.mwID, modalConfig.name, modalConfig.title)

    local player = Player(cid)
    if not isOnElevator(player:getPosition()) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You must be inside the elevator.")
        return false
    end

    for choiceID, choiceText in pairs(modalConfig.choice) do
        modal:addChoice(choiceID, choiceText)
    end

    for buttonID, buttonText in pairs(modalConfig.button) do
        modal:addButton(buttonID, buttonText)
    end

    return modal:sendToPlayer(player)
end

Edit;
Second script;
Lua:
local modalWindowTargetId = 1901
local elevatorConfig = {
    [1] = { -- choiceID matched with modal window
        position = Position(1232, 1043, 7), -- position to teleport per floor
        dingPos = Position(1231, 1043, 7), -- position of switch  on each floor where ding displays on arrival
        msg = "You have arrived at the ground floor.",
    },
    [2] = {
        position = Position(1232, 1043, 6),
        dingPos = Position(1231, 1043, 6),
        msg = "You have arrived at Floor 1.",
    },
    [3] = {
        position = Position(1232, 1043, 5),
        dingPos = Position(1231, 1043, 5),
        msg = "You have arrived at Floor 2.",
    },
    [4] = {
        position = Position(1232, 1043, 4),
        dingPos = Position(1231, 1043, 4),
        msg = "You have arrived at Floor 3.",
    }
}

local function onDing(playerID, position, dingPos)
    local player = Player(playerID)
    if player and player:getPosition() == position then
        player:say("*ding*", TALKTYPE_MONSTER_SAY, false, dingPos)
    end
end

local function removeWall(wallPosition, wallId)
    local tile = Tile(wallPosition)
    local item = tile and tile:getItemById(wallId)
    if item then
        item:remove()
    end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= modalWindowTargetId then
        return
    end

    if buttonId == 2 then
        return
    end

    local elevatorConfig = elevatorConfig[choiceID]
    if not elevatorConfig then
        return print("player was able to choose elevator choice which does not exist: " .. choiceId)
    end

    local player = Player(cid)
    local playerPos = player:getPosition()
    local positionA = Position(playerPos.x + 1, playerPos.y + 1, playerPos.z)
    local positionB = Position(playerPos.x, playerPos.y + 1, playerPos.z)
    local playerId = player:getId()

    Game.createItem(9486, 1, positionA)
    addEvent(function (positionB) Game.createItem(9486, 1, positionB) end, 500, positionB)
    addEvent(function (playerId, msg) local player = Player(cid) return player ~= nil and player:sendTextMessage(MESSAGE_STATUS_WARNING, msg) or false end, 1000, playerId, elevatorConfig.msg)
    addEvent(function (playerId, position) local player = Player(cid) return player ~= nil and player:teleportTo(position) or false end, 1000 playerId, elevatorConfig.position)
    addEvent(onDing, 1010, playerId, elevatorConfig.position, elevatorConfig.dingPos)
    addEvent(removeWall, 2000, positionA, 9486)
    addEvent(removeWall, 1500, positionB, 9486)

    return true
end
 
Last edited:
Maybe put onDing first and then teleport player? I think this is the problem

If I put it before, it will send the ding to the starting floor level. I think maybe the issue was with the OTClient, switched to custom tibia client and it hasn't showed the bug yet.

About the errors, forgot to change a variable name :p
Lua:
local elevatorConfig = {
    modalWindow = {
        mwID = 1901,
        name = "Depot Elevator",
        title = "Choose a floor:",
        choice = {
            "Ground Floor",
            "Floor 1",
            "Floor 2",
            "Floor 3",
        },
        button = {
            "Select",
            "Cancel",
        }
    },
}

local tilePositions = { -- elevator positions
    Position(1232, 1043, 7),
    Position(1232, 1043, 6),
    Position(1232, 1043, 5),
    Position(1232, 1043, 4)
}

local function isOnElevator(position)
    for i = 1, #tilePositions do
        if position == tilePositions[i] then
            return true
        end
    end
    return false
end

function onUse(cid, item, fromPosition, target, toPosition, isHotkey)
    local modalConfig = elevatorConfig.modalWindow
    local modal = ModalWindow(modalConfig.mwID, modalConfig.name, modalConfig.title)

    local player = Player(cid)
    if not isOnElevator(player:getPosition()) then
        player:sendTextMessage(MESSAGE_STATUS_WARNING, "You must be inside the elevator.")
        return false
    end

    for choiceID, choiceText in pairs(modalConfig.choice) do
        modal:addChoice(choiceID, choiceText)
    end

    for buttonID, buttonText in pairs(modalConfig.button) do
        modal:addButton(buttonID, buttonText)
    end

    return modal:sendToPlayer(player)
end

Edit;
Second script;
Lua:
local modalWindowTargetId = 1901
local elevatorConfig = {
    [1] = { -- choiceID matched with modal window
        position = Position(1232, 1043, 7), -- position to teleport per floor
        dingPos = Position(1231, 1043, 7), -- position of switch  on each floor where ding displays on arrival
        msg = "You have arrived at the ground floor.",
    },
    [2] = {
        position = Position(1232, 1043, 6),
        dingPos = Position(1231, 1043, 6),
        msg = "You have arrived at Floor 1.",
    },
    [3] = {
        position = Position(1232, 1043, 5),
        dingPos = Position(1231, 1043, 5),
        msg = "You have arrived at Floor 2.",
    },
    [4] = {
        position = Position(1232, 1043, 4),
        dingPos = Position(1231, 1043, 4),
        msg = "You have arrived at Floor 3.",
    }
}

local function onDing(playerID, position, dingPos)
    local player = Player(playerID)
    if player and player:getPosition() == position then
        player:say("*ding*", TALKTYPE_MONSTER_SAY, false, dingPos)
    end
end

local function removeWall(wallPosition, wallId)
    local tile = Tile(wallPosition)
    local item = tile and tile:getItemById(wallId)
    if item then
        item:remove()
    end
end

function onModalWindow(cid, modalWindowId, buttonId, choiceId, item, position, pos, toPosition, fromPosition, itemEx)
    if modalWindowId ~= modalWindowTargetId then
        return
    end

    if buttonId == 2 then
        return
    end

    local elevatorConfig = elevatorConfig[choiceID]
    if not elevatorConfig then
        return print("player was able to choose elevator choice which does not exist: " .. choiceId)
    end

    local player = Player(cid)
    local playerPos = player:getPosition()
    local positionA = Position(playerPos.x + 1, playerPos.y + 1, playerPos.z)
    local positionB = Position(playerPos.x, playerPos.y + 1, playerPos.z)
    local playerId = player:getId()

    Game.createItem(9486, 1, positionA)
    addEvent(function (positionB) Game.createItem(9486, 1, positionB) end, 500, positionB)
    addEvent(function (playerId, msg) local player = Player(cid) return player ~= nil and player:sendTextMessage(MESSAGE_STATUS_WARNING, msg) or false end, 1000, playerId, elevatorConfig.msg)
    addEvent(function (playerId, position) local player = Player(cid) return player ~= nil and player:teleportTo(position) or false end, 1000 playerId, elevatorConfig.position)
    addEvent(onDing, 1010, playerId, elevatorConfig.position, elevatorConfig.dingPos)
    addEvent(removeWall, 2000, positionA, 9486)
    addEvent(removeWall, 1500, positionB, 9486)

    return true
end

Can't get past this now >.<

Nothing happening and the print message "player was able to choose elevator choice which does not exist: 3" is displaying.
 
Back
Top