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

Add collect money and cooldown

bolachapanco

Member
Joined
Aug 5, 2023
Messages
30
Reaction score
5
Location
Brazil
How do I put a collection of money when using and add a cooldown in this script?

Lua:
local config = {
    { name="Ab'Dendriel", position = Position(32732, 31634, 7) },
    { name="Ankrahmun", position = Position(33194, 32853, 8) },
    { name="Carlin", position = Position(32360, 31782, 7) },
    { name="Darashia", position = Position(33213, 32454, 1) },
    { name="Edron", position = Position(33217, 31814, 7) },
    { name="Kazordoon", position = Position(32649, 31925, 11) },
    { name="Liberty Bay", position = Position(32317, 32826, 7) },
    { name="Port Hope", position = Position(32595, 32744, 7) },
    { name="Thais", position = Position(32369, 32241, 7) },
    { name="Venore", position = Position(32957, 32076, 7) }
}

local itemTeleport = Action()

function itemTeleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local menu = ModalWindow{
        title = "Teleport Ring",
        message = "Locations"
    }

    for i, info in pairs(config) do
        menu:addChoice(string.format("%s", info.name), function (player, button, choice)
            if button.name ~= "Select" then
                return
            end

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
            player:teleportTo(info.position)
        end)
    end

    menu:addButton("Select")
    menu:addButton("Close")
    menu:sendToPlayer(player)
    return false
end

itemTeleport:id(44064)
itemTeleport:register()
 
checking not testing

Lua:
local config = {
    { name = "Ab'Dendriel", position = Position(32732, 31634, 7) },
    { name = "Ankrahmun", position = Position(33194, 32853, 8) },
    { name = "Carlin", position = Position(32360, 31782, 7) },
    { name = "Darashia", position = Position(33213, 32454, 1) },
    { name = "Edron", position = Position(33217, 31814, 7) },
    { name = "Kazordoon", position = Position(32649, 31925, 11) },
    { name = "Liberty Bay", position = Position(32317, 32826, 7) },
    { name = "Port Hope", position = Position(32595, 32744, 7) },
    { name = "Thais", position = Position(32369, 32241, 7) },
    { name = "Venore", position = Position(32957, 32076, 7) }
}

local itemTeleport = Action()

-- Cooldown settings (in seconds)
local cooldownTime = 60 -- Change this value to set the cooldown time
local cooldownStorage = 12345 -- Change this to a unique storage value

function itemTeleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local lastTeleportTime = player:getStorageValue(cooldownStorage)
    local currentTime = os.time()

    if lastTeleportTime > 0 and currentTime - lastTeleportTime < cooldownTime then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must wait before teleporting again.")
        return false
    end

    local menu = ModalWindow{
        title = "Teleport Ring",
        message = "Locations"
    }

    for i, info in pairs(config) do
        menu:addChoice(string.format("%s", info.name), function(player, button, choice)
            if button.name ~= "Select" then
                return
            end

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
            player:teleportTo(info.position)
            player:setStorageValue(cooldownStorage, currentTime) -- Set the cooldown storage
        end)
    end

    menu:addButton("Select")
    menu:addButton("Close")
    menu:sendToPlayer(player)
    return false
end

itemTeleport:id(44064)
itemTeleport:register()
 
I added a cooldown and set it to remove money when teleporting players
Lua:
local config = {
    { name = "Ab'Dendriel", position = Position(32732, 31634, 7), cooldown = 60, cost = 100 },
    { name = "Ankrahmun", position = Position(33194, 32853, 8), cooldown = 120, cost = 150 },
    { name = "Carlin", position = Position(32360, 31782, 7), cooldown = 90, cost = 120 },
    { name = "Darashia", position = Position(33213, 32454, 1), cooldown = 120, cost = 180 },
    { name = "Edron", position = Position(33217, 31814, 7), cooldown = 120, cost = 160 },
    { name = "Kazordoon", position = Position(32649, 31925, 11), cooldown = 150, cost = 200 },
    { name = "Liberty Bay", position = Position(32317, 32826, 7), cooldown = 90, cost = 130 },
    { name = "Port Hope", position = Position(32595, 32744, 7), cooldown = 90, cost = 140 },
    { name = "Thais", position = Position(32369, 32241, 7), cooldown = 90, cost = 110 },
    { name = "Venore", position = Position(32957, 32076, 7), cooldown = 90, cost = 120 }
}

local itemTeleport = Action()

function itemTeleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local menu = ModalWindow{
        title = "Teleport Ring",
        message = "Locations"
    }

    local currentTime = os.time()
    local lastTeleportTime = player:getStorageValue("LastTeleportTime")

    for i, info in ipairs(config) do
        local timeSinceLastTeleport = currentTime - lastTeleportTime
        local canTeleport = lastTeleportTime <= 0 or timeSinceLastTeleport >= info.cooldown
        local canAfford = player:getMoney() >= info.cost

        local buttonText = info.name
        if not canTeleport then
            buttonText = buttonText .. " (Cooldown)"
        elseif not canAfford then
            buttonText = buttonText .. " (Not enough money)"
        end

        menu:addChoice(buttonText, function(player, button, choice)
            if button.name ~= "Select" then
                return
            end

            if canTeleport and canAfford then
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
                player:teleportTo(info.position)
                player:setStorageValue("LastTeleportTime", currentTime)
                player:removeMoney(info.cost)
            elseif not canTeleport then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must wait before teleporting again.")
            elseif not canAfford then
                player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enough money.")
            end
        end)
    end

    menu:addButton("Select")
    menu:addButton("Close")
    menu:sendToPlayer(player)
    return false
end

itemTeleport:id(44064)
itemTeleport:register()
 
Last edited:
I added a cooldown and set it to remove money when teleporting players
Lua:
local config = {
    { name = "Ab'Dendriel", position = Position(32732, 31634, 7), cooldown = 60, cost = 100 },
    { name = "Ankrahmun", position = Position(33194, 32853, 8), cooldown = 120, cost = 150 },
     { name = "Carlin", position = Position(32360, 31782, 7), cooldown = 90, cost = 120 },
    { name = "Darashia", position = Position(33213, 32454, 1), cooldown = 120, cost = 180 },
    { name = "Edron", position = Position(33217, 31814, 7), cooldown = 120, cost = 160 },
    { name = "Kazordoon", position = Position(32649, 31925, 11), cooldown = 150, cost = 200 },
    { name = "Liberty Bay", position = Position(32317, 32826, 7), cooldown = 90, cost = 130 },
    { name = "Port Hope", position = Position(32595, 32744, 7), cooldown = 90, cost = 140 },
    { name = "Thais", position = Position(32369, 32241, 7), cooldown = 90, cost = 110 },
    { name = "Venore", position = Position(32957, 32076, 7), cooldown = 90, cost = 120 }
}

local itemTeleport = Action()

function itemTeleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local destination = config[item.uid]

    if not destination then
        return false
    end

    local lastTeleportTime = player:getStorageValue(destination.name .. "Cooldown")
    local currentTime = os.time()

    if lastTeleportTime > 0 and currentTime - lastTeleportTime < destination.cooldown then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must wait before teleporting again.")
        return false
    end

    local cost = destination.cost

    if player:removeMoney(cost) then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. destination.name)
        player:teleportTo(destination.position)
        player:setStorageValue(destination.name .. "Cooldown", currentTime)
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You don't have enough money.")
    end

    return false
end

itemTeleport:uid(44064)
itemTeleport:register()
but you removed the modal window 🤔
 
but you removed the modal window 🤔
Now I see it, sorry... I've updated my post now.... 🤣
Post automatically merged:

How do I put a collection of money when using and add a cooldown in this script?

Lua:
local config = {
    { name="Ab'Dendriel", position = Position(32732, 31634, 7) },
    { name="Ankrahmun", position = Position(33194, 32853, 8) },
    { name="Carlin", position = Position(32360, 31782, 7) },
    { name="Darashia", position = Position(33213, 32454, 1) },
    { name="Edron", position = Position(33217, 31814, 7) },
    { name="Kazordoon", position = Position(32649, 31925, 11) },
    { name="Liberty Bay", position = Position(32317, 32826, 7) },
    { name="Port Hope", position = Position(32595, 32744, 7) },
    { name="Thais", position = Position(32369, 32241, 7) },
    { name="Venore", position = Position(32957, 32076, 7) }
}

local itemTeleport = Action()

function itemTeleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local menu = ModalWindow{
        title = "Teleport Ring",
        message = "Locations"
    }

    for i, info in pairs(config) do
        menu:addChoice(string.format("%s", info.name), function (player, button, choice)
            if button.name ~= "Select" then
                return
            end

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
            player:teleportTo(info.position)
        end)
    end

    menu:addButton("Select")
    menu:addButton("Close")
    menu:sendToPlayer(player)
    return false
end

itemTeleport:id(44064)
itemTeleport:register()
I went to test this script and it didn't work, there was no teleportation.


checking not testing

Lua:
local config = {
    { name = "Ab'Dendriel", position = Position(32732, 31634, 7) },
    { name = "Ankrahmun", position = Position(33194, 32853, 8) },
    { name = "Carlin", position = Position(32360, 31782, 7) },
    { name = "Darashia", position = Position(33213, 32454, 1) },
    { name = "Edron", position = Position(33217, 31814, 7) },
    { name = "Kazordoon", position = Position(32649, 31925, 11) },
    { name = "Liberty Bay", position = Position(32317, 32826, 7) },
    { name = "Port Hope", position = Position(32595, 32744, 7) },
    { name = "Thais", position = Position(32369, 32241, 7) },
    { name = "Venore", position = Position(32957, 32076, 7) }
}

local itemTeleport = Action()

-- Cooldown settings (in seconds)
local cooldownTime = 60 -- Change this value to set the cooldown time
local cooldownStorage = 12345 -- Change this to a unique storage value

function itemTeleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local lastTeleportTime = player:getStorageValue(cooldownStorage)
    local currentTime = os.time()

    if lastTeleportTime > 0 and currentTime - lastTeleportTime < cooldownTime then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must wait before teleporting again.")
        return false
    end

    local menu = ModalWindow{
        title = "Teleport Ring",
        message = "Locations"
    }

    for i, info in pairs(config) do
        menu:addChoice(string.format("%s", info.name), function(player, button, choice)
            if button.name ~= "Select" then
                return
            end

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
            player:teleportTo(info.position)
            player:setStorageValue(cooldownStorage, currentTime) -- Set the cooldown storage
        end)
    end

    menu:addButton("Select")
    menu:addButton("Close")
    menu:sendToPlayer(player)
    return false
end

itemTeleport:id(44064)
itemTeleport:register()
I went to test this script and it didn't work, just like mine doesn't work either. It may be that some functions are missing for the teleport, as the 'OK' window appears, but the teleport does not occur
 
Last edited:
Replace not Testing

Lua:
local teleportLocations = {
    { name = "Ab'Dendriel", position = Position(32732, 31634, 7) },
    { name = "Ankrahmun", position = Position(33194, 32853, 8) },
    { name = "Carlin", position = Position(32360, 31782, 7) },
    { name = "Darashia", position = Position(33213, 32454, 1) },
    { name = "Edron", position = Position(33217, 31814, 7) },
    { name = "Kazordoon", position = Position(32649, 31925, 11) },
    { name = "Liberty Bay", position = Position(32317, 32826, 7) },
    { name = "Port Hope", position = Position(32595, 32744, 7) },
    { name = "Thais", position = Position(32369, 32241, 7) },
    { name = "Venore", position = Position(32957, 32076, 7) }
}

local cooldownTime = 60 -- Cooldown time in seconds
local cooldownStorage = 12345 -- Unique storage value for cooldown

local itemTeleport = Action()

function itemTeleport.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local lastTeleportTime = player:getStorageValue(cooldownStorage)
    local currentTime = os.time()

    if lastTeleportTime > 0 and currentTime - lastTeleportTime < cooldownTime then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You must wait before teleporting again.")
        return false
    end

    local menu = ModalWindow{
        title = "Teleport Ring",
        message = "Select a location:"
    }

    for i, location in ipairs(teleportLocations) do
        menu:addChoice(location.name, function(player, button, choice)
            if button.name ~= "Select" then
                return
            end

            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. location.name)
            player:teleportTo(location.position)
            player:setStorageValue(cooldownStorage, currentTime) -- Set the cooldown storage
        end)
    end

    menu:addButton("Select")
    menu:addButton("Close")
    menu:sendToPlayer(player)
    return false
end

itemTeleport:id(44064)
itemTeleport:register()
 
Last edited:
Back
Top