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

Teleport Ring

I am actually tring this script, but cannot figure out why it is not working properly...
If someone can point out what is wrong with it, that would be a great help!

Code:
Data/Scripts/Actions
Lua:
local destinations = {
        [1] = {name = "Thais", ID = 8},
        [2] = {name = "Carlin", ID = 6}
    }

local supreme_Cube = Action()

function supreme_Cube.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    player:registerEvent("modalCube")
 
    local title = "Supreme Cube is being used"
    local message = "Select your destination:"
 
    local window = ModalWindow(1001, title, message)
    if player:getItemCount(31633) >= 1 then
        window:addButton(100, "GO!")
        window:setDefaultEnterButton(100)
    else
        window:setDefaultEnterButton(101)
    end
    window:addButton(101, "Cancel")
    window:setDefaultEscapeButton(101)
 
    for i = 1, #destinations do
        local o = destinations[i].name
        local town = Town(destinations[i].ID):getTemplePosition()
        window:addChoice(i, o)
    end
    
    if destinations.id == 1 then
    player:getPosition():sendMagicEffect(201)   
    elseif destinations.id == 2 then
    player:getPosition():sendMagicEffect(201)
        return false
    end
    

    --player:teleportTo(town)

    window:sendToPlayer(player)
    return true
end

supreme_Cube:id(31633)
supreme_Cube:register()
Pic:
1694706154717.png
The problem is that it is not showing any error, I can choose a destination, but nothing is happening. Right now I have not configured the teleport action, however I am using the animation to track if the scripts works, however still haven't got the animation to appear after selecting a destination. Teleport is working and animation is fine, because I already tested those without the conditionals, but that way it happened even before choosing.
 
You are missing response from modalWindow

Lua:
local creaturescript = CreatureEvent("modalCube")
function creaturescript.onModalWindow(player, modalWindowId, buttonId, choiceId)
    
    if modalWindowId ~= 1001 then --- we dont wanna doubled modal windows, so there is check if its equal for cube
        return false
    end
    
    player:unregisterEvent("modalCube")
    
    if buttonId == 101 then  --- 101 in this case its a cancel button, so we return
        return false
    end
 
    local townTable = destinations[choiceId]
    if not townTable then
        print("[Cube Teleporter] - Something is wrong.") --- probably will never happen, but who knows
        return false
    end
 
    local name = townTable.name
    local id = townTable.id
 
    local town = Town(id)
    if not town then
       print("[Cube Teleporter] - Town with this ID doesnt exsists.") -- just a check for correct town id
       return false
    end
 
    local pos = town:getTemplePosition()
 
    player:sendTextMessage(MESSAGE_INFO_DESCR, "You have been teleported to " .. name .. ".")
    player:teleportTo(pos)
    player:sendMagicEffect(CONST_ME_TELEPORT)
    return true
end

(put it bellow your code)
ps. full freestyle, untested
ps2 oh it was old topic, but oh well, lets hope it will help to someone
 
Back
Top