-- Config
local tplist = {
[27431] = {name = "", positions = {{x = 31832, y = 32377, z = 8}}, subareas = {}},
[27432] = {name = "", positions = {{x = 31894, y = 32434, z = 7}}, subareas = {}}
}
local firstid = 27431
local lastid = 27432
-- Config End
local teleports = MoveEvent()
function teleports.onStepIn(player, item, position, fromPosition)
if not player:isPlayer() then
return false
end
local tp = tplist[item.actionid]
local quantity = table.getn(tp.positions)
player:registerEvent("Teleport_Modal_Window")
local title = "Teleport"
local message = "List of ".. tp.name .." Spawns"
local window = ModalWindow(item.actionid, title, message)
window:addButton(100, "Go")
window:addButton(101, "Cancel")
for i = 1, quantity do
if tp.subareas[i] == nil then
window:addChoice(i,"".. tp.name .." ".. i .."")
else
window:addChoice(i,"".. tp.subareas[i] .."")
end
end
window:setDefaultEnterButton(100)
window:setDefaultEscapeButton(101)
if tp and quantity < 2 then
player:unregisterEvent("Teleport_Modal_Window")
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:teleportTo(tp.positions[1])
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
else
window:sendToPlayer(player)
end
return true
end
for j = firstid, lastid do
teleports:aid(j)
end
teleports:type("stepin")
teleports:register()
local modalTp = CreatureEvent("Teleport_Modal_Window")
modalTp:type("modalwindow")
function modalTp.onModalWindow(player, modalWindowId, buttonId, choiceId)
player:unregisterEvent("Teleport_Modal_Window")
if modalWindowId >= firstid and modalWindowId <= lastid then
if buttonId == 100 then
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:teleportTo(tplist[modalWindowId].positions[choiceId])
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
if tplist[modalWindowId].subareas[choiceId] == nil then
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Teleported to '.. tplist[modalWindowId].name ..' '.. choiceId ..'.')
else
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'Teleported to '.. tplist[modalWindowId].subareas[choiceId] ..'.')
end
end
end
return true
end
modalTp:register()