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

Lua Need some help to merge unlockable locations script with my TP scroll!

calveron

Bravemansworld
Joined
Feb 5, 2008
Messages
165
Reaction score
13
Location
Sweden
So basicly what I want is to merge my TP scroll (Scroll that currently sends you to temple of any town) into something like this: https://otland.net/threads/tfs-1-1-...ablo-3-teleport-great-for-rpg-servers.230015/ This is how my TP scroll looks like now:
Tp_book.png

What I want is that when you pick Edron for example, it opens a new window where you can see your unlocked locations. (Temple, cyclopolis, dragon cave etc.) I've already implented the catacomb teleporter I provided link to, to my server and I added the movements to unlock cyclopolis so far.
How would I change so that when I pick Edron it sends the modalwindow for the "catacombs" to the player?
I tried a few things and I did manage to make it work so that the new window pops up, but there were no choises and sometimes not even any buttons.

Here's my current TP scroll scripts:
Code:
local towns = {
    "Thais",
    "Carlin",
    "Venore",
    "Ab'dendriel",
    "Liberty Bay",
    "Port Hope",
    "Ankrahmun",
    "Darashia",
    "Kazordoon",
    "Edron",
    "Svargrond",
    "Yalahar",
    "Farmine",
    "Gray Beach",
    "Roshamuul",
    "Trainers"
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT) then
        player:sendCancelMessage("PZ locked!")
        player:getPosition():sendMagicEffect(CONST_ME_POFF)
        return true
    end

    local modalWindow = ModalWindow(2, "Destination", "Make your choice:")
    for i = 1, #towns do
        modalWindow:addChoice(i, i .. ". " .. towns[i])
    end

    modalWindow:addButton(1, 'Open')
    modalWindow:setDefaultEnterButton(1)
    modalWindow:addButton(2, 'Exit')
    modalWindow:setDefaultEscapeButton(2)

    modalWindow:sendToPlayer(player)
    player:registerEvent("Destination")
    return true
end
Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)

if modalWindowId == 2 then


local player = Player(cid)

local thais = {x = 32369, y = 32241, z = 7}
local carlin = {x = 32360, y = 31782, z = 7}
local venore = {x = 32957, y = 32076, z = 7}
local ab = {x = 32732, y = 31634, z = 7}
local liberty = {x = 32317, y = 32826, z = 7}
local port = {x = 32594, y = 32745, z = 7}
local ankrahmun = {x = 33194, y = 32853, z = 7}
local darashia = {x = 33213, y = 32454, z = 1}
local kazordoon = {x = 32649, y = 31925, z = 11}
local edron = {x = 33217, y = 31814, z = 8}
local svargrond = {x = 32212, y = 31132, z = 7}
local yalahar = {x = 32787, y = 31276, z = 7}
local farmine = {x = 33023, y = 31521, z = 11}
local gray = {x = 33447, y = 31323, z = 9}
local roshamuul = {x = 33513, y = 32363, z = 6}
local trainers = {x = 32682, y = 32484, z = 7}

if buttonId == 2 then
return false
else
    if choiceId == 1 then
player:teleportTo(thais)
return true
    end
    if choiceId == 2 then
player:teleportTo(carlin)
return true
    end
    if choiceId == 3 then
player:teleportTo(venore)
return true
    end
    if choiceId == 4 then
player:teleportTo(ab)
return true
    end
    if choiceId == 5 then
player:teleportTo(liberty)
return true
    end
    if choiceId == 6 then
player:teleportTo(port)
return true
    end
    if choiceId == 7 then
player:teleportTo(ankrahmun)
return true
    end
    if choiceId == 8 then
player:teleportTo(darashia)
return true
    end
    if choiceId == 9 then
player:teleportTo(kazordoon)
return true
    end
    if choiceId == 10 then
player:teleportTo(edron)
return true
    end
    if choiceId == 11 then
player:teleportTo(svargrond)
return true
    end
    if choiceId == 12 then
player:teleportTo(yalahar)
return true
    end
    if choiceId == 13 then
player:teleportTo(farmine)
return true
    end
    if choiceId == 14 then
player:teleportTo(gray)
return true
    end
    if choiceId == 15 then
player:teleportTo(roshamuul)
return true
    end
    if choiceId == 16 then
player:teleportTo(trainers)
return true
    end
 
    end
end
end
Any help would be awesome!
Using tfs 1.1
 
Last edited:
easy peasy

Instead of doing this:
Code:
 if choiceId == 1 then
player:teleportTo(thais)
return true
    end
send another Modal window.
Code:
local modalWindow = ModalWindow(3, "Destination", "Make your choice:")
    for i = 1, #towns do
        modalWindow:addChoice(i, i .. ". " .. towns[i])
    end

    modalWindow:addButton(1, 'Open')
    modalWindow:setDefaultEnterButton(1)
    modalWindow:addButton(2, 'Exit')
    modalWindow:setDefaultEscapeButton(2)

    modalWindow:sendToPlayer(player)
    player:registerEvent("REAL Destination")
    return true
And on that modal window you give the options to teleport to locations.
And why don't you use loop? in ModalWindow function?
Code:
local locations = {thais, carlin, happyTown, etc}

for x=1, #locatations do
if choiceId == x then
player:teleportTo(locations[x])
return true
    end
 
Sounds like a good idea, and thanks for helping me out! If you have any chance to help me some more that would be so awesome.
Im trying to get it to work, but it ends up only working for my GM char, and no other char at all. I really dont understand why.
And one more thing, I want it to only show the location the character has unlocked, that the player has the storage for. For Cyclopolis in edron for example, the storage is 6661.
If you would have the energy to help me build this code for me I would be extremely happy.
 
i dont have energy to help you today, i will shove my KeyChain Script into your face. Maybe it helps you, because it is doing the same thing basically as you want to learn. just different variables.
showKeys.lua
Code:
function onSay(cid, words, param)
    keyChainModalWindow(cid)
end

function keyChainModalWindow(cid)
    local player = Player(cid)
    local playerOwnedKeys = {}
    local keys = {}

    keys[2] = "Bone key : 1001"
    keys[3] = "another key"
    keys[4] = "another another key"
  
    window = ModalWindow(2000, "Key-chain", "Choose a key for more information")
    player:registerEvent("keyChain")
    window:addButton(100, "Choose")
    window:addButton(101, "Close")
  
    for k, v in pairs(keys) do
        if (player:getStorageValue(k + 10000) > -1) then
            window:addChoice(k, v)
        end
    end
  
    window:setDefaultEnterButton(100)
    window:setDefaultEscapeButton(101)
    window:sendToPlayer(player)
end

KeyChain.lua
Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
    local player = Player(cid)

    player:unregisterEvent("keyChain")
    local keys = {}
    keys[2] = {10002, "Bone key : ActionId 1001", "Key from skeleton", "Key for starting area"}
    keys[3] = {10003, "another key", "key from someone", "key for sth"}
    keys[4] = {10004, "another another key", "key from someone I think", "key for sth I think idk"}

    if modalWindowId == 2000 then
        if buttonId == 100 then
            for k, v in pairs(keys) do
                if choiceId == k then
                    keyInfoModalWindow(cid, v)
                end
            end
        end
    end
end

function keyInfoModalWindow(cid, keyInfo)
    local player = Player(cid)
    window = ModalWindow(2001, keyInfo[2], "Information about this key")
    player:registerEvent("keyInfo")
    window:addButton(100, "Back")
  
    window:addChoice(1, keyInfo[3])
    if player:getStorageValue(keyInfo[1]) == 1 then
        window:addChoice(2, keyInfo[4])
    end
  
    window:setDefaultEnterButton(100)
    window:sendToPlayer(player)
end

keyInfo.lua
Code:
function onModalWindow(cid, modalWindowId, buttonId, choiceId)
    local player = Player(cid)
    player:unregisterEvent("keyInfo")

    if modalWindowId == 2001 then
        if buttonId == 100 then
            keyChainModalWindow(cid)
        end
    end
end
 
Back
Top