Hello, I am new to the software.
My idea is to create a portal that allows the player to travel to different dungeons depending on their level.
When the player interacts with the portal, a menu will be displayed showing all the available dungeons, if the player has the appropriate level they will be able to travel to it. If you do not have the appropriate level, the dungeon appears blocked and must be unlocked by reaching the necessary level and paying with coins obtained from the loot.
Below I detail my code for this idea. I have the following error: Error on line 1: "begin" expected after function argument list
function onInteract()
-- Obtener el jugador y la instancia del objeto interactuado
local player = getPlayer()
local instance = getInteractedInstance()
-- Verificar si el objeto interactuado es el portal
if instance.name == "Portal" then
-- Obtener el nivel y la cantidad de monedas del jugador
local playerLevel = player:getLevel()
local playerCoins = player:getCoins()
-- Crear una tabla que mapee las mazmorras disponibles con sus niveles correspondientes y el costo de desbloqueo
local dungeons = {
["Mazmorra 1"] = {level = 1, cost = 0},
["Mazmorra 2"] = {level = 3, cost = 100},
["Mazmorra 3"] = {level = 5, cost = 200}
}
-- Crear una lista de opciones para el menú que incluya las mazmorras disponibles y sus requisitos de desbloqueo
local menuOptions = {}
for dungeon, info in pairs(dungeons) do
if playerLevel >= info.level then
table.insert(menuOptions, dungeon)
else
table.insert(menuOptions, dungeon .. " (Requiere nivel " .. info.level .. ")")
end
end
-- Mostrar menú de selección de mazmorras
local selected = player:menu(menuOptions, "Selecciona una mazmorra:")
-- Verificar la selección del jugador y transportarlo a la mazmorra correspondiente si está desbloqueada
if selected ~= nil then
local dungeon = selected:gsub(" ", "_"):lower() -- Convertir el nombre de la mazmorra a formato de instancia (sin espacios y en minúsculas)
local dungeonInfo = dungeons[selected]
if playerLevel >= dungeonInfo.level then
player:teleport(dungeon) -- Teletransportar al jugador a la mazmorra seleccionada
else
player:message("No tienes el nivel suficiente para acceder a esta mazmorra.") -- Mostrar mensaje de error si la mazmorra está bloqueada
end
end
end
end