local config = {
-- Configuración para la sala del boss
bossName = "Dragon",
bossPosition = Position(61, 2706, 7),
teleportPosition = Position(67, 2706, 7),
roomCenterPosition = Position(62, 2706, 7),
cooldownMinutes = 600, -- Cooldown de 10 horas (600 minutos)
kickMinutes = 15,
kickPosition = Position(991, 1210, 7),
playerPosition = Position(61, 2696, 7),
requiredLevel = 100,
storage = 2002,
countdownDuration = 30, -- Duración del conteo regresivo en segundos
countdownPosition = Position(1000, 1210, 7) -- Nueva posición para el conteo regresivo
}
-- Función para verificar si el boss ya está en la sala
local function isBossPresent()
for _, monster in pairs(Game.getSpectators(config.bossPosition, false, false, 1, 1, 1, 1)) do
if monster:isMonster() and monster:getName() == config.bossName then
return true
end
end
return false
end
-- Función para verificar el tiempo de cooldown
local function checkCooldown(player)
local lastTime = player:getStorageValue(config.storage)
if lastTime <= 0 then
return true, 0 -- No hay tiempo de cooldown establecido
end
local currentTime = os.time()
local cooldownExpires = lastTime + config.cooldownMinutes * 60
local timeRemaining = cooldownExpires - currentTime
if timeRemaining < 0 then
timeRemaining = 0
end
return timeRemaining == 0, timeRemaining
end
-- Función para el conteo regresivo con efecto visual
local function startCountdown(position)
local countdownTime = config.countdownDuration
local function countdown()
if countdownTime <= 0 then
return
end
-- Mostrar el texto animado con el tiempo restante en la posición específica
Game.sendAnimatedText(position, tostring(countdownTime), TEXTCOLOR_RED)
countdownTime = countdownTime - 1
addEvent(countdown, 1000) -- Repetir cada segundo
end
countdown()
end
-- Evento de teletransportación al entrar en la sala del boss
local BossRoomArena = MoveEvent()
function BossRoomArena.onStepIn(creature, item, position, fromPosition)
local player = creature:getPlayer()
if not player then
return true
end
-- Verificar el nivel del jugador
if player:getLevel() < config.requiredLevel then
player:teleportTo(fromPosition, true)
fromPosition:sendMagicEffect(241) -- Efecto de acceso denegado
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Necesitas ser al menos nivel " .. config.requiredLevel .. " para entrar en esta área.")
return true
end
-- Verificar si hay otros jugadores en la sala del boss
for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, 5, 5, 5, 5)) do
if spectator:isPlayer() then
player:teleportTo(fromPosition, true)
fromPosition:sendMagicEffect(241) -- Efecto de sala ocupada
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "La sala del boss está ocupada actualmente. Por favor, intenta de nuevo más tarde.")
return true
end
end
-- Verificar si el boss ya está presente en la sala
if isBossPresent() then
player:teleportTo(fromPosition, true)
fromPosition:sendMagicEffect(241) -- Efecto de sala ocupada
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Ya hay un boss presente en la sala. Por favor, intenta de nuevo más tarde.")
return true
end
-- Verificar el tiempo de cooldown
local isCooldownExpired, timeRemaining = checkCooldown(player)
if not isCooldownExpired then
local hoursRemaining = math.floor(timeRemaining / 3600) -- Horas restantes
local minutesRemaining = math.ceil((timeRemaining % 3600) / 60) -- Minutos restantes
local timeMessage = hoursRemaining > 0 and hoursRemaining .. " hora(s) y " .. minutesRemaining .. " minuto(s)" or minutesRemaining .. " minuto(s)"
-- Corregir el mensaje para mostrar solo el tiempo restante
player:teleportTo(fromPosition, true)
fromPosition:sendMagicEffect(241) -- Efecto de acceso denegado
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Debes esperar " .. timeMessage .. " antes de volver a entrar en la sala del boss.")
return true
end
-- Crear el boss y teleportar al jugador
local boss = Game.createMonster(config.bossName, config.bossPosition)
if boss then boss:registerEvent("CancelKickEvent") end
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:teleportTo(config.teleportPosition)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Tienes 15 minutos para derrotar al boss.")
player:setStorageValue(config.storage, os.time()) -- Actualizar el tiempo de cooldown al tiempo actual
-- Configurar el evento para kickear al jugador después de 15 minutos
local kickEventId = addEvent(function ()
if player:getPosition() == config.teleportPosition then
player:teleportTo(config.kickPosition, false)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "¡Se acabó el tiempo! Has sido enviado de vuelta al templo.")
config.kickPosition:sendMagicEffect(CONST_ME_TELEPORT)
end
end, config.kickMinutes * 1000 * 60)
-- Iniciar el conteo regresivo de 30 segundos en la nueva posición
startCountdown(config.countdownPosition)
end
-- Configurar el MoveEvent
local TeleportBossArena = BossRoomArena
TeleportBossArena:type("stepin")
TeleportBossArena:uid(18188) -- Asegúrate de que el UID del item es correcto
TeleportBossArena:register()