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

Stone City Teleport. ModalWindow and only use with premium Tfs 1.4.2

No permission to download
data/scripts/teleporttown.lua


LUA:
local teleportItemId = 26398

local config = {

    modalWindow = {
        id = 1001,
        title = "Stone Teleport",
        message = "Select a city to teleport:",
        eventText = "ModalWindow_TeleportCities",
        buttons = {
            {text = "Teleport", defaultEnterButton = true},
            {text = "Cancel", defaultEscapeButton = true},
        }
    },
    cities = {
        {name = "City1", pos = Position(1283, 615, 5)},  -- Example positions, replace with actual temple positions
        {name = "City2", pos = Position(960, 1058, 7)},
        {name = "City3", pos = Position(1703, 950, 8)},
        {name = "City4", pos = Position(1669, 1279, 6)},
        {name = "City5", pos = Position(439, 520, 7)},
    }
}

-- End configuration --

local function createCityTeleportWindow(playerId)
    local player = Player(playerId)
    if not player then
        return
    end

    if not player:isPremium() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need to be a premium player to use this stone.")
        return
    end

    if player:hasEvent(CREATURE_EVENT_MODALWINDOW, config.modalWindow.eventText) then
        player:unregisterEvent(config.modalWindow.eventText)
    end
    player:registerEvent(config.modalWindow.eventText)
 
    local modalWindow = ModalWindow(config.modalWindow.id, config.modalWindow.title, config.modalWindow.message)
 
    for id, button in ipairs(config.modalWindow.buttons) do
        modalWindow:addButton(id, button.text)
        if button.defaultEscapeButton then
            modalWindow:setDefaultEscapeButton(id)
        elseif button.defaultEnterButton then
            modalWindow:setDefaultEnterButton(id)
        end
    end  

    for id, city in ipairs(config.cities) do
        modalWindow:addChoice(id, city.name)
    end
 
    modalWindow:hasPriority()
    modalWindow:sendToPlayer(player)
end

local action = Action()

function action.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() == teleportItemId then
        createCityTeleportWindow(player:getId())
    end
    return true
end

action:id(teleportItemId)
action:register()

local creatureevent = CreatureEvent(config.modalWindow.eventText)

function creatureevent.onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent(config.modalWindow.eventText)
 
    if modalWindowId == config.modalWindow.id then
        local buttonChoice = config.modalWindow.buttons[buttonId].text
   
        if buttonChoice == "Teleport" then
            local city = config.cities[choiceId]
            if city then
                player:teleportTo(city.pos)
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You have been teleported to " .. city.name .. "!")
            else
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Invalid city selection.")
            end
        end
    end
end

creatureevent:register()

ex 1.webp


ex 2.webp



If you dont want this script only play for premium, need delete this part of script

LUA:
    if not player:isPremium() then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You need to be a premium player to use this stone.")
        return
    end


I'm not a programmer, but I can pretend to be one. I have my favorite tool if you know how to use it well, Chat gpt... it doesn't make the best scripts but they work for you. If you have any questions, ask me and I'll ask her for you!

I hope I can help people with the same level of knowledge as me. It is appreciated to see these scripts and to return the favor with the same love!

be happy, regards!
Author
MyksaND
Downloads
5
Views
493
First release
Last update

Ratings

0.00 star(s) 0 ratings
Back
Top