XiolenceOT
New Member
- Joined
- Jun 5, 2023
- Messages
- 42
- Reaction score
- 4
Is using an item such as the Nautical map with a unique ID that opens a menu, even if its a shop menu (if I have to)
to select teleport destinations possible? I keep getting "function even onUse not found" but it's clearly in the script, or is this only possible through the source files?
to select teleport destinations possible? I keep getting "function even onUse not found" but it's clearly in the script, or is this only possible through the source files?
Lua:
local TELEPORT_ITEM_ID = 10225
local TELEPORT_DESTINATIONS = {
[1] = {name = "Destination 1", position = {x = 50, y = 100, z = 7}}, -- Adjust coordinates accordingly
[2] = {name = "Destination 2", position = {x = 75, y = 150, z = 7}},
[3] = {name = "Destination 3", position = {x = 120, y = 180, z = 7}}
}
function onUse(cid, item, fromPosition, itemEx, toPosition)
if item.itemid == TELEPORT_ITEM_ID then
showMenu(cid)
return true
end
return false
end
function showMenu(cid)
local player = Player(cid)
local menuText = "Teleport Menu:\n"
for option, destination in ipairs(TELEPORT_DESTINATIONS) do
menuText = menuText .. option .. ". " .. destination.name .. "\n"
end
player:setActionId(5000) -- Set a temporary action ID to capture menu selection
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, menuText)
end
function onAction(cid, action, itemEx, toPosition, isHotkey)
if action == "5000" and itemEx.itemid == TELEPORT_ITEM_ID then
local choice = tonumber(itemEx.actionid)
if choice and TELEPORT_DESTINATIONS[choice] then
local destination = TELEPORT_DESTINATIONS[choice].position
local player = Player(cid)
player:teleportTo(destination)
player:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
player:say("You have been teleported to " .. TELEPORT_DESTINATIONS[choice].name .. ".", TALKTYPE_MONSTER_SAY)
player:setActionId(0) -- Reset action ID to close the menu
end
end
return true
end