• 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.3] Small Boss Room

Am having an issue with this part of the code, for some reason when players has made the boss once and gets the storage so they need to wait the time before trying again. But am not getting that "The player %s must wait a while before being able to enter again." Its jumping straight down to "You need atleast 4 participants"

I used the same 4 characters that made the first boss. Anyone has any idea?


Lua:
            if participant:getStorageValue(config.attempts.storage) >= os.time() then
                player:sendCancelMessage(string.format("The player %s must wait a while before being able to enter again.", participant:getName()))
            elseif participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(string.format("The player %s is not level %d.", participant:getName(), config.attempts.level))
            else
                participants[#participants +1] = participant
            end
        end
    end

    if #participants == 0 then
        player:sendCancelMessage("You need atleast 4 participant.")
        return true
    elseif not allowedAnyParticipantsCount and #participants ~= #config.participantsPos then
        player:sendCancelMessage("You need all participants.")
        return true
    end
if you want to force an exact amount using allowedAnyParticipantsCount = false you can do what @Xikini suggested.
but if in another script you use allowedAnyParticipantsCount = true adding those return true will break the logic.
 
if you want to force an exact amount using allowedAnyParticipantsCount = false you can do what @Xikini suggested.
but if in another script you use allowedAnyParticipantsCount = true adding those return true will break the logic.
Hi, I have a problem, I don't know if it's an error due to my misconfiguration or maybe something is wrong with the server... when I use it in 1 bossrom it works normally but when I want to use it in another when I finish killing the boss, the portal doesn't appear. could it be happening? Thank you very much in advance if you can answer this I use tfs 1.3 otv8

by the way it does not throw me errors in console
 
Hi, I have a problem, I don't know if it's an error due to my misconfiguration or maybe something is wrong with the server... when I use it in 1 bossrom it works normally but when I want to use it in another when I finish killing the boss, the portal doesn't appear. could it be happening? Thank you very much in advance if you can answer this I use tfs 1.3 otv8

by the way it does not throw me errors in console
Did u change the names on events in the script? Further down there is register , u must have different register name in each script
 
Hey nice script, but I don't understand what "FROM POS" "TO POS" is, like what is the purpose of those lines? no offense Im just curious.
 
The config is pretty self explanatory, bossArea -> (fromPos, toPos)
In other words, its to parse all creatures inside the area

EDIT -> by parsing the area you can do other stuff aswell <like randomly spawning the boss in a valid position> but on this specific script, its only used for that purpose
 
Last edited:
Well,

I used it and I can't seem to figure out where the mistake are, so basically here is what I'm facing.
  • I can't seem to make the lever function every 1 hour
  • if the boss kills the player, the boss will remain in the room and not disappear.
*if another team uses the lever with a boss inside it will create a second boss.
*Some players are getting a message "You need at least one participant" even if they have all 5 players.
*The teleport is not being created after the boss is killed.
*even if the boss is killed the timer will kick out the player with the message as if the boss was never killed.

And is it possible that the players get TP out of the room once the boss has been killed instead of creating a teleport?

Lua:
local config = {
    actionId = 59124, -- ActionID to use in the lever
    bossName = "Goshnars Cruelty",
    bossPosition = Position(33855, 31866, 7), -- Position where the boss will appear
    bossArea = {
        fromPos = Position(33852, 31858, 7), -- Upper left corner of the room
        toPos = Position(33861, 31873, 7), -- Lower right corner of the room
        entrancePos = Position(33856, 31868, 7), -- Position where players will be teleported when they enter
        exitPosition = Position(33855, 31865, 7) -- If the participants take too long they will be kicked from the room to this position
    },
    allowedAnyParticipantsCount = true, -- allow any valid number of participants to enter. example: 1,2,3 or 4
    participantsPos = {   
        Position(33854, 31854, 6), -- Player 1, this player should be the one to pull the lever
        Position(33855, 31854, 6), -- Player 2
        Position(33856, 31854, 6), -- Player 3
        Position(33857, 31854, 6), -- Player 4
        Position(33858, 31854, 6) -- Player 5
    },
    attempts = {
        level = 8, -- Level required to enter
        storage = 20001, -- Storage where we keep the waiting time
        seconds = 10 -- 1 hours
    },
    createTeleportPos = Position(33859, 31874, 7), -- Position where the teleport is created when the boss dies
    teleportToPosition = Position(33855, 31866, 7), -- Position where the teleport created by the boss will take you when you die
    teleportRemoveSeconds = 30, -- seconds
    kickParticipantAfterSeconds = 60 * 15, -- 15 minutes
    leverIds = {8911, 8912} -- Lever animation, on/off
}

local function getSpectators(onlyPlayers)
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(config.centerPosition, false, onlyPlayers, config.diffX, config.diffX, config.diffY, config.diffY)
end

local action = Action()

function action.onUse(player, item, fromPos, target, toPos, isHotkey)
    local participants = {}
    for index, pos in pairs(config.participantsPos) do
        local tile = Tile(pos)
        if not tile then error("[Warning - Tile not found]") end
        local participant = tile:getTopVisibleCreature(player)
        if participant and participant:isPlayer() then
            if index == 1 and participant ~= player then
                player:sendCancelMessage("Only the first participant can pull the lever.")
                return true
            end

            if participant:getStorageValue(config.attempts.storage) >= os.time() then
                player:sendCancelMessage(string.format("El jugador %s debe esperar para volver a entrar.", participant:getName()))
            elseif participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(string.format("El jugador %s no es nivel %d.", participant:getName(), config.attempts.level))
            else
                participants[#participants +1] = participant
            end
        end
    end

    if #participants == 0 then
        player:sendCancelMessage("Espere un momento.")
        return true
    elseif not config.allowedAnyParticipantsCount and #participants ~= #config.participantsPos then
        player:sendCancelMessage("Espere un momento.")
        return true
    end

    if #getSpectators(true) > 0 then
        player:sendCancelMessage("Esta ocupado en este momento, intenta mas tarde.")
        return true
    end

    stopEvent(config.kickEventId)

    for _, monsterSpectator in pairs(getSpectators()) do
        monsterSpectator:remove()
    end

    local boss = Game.createMonster(config.bossName, config.bossPosition)
    if not boss then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end

    boss:registerEvent("bossSystemDeath")

    for index, participant in pairs(participants) do
        participant:getPosition():sendMagicEffect(CONST_ME_POFF)
        participant:teleportTo(config.bossArea.entrancePos, false)
        participant:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.seconds)
    end

    config.kickEventId = addEvent(function ()
        for _, spectator in pairs(getSpectators()) do
            if spectator:isPlayer() then
                spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                spectator:teleportTo(config.bossArea.exitPosition, false)
                spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Ha pasado mucho tiempo y no haz podido matar al boss, sera removido de la sala.")
            else
                spectator:remove()
            end
        end
    end, config.kickParticipantAfterSeconds * 11)
    item:transform(item:getId() == config.leverIds[1] and config.leverIds[2] or config.leverIds[1])
    return true
end

action:aid(config.actionId)
action:register()

local creatureEvent = CreatureEvent("bossSystemDeath")

function creatureEvent.onDeath()
    stopEvent(config.kickEventId)
    local teleport = Game.createItem(29980, 1, config.createTeleportPos)
    if teleport then
        teleport:setDestination(config.teleportToPosition)
        addEvent(function ()
            local tile = Tile(config.createTeleportPos)
            if tile then
                local teleport = tile:getItemById(29980)
                if teleport then
                    teleport:remove()
                    config.teleportToPosition:sendMagicEffect(CONST_ME_POFF)
                end
            end

            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.teleportToPosition, false)
                    spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                else
                    spectator:remove()
                end
            end
        end, config.teleportRemoveSeconds * 20)
    end
    return true
end

creatureEvent:register()

EDIT : The timers are set with low values because i was testing them, they should be

Lever 1 hour
time in room 5 minutes
 
Hi! I wonder if there could be a little improvement to this system, adding time exact cooldown time at
Lua:
player:sendCancelMessage(string.format("The player %s must wait a while before being able to enter again.", participant:getName()

Based on the given storage, to get "The player %s must wait XX:XX seconds (or minutes) before being able to enter...
Thanks in advance!

enriquegomezha9 said:
Some players are getting a message "You need at least one participant" even if they have all 5 players.
To fix this just add the returns where @Xikini said here
 
Script works fine on a friends server Sarah, thank you. He had some issues with it and asked me for help but turned out it was just the cancelMessages that weren't showing correctly.

These need a return true after the cancelMessages:
Lua:
 if participant:getStorageValue(config.attempts.storage) >= os.time() then
                player:sendCancelMessage(string.format("The player %s must wait a while before being able to enter again.", participant:getName()))
            elseif participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(string.format("The player %s is not level %d.", participant:getName(), config.attempts.level))
            else

Otherwise, it will just show this message "You need at least one participant." if nobody meets the requirements.

Thanks again and good job!
 
There shouldn't be an issue. Just use it as explained in the first post.
I'm using tfs 1.5, and I have a small problem, when I kill the boss I'm not sent out, then I wait and get thrown out for "taking too long", I would like to be sent out when I kill the boss, and know also if it is possible for all players in the boss room to receive x reward when the boss dies, example: we have 3 players in the room, the boss dies, the 3 are thrown out and receive a boh, and a message "you defeated the boss "
 
Hello, when I make one boss, everything is fine, but when I try to make more, the teleport does not appear. server does not show errors tfs 1.5 downgraded by nekiro 8.6
 
Is there a way to use this version of a boss room but to simplify it and connecting the action Id into a teleport that is meant for "solo bosses" instead of having participants and a lever. so instead of using a OnUse function you would use a StepIn function?

ive tried alot on my own with no luck. Would highly appreciate it if anyone could help me or guide me in any way shape or form<3

TFS 1.4.2 10.98
 
Is there a way to use this version of a boss room but to simplify it and connecting the action Id into a teleport that is meant for "solo bosses" instead of having participants and a lever. so instead of using a OnUse function you would use a StepIn function?

ive tried alot on my own with no luck. Would highly appreciate it if anyone could help me or guide me in any way shape or form<3

TFS 1.4.2 10.98
try

Lua:
local config = {
    tileId = 59124, -- ActionID onStepIn Tile
    bossName = "Goshnars Cruelty",
    bossPosition = Position(33855, 31866, 7), -- Position where the boss will appear
    bossArea = {
        fromPos = Position(33852, 31858, 7), -- Upper left corner of the room
        toPos = Position(33861, 31873, 7), -- Lower right corner of the room
        entrancePos = Position(33856, 31868, 7), -- Position where players will be teleported when they enter
        exitPosition = Position(33855, 31865, 7) -- If the participants take too long they will be kicked from the room to this position
    },
    allowedAnyParticipantsCount = true, 
    participantsPos = {   
        Position(33854, 31854, 6), -- 1 Tile where is the AID 59124
    },
    attempts = {
        level = 8, -- Level required to enter
        storage = 20001, -- Storage where we keep the waiting time
        seconds = 10 -- 1 hours
    },
    createTeleportPos = Position(33859, 31874, 7), -- Position where the teleport is created when the boss dies
    teleportToPosition = Position(33855, 31866, 7), -- Position where the teleport created by the boss will take you when you die
    teleportRemoveSeconds = 30, -- seconds
    kickParticipantAfterSeconds = 60 * 15, -- 15 minutes
    leverIds = {8911, 8912} -- Lever animation, on/off
}

local function getSpectators(onlyPlayers)
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(config.centerPosition, false, onlyPlayers, config.diffX, config.diffX, config.diffY, config.diffY)
end

local action = MoveEvent()

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

    local participants = {}
    for index, pos in pairs(config.participantsPos) do
        local tile = Tile(pos)
        if not tile then error("[Warning - Tile not found]") end
        local participant = tile:getTopVisibleCreature(player)
        if participant and participant:isPlayer() then
            if index == 1 and participant ~= player then
                player:sendCancelMessage("Only the first participant can pull the lever.")
                return true
            end

            if participant:getStorageValue(config.attempts.storage) >= os.time() then
                player:sendCancelMessage(string.format("El jugador %s debe esperar para volver a entrar.", participant:getName()))
            elseif participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(string.format("El jugador %s no es nivel %d.", participant:getName(), config.attempts.level))
            else
                participants[#participants +1] = participant
            end
        end
    end

    if #participants == 0 then
        player:sendCancelMessage("Espere un momento.")
        return true
    elseif not config.allowedAnyParticipantsCount and #participants ~= #config.participantsPos then
        player:sendCancelMessage("Espere un momento.")
        return true
    end

    if #getSpectators(true) > 0 then
        player:sendCancelMessage("Esta ocupado en este momento, intenta mas tarde.")
        return true
    end

    stopEvent(config.kickEventId)

    for _, monsterSpectator in pairs(getSpectators()) do
        monsterSpectator:remove()
    end

    local boss = Game.createMonster(config.bossName, config.bossPosition)
    if not boss then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end

    boss:registerEvent("bossSystemDeath")

    for index, participant in pairs(participants) do
        participant:getPosition():sendMagicEffect(CONST_ME_POFF)
        participant:teleportTo(config.bossArea.entrancePos, false)
        participant:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.seconds)
    end

    config.kickEventId = addEvent(function ()
        for _, spectator in pairs(getSpectators()) do
            if spectator:isPlayer() then
                spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                spectator:teleportTo(config.bossArea.exitPosition, false)
                spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Ha pasado mucho tiempo y no haz podido matar al boss, sera removido de la sala.")
            else
                spectator:remove()
            end
        end
    end, config.kickParticipantAfterSeconds * 11)
    item:transform(item:getId() == config.leverIds[1] and config.leverIds[2] or config.leverIds[1])
    return true
end

action:aid(config.tileId)
action:register()

local creatureEvent = CreatureEvent("bossSystemDeath")

function creatureEvent.onDeath()
    stopEvent(config.kickEventId)
    local teleport = Game.createItem(29980, 1, config.createTeleportPos)
    if teleport then
        teleport:setDestination(config.teleportToPosition)
        addEvent(function ()
            local tile = Tile(config.createTeleportPos)
            if tile then
                local teleport = tile:getItemById(29980)
                if teleport then
                    teleport:remove()
                    config.teleportToPosition:sendMagicEffect(CONST_ME_POFF)
                end
            end

            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.teleportToPosition, false)
                    spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                else
                    spectator:remove()
                end
            end
        end, config.teleportRemoveSeconds * 20)
    end
    return true
end

creatureEvent:register()
 
try

Lua:
local config = {
    tileId = 59124, -- ActionID onStepIn Tile
    bossName = "Goshnars Cruelty",
    bossPosition = Position(33855, 31866, 7), -- Position where the boss will appear
    bossArea = {
        fromPos = Position(33852, 31858, 7), -- Upper left corner of the room
        toPos = Position(33861, 31873, 7), -- Lower right corner of the room
        entrancePos = Position(33856, 31868, 7), -- Position where players will be teleported when they enter
        exitPosition = Position(33855, 31865, 7) -- If the participants take too long they will be kicked from the room to this position
    },
    allowedAnyParticipantsCount = true,
    participantsPos = {  
        Position(33854, 31854, 6), -- 1 Tile where is the AID 59124
    },
    attempts = {
        level = 8, -- Level required to enter
        storage = 20001, -- Storage where we keep the waiting time
        seconds = 10 -- 1 hours
    },
    createTeleportPos = Position(33859, 31874, 7), -- Position where the teleport is created when the boss dies
    teleportToPosition = Position(33855, 31866, 7), -- Position where the teleport created by the boss will take you when you die
    teleportRemoveSeconds = 30, -- seconds
    kickParticipantAfterSeconds = 60 * 15, -- 15 minutes
    leverIds = {8911, 8912} -- Lever animation, on/off
}

local function getSpectators(onlyPlayers)
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(config.centerPosition, false, onlyPlayers, config.diffX, config.diffX, config.diffY, config.diffY)
end

local action = MoveEvent()

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

    local participants = {}
    for index, pos in pairs(config.participantsPos) do
        local tile = Tile(pos)
        if not tile then error("[Warning - Tile not found]") end
        local participant = tile:getTopVisibleCreature(player)
        if participant and participant:isPlayer() then
            if index == 1 and participant ~= player then
                player:sendCancelMessage("Only the first participant can pull the lever.")
                return true
            end

            if participant:getStorageValue(config.attempts.storage) >= os.time() then
                player:sendCancelMessage(string.format("El jugador %s debe esperar para volver a entrar.", participant:getName()))
            elseif participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(string.format("El jugador %s no es nivel %d.", participant:getName(), config.attempts.level))
            else
                participants[#participants +1] = participant
            end
        end
    end

    if #participants == 0 then
        player:sendCancelMessage("Espere un momento.")
        return true
    elseif not config.allowedAnyParticipantsCount and #participants ~= #config.participantsPos then
        player:sendCancelMessage("Espere un momento.")
        return true
    end

    if #getSpectators(true) > 0 then
        player:sendCancelMessage("Esta ocupado en este momento, intenta mas tarde.")
        return true
    end

    stopEvent(config.kickEventId)

    for _, monsterSpectator in pairs(getSpectators()) do
        monsterSpectator:remove()
    end

    local boss = Game.createMonster(config.bossName, config.bossPosition)
    if not boss then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end

    boss:registerEvent("bossSystemDeath")

    for index, participant in pairs(participants) do
        participant:getPosition():sendMagicEffect(CONST_ME_POFF)
        participant:teleportTo(config.bossArea.entrancePos, false)
        participant:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.seconds)
    end

    config.kickEventId = addEvent(function ()
        for _, spectator in pairs(getSpectators()) do
            if spectator:isPlayer() then
                spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                spectator:teleportTo(config.bossArea.exitPosition, false)
                spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Ha pasado mucho tiempo y no haz podido matar al boss, sera removido de la sala.")
            else
                spectator:remove()
            end
        end
    end, config.kickParticipantAfterSeconds * 11)
    item:transform(item:getId() == config.leverIds[1] and config.leverIds[2] or config.leverIds[1])
    return true
end

action:aid(config.tileId)
action:register()

local creatureEvent = CreatureEvent("bossSystemDeath")

function creatureEvent.onDeath()
    stopEvent(config.kickEventId)
    local teleport = Game.createItem(29980, 1, config.createTeleportPos)
    if teleport then
        teleport:setDestination(config.teleportToPosition)
        addEvent(function ()
            local tile = Tile(config.createTeleportPos)
            if tile then
                local teleport = tile:getItemById(29980)
                if teleport then
                    teleport:remove()
                    config.teleportToPosition:sendMagicEffect(CONST_ME_POFF)
                end
            end

            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.teleportToPosition, false)
                    spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                else
                    spectator:remove()
                end
            end
        end, config.teleportRemoveSeconds * 20)
    end
    return true
end

creatureEvent:register()
hi!

im having some issues with the script and i cant really pinpoint why, when a player kills the demon he instantly gets teleported out of the boss Area, and a Teleport never spawns, the "cooldown" on using the teleport doesnt work either, they can simply reenter.

ive put the script in data/scripts.

i changed some stuff on the script like the id of the teleports to the regular ones (1387) and obviously my cordinates and the boss name (demon)
i was unsure about what to put on the lever ids so i simply put the id for a teleport x).


Lua:
function creatureEvent.onDeath()
    stopEvent(config.kickEventId)
    local teleport = Game.createItem(1387, 1, config.createTeleportPos)
    if teleport then
        teleport:setDestination(config.teleportToPosition)
        addEvent(function ()
            local tile = Tile(config.createTeleportPos)
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport then
                    teleport:remove()
                    config.teleportToPosition:sendMagicEffect(CONST_ME_POFF)
                end
            end


Here is the entire code:


Code:
local config = {
    tileId = 9954, -- ActionID onStepIn Tile
    bossName = "demon",
    bossPosition = Position(687, 976, 5), -- Position where the boss will appear
    bossArea = {
        fromPos = Position(672, 963, 5), -- Upper left corner of the room
        toPos = Position(708, 1005, 5), -- Lower right corner of the room
        entrancePos = Position(688, 982, 5), -- Position where players will be teleported when they enter
        exitPosition = Position(757, 976, 5) -- If the participants take too long they will be kicked from the room to this position
    },
    allowedAnyParticipantsCount = true,
    participantsPos = {   
        Position(754, 976, 5), -- 1 Tile where is the AID 59124
    },
    attempts = {
        level = 8, -- Level required to enter
        storage = 20001, -- Storage where we keep the waiting time
        seconds = 10 -- 1 hours
    },
    createTeleportPos = Position(688, 991, 5), -- Position where the teleport is created when the boss dies
    teleportToPosition = Position(757, 976, 5), -- Position where the teleport created by the boss will take you when you die
    teleportRemoveSeconds = 30, -- seconds
    kickParticipantAfterSeconds = 60 * 15, -- 15 minutes
    leverIds = {1387} -- Lever animation, on/off
}

local function getSpectators(onlyPlayers)
    if not config.centerPosition then
        config.diffX = math.ceil((config.bossArea.toPos.x - config.bossArea.fromPos.x) / 2)
        config.diffY = math.ceil((config.bossArea.toPos.y - config.bossArea.fromPos.y) / 2)
        config.centerPosition = config.bossArea.fromPos + Position(config.diffX, config.diffY, 0)
    end
    return Game.getSpectators(config.centerPosition, false, onlyPlayers, config.diffX, config.diffX, config.diffY, config.diffY)
end

local action = MoveEvent()

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

    local participants = {}
    for index, pos in pairs(config.participantsPos) do
        local tile = Tile(pos)
        if not tile then error("[Warning - Tile not found]") end
        local participant = tile:getTopVisibleCreature(player)
        if participant and participant:isPlayer() then
            if index == 1 and participant ~= player then
                player:sendCancelMessage("Only the first participant can pull the lever.")
                return true
            end

            if participant:getStorageValue(config.attempts.storage) >= os.time() then
                player:sendCancelMessage(string.format("El jugador %s debe esperar para volver a entrar.", participant:getName()))
            elseif participant:getLevel() < config.attempts.level then
                player:sendCancelMessage(string.format("El jugador %s no es nivel %d.", participant:getName(), config.attempts.level))
            else
                participants[#participants +1] = participant
            end
        end
    end

    if #participants == 0 then
        player:sendCancelMessage("Espere un momento.")
        return true
    elseif not config.allowedAnyParticipantsCount and #participants ~= #config.participantsPos then
        player:sendCancelMessage("Espere un momento.")
        return true
    end

    if #getSpectators(true) > 0 then
        player:sendCancelMessage("Esta ocupado en este momento, intenta mas tarde.")
        return true
    end

    stopEvent(config.kickEventId)

    for _, monsterSpectator in pairs(getSpectators()) do
        monsterSpectator:remove()
    end

    local boss = Game.createMonster(config.bossName, config.bossPosition)
    if not boss then
        player:sendCancelMessage(RETURNVALUE_NOTPOSSIBLE)
        return true
    end

    boss:registerEvent("bossSystemDeath")

    for index, participant in pairs(participants) do
        participant:getPosition():sendMagicEffect(CONST_ME_POFF)
        participant:teleportTo(config.bossArea.entrancePos, false)
        participant:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
        participant:setStorageValue(config.attempts.storage, os.time() + config.attempts.seconds)
    end

    config.kickEventId = addEvent(function ()
        for _, spectator in pairs(getSpectators()) do
            if spectator:isPlayer() then
                spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                spectator:teleportTo(config.bossArea.exitPosition, false)
                spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Ha pasado mucho tiempo y no haz podido matar al boss, sera removido de la sala.")
            else
                spectator:remove()
            end
        end
    end, config.kickParticipantAfterSeconds * 11)
    item:transform(item:getId() == config.leverIds[1])
    return true
end

action:aid(config.tileId)
action:register()

local creatureEvent = CreatureEvent("bossSystemDeath")

function creatureEvent.onDeath()
    stopEvent(config.kickEventId)
    local teleport = Game.createItem(1387, 1, config.createTeleportPos)
    if teleport then
        teleport:setDestination(config.teleportToPosition)
        addEvent(function ()
            local tile = Tile(config.createTeleportPos)
            if tile then
                local teleport = tile:getItemById(1387)
                if teleport then
                    teleport:remove()
                    config.teleportToPosition:sendMagicEffect(CONST_ME_POFF)
                end
            end

            for _, spectator in pairs(getSpectators()) do
                if spectator:isPlayer() then
                    spectator:getPosition():sendMagicEffect(CONST_ME_POFF)
                    spectator:teleportTo(config.teleportToPosition, false)
                    spectator:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
                else
                    spectator:remove()
                end
            end
        end, config.teleportRemoveSeconds * 20)
    end
    return true
end

creatureEvent:register()

Thank you for taking your time to send me your script! highly appreciated!
 
Back
Top