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

RevScripts add cooldown

bolachapanco

Member
Joined
Aug 5, 2023
Messages
30
Reaction score
5
Location
Brazil
How could I add a cooldown to this script and show a message about how much time is left before I can use the item again

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 teleportCube = Action()
function teleportCube.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local window = ModalWindow {
        title = "Teleport System",
        message = "Locations"
    }
    for i, info in pairs(config) do
        window:addChoice(string.format("%s", info.name), function (player, button, choice)
            if button.name ~= "Select" then
                return true
            end
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
            player:teleportTo(info.position)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            return true
        end)
    end
    window:addButton("Select")
    window:addButton("Close")
    window:setDefaultEnterButton(0)
    window:setDefaultEscapeButton(1)
    window:sendToPlayer(player)
    return true
end
teleportCube:id(31633)
teleportCube:register()
 
Lua:
local exhaustedTime = 30 -- seconds
local tmp = {}
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 teleportCube = Action()
function teleportCube.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerGuid = player:getGuid()
    local time = tmp[playerGuid]
    if time and time > os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must wait " .. (time - os.time()) .. " seconds before teleporting.")
        return true
    end
    local window = ModalWindow {
        title = "Teleport System",
        message = "Locations"
    }
    for i, info in pairs(config) do
        window:addChoice(string.format("%s", info.name), function (player, button, choice)
            if button.name ~= "Select" then
                return true
            end
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
            player:teleportTo(info.position)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            return true
        end)
    end
    window:addButton("Select")
    window:addButton("Close")
    window:setDefaultEnterButton(0)
    window:setDefaultEscapeButton(1)
    window:sendToPlayer(player)
    tmp[playerGuid] = os.time() + exhaustedTime
    return true
end
teleportCube:id(31633)
teleportCube:register()
 
Last edited:
Lua:
local storage = 9002
if player:getStorageValue(storage) > 0 then
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You can use it again in: '..player:getStorageValue(storage) - os.time()..' seconds.')
    return true
end
player:setStorageValue(storage, os.time() + 60)
 
Last edited:
Lua:
local exhaustedTime = 30 -- seconds
local tmp = {}
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 teleportCube = Action()
function teleportCube.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local playerGuid = player:getGuid()
    local time = tmp[playerGuid]
    if time and time > os.time() then
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You must wait " .. (time - os.time()) .. " seconds before teleporting.")
        return true
    end
    local window = ModalWindow {
        title = "Teleport System",
        message = "Locations"
    }
    for i, info in pairs(config) do
        window:addChoice(string.format("%s", info.name), function (player, button, choice)
            if button.name ~= "Select" then
                return true
            end
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
            player:teleportTo(info.position)
            player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
            return true
        end)
    end
    window:addButton("Select")
    window:addButton("Close")
    window:setDefaultEnterButton(0)
    window:setDefaultEscapeButton(1)
    window:sendToPlayer(player)
    tmp[playerGuid] = os.time() + exhaustedTime
    return true
end
teleportCube:aid(31633)
teleportCube:register()

Without a result, the item becomes unusable
Post automatically merged:

Lua:
local storage = 9002
if player:getStorageValue(storage) > 0 then
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You can use it again in: '..player.getStorageValue(storage) - os.time()..' seconds.')
    return true
end
player:setStorageValue(storage, os.time() + 60)

where to add the code?
 
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 teleportCooldown = 5000  -- Cooldown in milliseconds (5 seconds)
local lastTeleportTimes = {}

local teleportCube = Action()
function teleportCube.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local now = os.time() * 1000
    
    if not lastTeleportTimes[player:getId()] or now - lastTeleportTimes[player:getId()] >= teleportCooldown then
        local window = ModalWindow {
            title = "Teleport System",
            message = "Locations"
        }
        for i, info in pairs(config) do
            window:addChoice(string.format("%s", info.name), function (player, button, choice)
                if button.name ~= "Select" then
                    return true
                end
                player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You were teleported to " .. info.name)
                player:teleportTo(info.position)
                player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                lastTeleportTimes[player:getId()] = now
                return true
            end)
        end
        window:addButton("Select")
        window:addButton("Close")
        window:setDefaultEnterButton(0)
        window:setDefaultEscapeButton(1)
        window:sendToPlayer(player)
        return true
    else
        local remainingCooldown = math.ceil((teleportCooldown - (now - lastTeleportTimes[player:getId()])) / 1000)
        player:sendTextMessage(MESSAGE_STATUS_SMALL, "You must wait " .. remainingCooldown .. " seconds before teleporting again.")
        return true
    end
end

teleportCube:id(31633)
teleportCube:register()
 
Lua:
local storage = 9002
if player:getStorageValue(storage) > 0 then
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You can use it again in: '..player:getStorageValue(storage) - os.time()..' seconds.')
    return true
end
player:setStorageValue(storage, os.time() + 60)
I am getting this bug adding such script into my teleport item.
23:53 The supreme cube is in cooldown: -334 seconds.
Like it is higher than 0.
 
I am getting this bug adding such script into my teleport item.
23:53 The supreme cube is in cooldown: -334 seconds.
Like it is higher than 0.
This one is much better and simpler, causing less headache.

Lua:
local storage = 9002
local cooldownTime = 60

if player:getStorageValue(storage) > os.time() then
    local remainingTime = player:getStorageValue(storage) - os.time()
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You can use it again in: ' .. remainingTime .. ' seconds.')
    return true
end

player:setStorageValue(storage, os.time() + cooldownTime)
 
This one is much better and simpler, causing less headache.

Lua:
local storage = 9002
local cooldownTime = 60

if player:getStorageValue(storage) > os.time() then
    local remainingTime = player:getStorageValue(storage) - os.time()
    player:sendTextMessage(MESSAGE_INFO_DESCR, 'You can use it again in: ' .. remainingTime .. ' seconds.')
    return true
end

player:setStorageValue(storage, os.time() + cooldownTime)
Thanks it is working just fine!
bcus the script I posted is wrong
use @Mateus Robeerto one
Done, thanks for your help!
 
Back
Top