• 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!
  • New resources must be posted under Resources tab. A discussion thread will be created automatically, you can't open threads manually anymore.
[Canary v.3.1.2+] Teleport Cube + Cooldown + Battle + Price

[Canary v.3.1.2+] Teleport Cube + Cooldown + Battle + Price

RonieNeubauer

New Member
Joined
May 6, 2024
Messages
2
Reaction score
4
GitHub
RonieNeubauer
RonieNeubauer submitted a new resource:

[Canary v.31.2+] Teleport Cube + Cooldown + Battle + Price - Supreme cube with battle checks, cooldown and price per use.

View attachment 84596View attachment 84597View attachment 84599View attachment 84600


Lua:
local supremeCube = Action()

local config = {
    price = 50000,
    storage = 9007,
    cooldown = 60,
    towns = {
        { name = "Ab'Dendriel", teleport = Position(32732 , 31634 , 7) },
        { name = "Ankrahmun", teleport = Position(33194 , 32853 , 8) },
        { name = "Carlin", teleport = Position(32360 , 31782 , 7) },
        {...

Read more about this resource...
 
Seems super cool but whee do I add it? Tried a few locations as supremecube.lua but i might be doing something wrong
 
You can put in the canary folder:
data\scripts\custom\supremecube.lua

When using item 31633, it will open the teleportation options.
Seems super cool but whee do I add it? Tried a few locations as supremecube.lua but i might be doing something wrong
 
Lua:
local supremeCube = Action()

local config = {
    cooldown = 60,
    towns = {
        { name = "Ab'Dendriel", teleport = Position(32732, 31634, 7), price = 50000, storage = 9007, level = 10 },
        { name = "Ankrahmun", teleport = Position(33194, 32853, 8), price = 60000, storage = 9008, level = 20 },
        { name = "Carlin", teleport = Position(32360, 31782, 7), price = 45000, storage = 9009, level = 15 },
    }
}

local function supremeCubeMessage(player, effect, message)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, message)
    player:getPosition():sendMagicEffect(effect)
end

function supremeCube.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local inPz = player:getTile():hasFlag(TILESTATE_PROTECTIONZONE)
    local inFight = player:isPzLocked() or player:getCondition(CONDITION_INFIGHT, CONDITIONID_DEFAULT)

    if not inPz and inFight then
        supremeCubeMessage(player, CONST_ME_POFF, "You can't use this when you're in a fight.")
        return false
    end

    local window = ModalWindow({
        title = "Supreme Cube",
        message = "Select a City.",
    })

    for _, town in pairs(config.towns) do
        if town.name then
            window:addChoice(town.name, function(player, button, choice)
                if button.name == "Select" then
                    if player:getLevel() < town.level then
                        supremeCubeMessage(player, CONST_ME_POFF, "You need to be at least level " .. town.level .. " to travel to " .. town.name .. ".")
                        return true
                    end

                    if player:getMoney() + player:getBankBalance() < town.price then
                        supremeCubeMessage(player, CONST_ME_POFF, "You don't have enough money to travel to " .. town.name .. ".")
                        return true
                    end

                    if player:getStorageValue(town.storage) > os.time() then
                        local remainingTime = player:getStorageValue(town.storage) - os.time()
                        supremeCubeMessage(player, CONST_ME_POFF, "You can use it again in: " .. remainingTime .. " seconds.")
                        return true
                    end

                    player:teleportTo(town.teleport, true)
                    player:removeMoneyBank(town.price)
                    supremeCubeMessage(player, CONST_ME_TELEPORT, "Welcome to " .. town.name)
                    player:setStorageValue(town.storage, os.time() + config.cooldown)
                end
                return true
            end)
        end
    end

    window:addButton("Select")
    window:addButton("Close")
    window:setDefaultEnterButton(0)
    window:setDefaultEscapeButton(1)
    window:sendToPlayer(player)

    return true
end

supremeCube:id(31633)
supremeCube:register()
 
hi, its 1.3 tfs otclientv8 on 10.98
So, you need to add it to the lib and CreatureScript for it to work and display a normal modal window.
 
So, you need to add it to the lib and CreatureScript for it to work and display a normal modal window.
wow thanks it works <3
Post automatically merged:

So, you need to add it to the lib and CreatureScript for it to work and display a normal modal window.
got another problem XD it doesnt wanna teleport me because its custom server i change possition press select and not doing anything
 
Last edited:
When i press submit nothing happens looks like i still miss something does anyone know? Thank you a lot for help
 
When i press submit nothing happens looks like i still miss something does anyone know? Thank you a lot for help
Want a tip? You shouldn't be grabbing scripts/systems from Canary for your TFS 1.3 1098. Of course, it doesn't work; sometimes they did. TFS and Canary have some functions that are totally different. I can't find the link I made for someone here on Otland, and I had already saved the script on my PC for a long time. I found it here and tested it; it works well for my TFS 1.4.3 1098. Here, it works for you.

If you don't want the item to be removed (consumable), just find this line 'item:remove(1)' and delete or comment it out.

Lua:
local teleportConfig = {
    locations = {
        { name="Mystic Pex City", position = Position(1029, 996, 7), price = 100 },
        { name="Thais", position = Position(1029, 996, 7), price = 200 },
    },
    storage = 12345,
    cooldown = 60,
    itemId = 6558
}

local teleportEvent = Action()

function teleportEvent.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() ~= teleportConfig.itemId then
        return false
    end
    
    player:registerEvent("TeleportModalWindowLocations")
    
    local teleportWindow = ModalWindow(1, "Select a Location")
    for i, location in ipairs(teleportConfig.locations) do
        teleportWindow:addChoice(i, location.name)
    end
    teleportWindow:addButton(1, "Select")
    teleportWindow:addButton(2, "Cancel")
    teleportWindow:setDefaultEnterButton(1)
    teleportWindow:setDefaultEscapeButton(2)
    teleportWindow:sendToPlayer(player)
    
   -- Consumable Item Remover
    item:remove(1)
    
    return true
end

teleportEvent:id(teleportConfig.itemId)
teleportEvent:register()

local modalEvent = CreatureEvent("TeleportModalWindowLocations")

function modalEvent.onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("TeleportModalWindowLocations")
    
    if buttonId == 1 then
        local selectedLocation = teleportConfig.locations[choiceId]
        if selectedLocation then
            if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
                return player:ProcessTeleport(selectedLocation.position, selectedLocation.price, selectedLocation.name)
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only teleport within a protection zone.")
            end
        end
    end
    
    return true
end

modalEvent:type("modalwindow")
modalEvent:register()

function Player.ProcessTeleport(self, position, price, locationName)
    if not self or not position then return false end

    local currentTime = os.time()
    local lastTeleport = self:getStorageValue(teleportConfig.storage) or -1

    local timeRemaining = teleportConfig.cooldown - (currentTime - lastTeleport)
    if timeRemaining > 0 then
        local minutes = math.floor(timeRemaining / 60)
        local seconds = math.floor(timeRemaining % 60)
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You must wait " .. minutes .. " minutes and " .. seconds .. " seconds before teleporting again.")
        return false
    end

    if not self:removeTotalMoney(price) then
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You do not have enough money to teleport.")
        return false
    end

    if self:getCondition(CONDITION_INFIGHT) then
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot teleport while in combat.")
        return false
    end

    local inPz = self:getTile():hasFlag(TILESTATE_PROTECTIONZONE)
    if not inPz then
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only teleport within a protection zone.")
        return false
    end

    self:teleportTo(position)
    self:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    self:setStorageValue(teleportConfig.storage, currentTime)
    self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully teleported to " .. locationName .. ".")
    
    return true
end
 
Want a tip? You shouldn't be grabbing scripts/systems from Canary for your TFS 1.3 1098. Of course, it doesn't work; sometimes they did. TFS and Canary have some functions that are totally different. I can't find the link I made for someone here on Otland, and I had already saved the script on my PC for a long time. I found it here and tested it; it works well for my TFS 1.4.3 1098. Here, it works for you.

If you don't want the item to be removed (consumable), just find this line 'item:remove(1)' and delete or comment it out.

Lua:
local teleportConfig = {
    locations = {
        { name="Mystic Pex City", position = Position(1029, 996, 7), price = 100 },
        { name="Thais", position = Position(1029, 996, 7), price = 200 },
    },
    storage = 12345,
    cooldown = 60,
    itemId = 6558
}

local teleportEvent = Action()

function teleportEvent.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item:getId() ~= teleportConfig.itemId then
        return false
    end
   
    player:registerEvent("TeleportModalWindowLocations")
   
    local teleportWindow = ModalWindow(1, "Select a Location")
    for i, location in ipairs(teleportConfig.locations) do
        teleportWindow:addChoice(i, location.name)
    end
    teleportWindow:addButton(1, "Select")
    teleportWindow:addButton(2, "Cancel")
    teleportWindow:setDefaultEnterButton(1)
    teleportWindow:setDefaultEscapeButton(2)
    teleportWindow:sendToPlayer(player)
   
   -- Consumable Item Remover
    item:remove(1)
   
    return true
end

teleportEvent:id(teleportConfig.itemId)
teleportEvent:register()

local modalEvent = CreatureEvent("TeleportModalWindowLocations")

function modalEvent.onModalWindow(player, modalWindowId, buttonId, choiceId)
    player:unregisterEvent("TeleportModalWindowLocations")
   
    if buttonId == 1 then
        local selectedLocation = teleportConfig.locations[choiceId]
        if selectedLocation then
            if player:getTile():hasFlag(TILESTATE_PROTECTIONZONE) then
                return player:ProcessTeleport(selectedLocation.position, selectedLocation.price, selectedLocation.name)
            else
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only teleport within a protection zone.")
            end
        end
    end
   
    return true
end

modalEvent:type("modalwindow")
modalEvent:register()

function Player.ProcessTeleport(self, position, price, locationName)
    if not self or not position then return false end

    local currentTime = os.time()
    local lastTeleport = self:getStorageValue(teleportConfig.storage) or -1

    local timeRemaining = teleportConfig.cooldown - (currentTime - lastTeleport)
    if timeRemaining > 0 then
        local minutes = math.floor(timeRemaining / 60)
        local seconds = math.floor(timeRemaining % 60)
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You must wait " .. minutes .. " minutes and " .. seconds .. " seconds before teleporting again.")
        return false
    end

    if not self:removeTotalMoney(price) then
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You do not have enough money to teleport.")
        return false
    end

    if self:getCondition(CONDITION_INFIGHT) then
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You cannot teleport while in combat.")
        return false
    end

    local inPz = self:getTile():hasFlag(TILESTATE_PROTECTIONZONE)
    if not inPz then
        self:sendTextMessage(MESSAGE_STATUS_SMALL, "You can only teleport within a protection zone.")
        return false
    end

    self:teleportTo(position)
    self:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    self:setStorageValue(teleportConfig.storage, currentTime)
    self:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You have successfully teleported to " .. locationName .. ".")
   
    return true
end
love it now everything works <3
 
Back
Top