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

TFS 1.X+ Boss room TFS 1.2X

luanldt

New Member
Joined
Sep 17, 2024
Messages
5
Reaction score
0
GitHub
luanldt
I have a problem with this boss room script on my server, I tried to make it work but I can't, I found two problems:
First: players are not sent away after their time is up, the function to kick players is not working
Second: When all players dies, boss don't dissapear and when new players use lever one new boss is summoned. I would like the script to remove the boss when all players die or when time runs out and all players are sent out.
If any hero without a cape can help me, it will be a great help
 

Attachments

replace file with onUse function
LUA:
local config = {
    actionId = 5900, -- ActionID da alavanca
    bossName = "Dorufin [BOSS]",
    bossPosition = Position(515, 963, 7), -- Posição onde o boss aparecerá
    bossArea = {
        fromPos = = { 511, 960, 7 }, -- Canto superior esquerdo da sala
        toPos = { 520, 966, 7 }, -- Canto inferior direito da sala
        entrancePos = Position(519, 961, 7), -- Posição onde os jogadores serão teleportados
        exitPosition = Position(508, 971, 7) -- Posição para onde os jogadores serão expulsos se demorar demais
    },
    participantsPos = {
        Position(510, 974, 7), -- Jogador 1, o que deve puxar a alavanca
        Position(511, 974, 7), -- Jogador 2
        Position(512, 974, 7), -- Jogador 3
        Position(513, 974, 7)  -- Jogador 4
    },
    attempts = {
        level = 50, -- Nível necessário para entrar
        storage = 20004    , -- Storage do tempo de espera
        seconds = 72000 -- 20 horas
    },
    kickParticipantAfterSeconds = 60 * 1, -- 15 minutos
    leverIds = {1945, 1946} -- Alavanca
}

local function getSpectators()
    local spectators = {}
    for x = config.bossArea.fromPos[1], config.bossArea.toPos[1] do
        for y = config.bossArea.fromPos[2], config.bossArea.toPos[2] do
            local tile = Tile(Position(x, y, config.bossArea.fromPos[3]))
            if tile then
                local creature = tile:getTopCreature()
                if creature and creature:isPlayer() then
                    table.insert(spectators, creature)
                end
            end
        end
    end
    return spectators
end

function onUse(player, item, fromPosition, target, toPosition)
    local participants = {}

    -- Verifica os participantes nas posições definidas
    for _, pos in pairs(config.participantsPos) do
        local tile = Tile(pos)
        if tile then
            local participant = tile:getTopCreature()
            if participant and participant:isPlayer() then
                if participant:getLevel() < config.attempts.level then
                    player:sendCancelMessage("O jogador " .. participant:getName() .. " não possui o nível necessário.")
                    return true
                elseif participant:getStorageValue(config.attempts.storage) > os.time() then
                    player:sendCancelMessage("O jogador " .. participant:getName() .. " precisa esperar para entrar novamente.")
                    return true
                end
                table.insert(participants, participant)
            end
        end
    end

    if #participants == 0 then
        player:sendCancelMessage("Você precisa de pelo menos um participante.")
        return true
    end

    -- Verifica se a sala está ocupada
    if #getSpectators() > 0 then
        player:sendCancelMessage("A sala já está ocupada. Tente mais tarde.")
        return true
    end

    -- Remove monstros restantes da sala
    for _, monster in pairs(getSpectators()) do
        if not monster:isPlayer() then
            monster:remove()
        end
    end

    -- Cria o boss
    local boss = Game.createMonster(config.bossName, config.bossPosition)
    if not boss then
        player:sendCancelMessage("Não foi possível criar o boss.")
        return true
    end

    boss:registerEvent("bossDeath") -- Evento de morte do boss

    -- Teleporta participantes e registra o tempo de espera
    for _, participant in pairs(participants) do
        participant:teleportTo(config.bossArea.entrancePos)
        participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.seconds)
    end

    -- Alterna a alavanca
    item:transform(item:getId() == config.leverIds[1] and config.leverIds[2] or config.leverIds[1])
    return true
end

and replace with onThink file
LUA:
local config = {
    bossArea = {
        fromPos = { 511, 960, 7 }, -- Canto superior esquerdo da sala
        toPos = { 520, 966, 7 }, -- Canto inferior direito da sala
        exitPosition = Position(508, 971, 7) -- Para onde os jogadores serão teleportados
    }
}

function onThink(interval)
    local spectators = {}
    for x = config.bossArea.fromPos[1], config.bossArea.toPos[1] do
        for y = config.bossArea.fromPos[2], config.bossArea.toPos[2] do
            local tile = Tile(Position(x, y, config.bossArea.fromPos[3]))
            if tile then
                local creature = tile:getTopCreature()
                if creature and creature:isPlayer() then
                    table.insert(spectators, creature)
                end
            end
        end
    end

    for _, spectator in pairs(spectators) do
        spectator:teleportTo(config.bossArea.exitPosition)
        spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Você foi removido da sala por demorar muito tempo.")
    end
    return true
end

Move local function "getSpectators()" to lib's as normal function, then file with event "onDeath" can read this part.
LUA:
for _, spectator in pairs(getSpectators(true)) do

but since you dont have any error that function is missing, monster that died have not registered this event onDeath anyway - so this u have to fix too.
 
Last edited:
@Dakos I don't know if it's too much to ask, probably yes. Could you help me fix it? Even though I understand what you meant, I'm not able to add the changes, anything I'll pay you too if you want.
 
Back
Top