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

RevScripts BossRoom Help... TFS 1.5

Kabo Flow

Member
Joined
May 17, 2020
Messages
84
Reaction score
7
Location
Mexico
Twitch
KaboFlow18
This is a revscript of a bossroom, but with an error since when the first boss is born, after killing it and wanting to enter again, the boss is no longer born and the room remains empty.

I managed to add the anti-mc... but now I can't make the boss hatch after they kill him and want to do the bossroom again...


LUA:
local config = {
    -- Configuración de la sala del jefe
    bossName = "Svoren the Mad",
    bossPosition = Position(61, 2706, 7),
    teleportPosition = Position(67, 2706, 7),
    roomCenterPosition = Position(62, 2706, 7),
    roomDimensions = {x = 10, y = 10, z = 7}, -- Dimensiones de la sala del jefe
    cooldownMinutes = 600, -- Tiempo de espera de 10 horas (600 minutos)
    kickMinutes = 15,
    kickPosition = Position(991, 1210, 7),
    requiredLevel = 100,
    storage = 1001,
    countdownDuration = 30, -- Duración de la cuenta regresiva en segundos
    countdownPosition = Position(62, 2440, 7), -- Posición para el texto flotante de la cuenta regresiva
    textColor = 180, -- Color del texto flotante
    maxPlayers = 10, -- Límite máximo de jugadores en la sala
    antiMCStorage = 1002, -- Almacenamiento para IP anti-multi-client
    bossStorage = 1003, -- Almacenamiento para verificar si el jefe ya está creado
    countdownStorage = 1004, -- Almacenamiento para verificar si la cuenta regresiva está activa
    bossCleanupDelay = 5 * 60 * 1000 -- Tiempo en milisegundos para eliminar el jefe si no hay jugadores en la sala (5 minutos)
}

-- Función para verificar si hay jugadores en la sala del jefe
local function hasPlayersInRoom()
    local playersInRoom = false
    for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, config.roomDimensions.x / 2, config.roomDimensions.y / 2, config.roomDimensions.z)) do
        if spectator:isPlayer() then
            playersInRoom = true
            break
        end
    end
    return playersInRoom
end

-- Función para verificar si el jefe está en la sala del jefe
local function isBossInRoom()
    local minPos = Position(config.bossPosition.x - config.roomDimensions.x / 2, config.bossPosition.y - config.roomDimensions.y / 2, config.bossPosition.z)
    local maxPos = Position(config.bossPosition.x + config.roomDimensions.x / 2, config.bossPosition.y + config.roomDimensions.y / 2, config.bossPosition.z)

    local monsters = Game.getSpectators(minPos, maxPos, false, false, 1, 1, 1, 1)
    for _, monster in pairs(monsters) do
        if monster:isMonster() and monster:getName() == config.bossName then
            return true
        end
    end
    return false
end

-- Función para eliminar el jefe si no hay jugadores en la sala
local function cleanupBoss()
    if not hasPlayersInRoom() then
        local minPos = Position(config.bossPosition.x - config.roomDimensions.x / 2, config.bossPosition.y - config.roomDimensions.y / 2, config.bossPosition.z)
        local maxPos = Position(config.bossPosition.x + config.roomDimensions.x / 2, config.bossPosition.y + config.roomDimensions.y / 2, config.bossPosition.z)
        
        local monsters = Game.getSpectators(minPos, maxPos, false, false, 1, 1, 1, 1)
        for _, monster in pairs(monsters) do
            if monster:isMonster() and monster:getName() == config.bossName then
                monster:remove()
                print("El jefe se eliminó por no tener ningún jugador presente.") -- Mensaje de depuración
                Game.setStorageValue(config.bossStorage, -1) -- Actualizar el almacenamiento para indicar que no hay jefe
                break
            end
        end
    end
end

-- Función para iniciar el proceso de limpieza del jefe si no hay jugadores
local function scheduleBossCleanup()
    addEvent(function()
        cleanupBoss()
    end, config.bossCleanupDelay)
end

-- Función para verificar el tiempo de espera
local function checkCooldown(player)
    local lastTime = player:getStorageValue(config.storage)
    if lastTime <= 0 then
        return true, 0 -- No hay tiempo de espera 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 iniciar la cuenta regresiva con efecto visual
local function startCountdown(position)
    local countdownTime = config.countdownDuration
    local function countdown()
        if countdownTime <= 0 then
            print("Cuenta regresiva finalizada.") -- Mensaje de depuración
            -- Limpiar el almacenamiento de la cuenta regresiva
            Game.setStorageValue(config.countdownStorage, -1)
            return
        end

        -- Mostrar el texto animado en la posición especificada
        Game.sendAnimatedText(tostring(countdownTime), position, config.textColor)

        countdownTime = countdownTime - 1
        addEvent(countdown, 1000) -- Repetir cada segundo
    end
    countdown()
end

-- Función para verificar el número de jugadores en la sala del jefe
local function checkPlayerCount()
    local count = 0
    for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, config.roomDimensions.x / 2, config.roomDimensions.y / 2, config.roomDimensions.z)) do
        if spectator:isPlayer() then
            count = count + 1
        end
    end
    return count
end

-- Función para verificar y manejar el Anti-Multi-Client
local function checkAntiMC(player)
    local playerIP = player:getIp()
    local playersInRoom = {}

    -- Buscar jugadores en la sala y registrar sus IPs
    for _, spectator in pairs(Game.getSpectators(config.roomCenterPosition, false, false, config.roomDimensions.x / 2, config.roomDimensions.y / 2, config.roomDimensions.z)) do
        if spectator:isPlayer() then
            local ip = spectator:getIp()
            playersInRoom[ip] = true
        end
    end

    if playersInRoom[playerIP] then
        -- Si la IP del jugador ya está en la sala, bloquear la entrada
        return false
    else
        -- Permitir la entrada y registrar la IP
        return true
    end
end

-- Evento al entrar en la sala del jefe
local BossRoomArena = MoveEvent()

function BossRoomArena.onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()
    if not player then
        return true
    end

    -- Verificar el Anti-Multi-Client
    if not checkAntiMC(player) then
        print("Anti-MC activado: Jugador con la misma IP ya está en la sala.") -- Mensaje de depuración
        player:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_POFF) -- Efecto de acceso denegado
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Ya hay otro jugador con la misma IP en la sala del jefe.")
        return true
    end

    -- Verificar el nivel del jugador
    if player:getLevel() < config.requiredLevel then
        print("Jugador de nivel insuficiente.") -- Mensaje de depuración
        player:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_POFF) -- Efecto de acceso denegado
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Necesitas tener al menos el nivel " .. config.requiredLevel .. " para ingresar a esta área.")
        return true
    end

    -- Verificar el número de jugadores en la sala del jefe
    if checkPlayerCount() >= config.maxPlayers then
        print("Sala del jefe llena.") -- Mensaje de depuración
        player:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_POFF) -- Efecto de sala llena
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "La sala del jefe está llena. Por favor, intenta nuevamente más tarde.")
        return true
    end

    -- Verificar si el jefe ya está presente en la sala
    if not isBossInRoom() then
        -- Si no hay jefe en la sala, crear uno nuevo y actualizar el almacenamiento
        local bossStorageValue = Game.getStorageValue(config.bossStorage)
        if bossStorageValue == -1 or bossStorageValue == nil then
            local boss = Game.createMonster(config.bossName, config.bossPosition)
            if boss then
                print("Jefe creado exitosamente.") -- Mensaje de depuración
                -- Establecer el tiempo de almacenamiento del jefe activo
                Game.setStorageValue(config.bossStorage, os.time())
                -- Programar limpieza del jefe si no hay jugadores
                scheduleBossCleanup()
            else
                print("Error al crear el jefe.") -- Mensaje de depuración
            end
        else
            print("Jefe ya presente en la sala.") -- Mensaje de depuración
        end
    end

    -- Verificar si la cuenta regresiva está activa
    local countdownStorageValue = Game.getStorageValue(config.countdownStorage)
    if countdownStorageValue == -1 or countdownStorageValue == nil then
        -- Iniciar la cuenta regresiva solo si no está activa
        print("Iniciando cuenta regresiva de 30 segundos.") -- Mensaje de depuración
        startCountdown(config.countdownPosition)
        -- Establecer el tiempo de almacenamiento de la cuenta regresiva activa
        Game.setStorageValue(config.countdownStorage, os.time())
    end

    -- Verificar el tiempo de espera
    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)"
        
        print("Tiempo de espera restante: " .. timeMessage) -- Mensaje de depuración
        player:teleportTo(fromPosition, true)
        fromPosition:sendMagicEffect(CONST_ME_POFF) -- Efecto de acceso denegado
        player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Debes esperar " .. timeMessage .. " antes de ingresar nuevamente a la sala del jefe.")
        return true
    end

    -- Teletransportar al jugador a la sala del jefe y actualizar el tiempo de espera
    player:teleportTo(config.teleportPosition)
    player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Tienes 15 minutos para derrotar al jefe.")
    player:setStorageValue(config.storage, os.time()) -- Actualizar el tiempo de espera al tiempo actual

    -- Configurar el evento para echar al jugador después de 15 minutos
    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)
            print("Jugador expulsado después de 15 minutos.") -- Mensaje de depuración
        end
    end, config.kickMinutes * 1000 * 60)
end

-- Configurar el MoveEvent
TeleportBossArena = BossRoomArena
TeleportBossArena:type("stepin")
TeleportBossArena:uid(18188) -- Asegúrate de que el UID del ítem sea correcto
TeleportBossArena:register()
 
You dont spawn the boss in the script… You need to spawn it by the code when player enters, not add the boss through editor.
 
Back
Top