• 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 script getSpectators error

undead mage

Active Member
Joined
Mar 25, 2012
Messages
364
Solutions
2
Reaction score
47
Location
Amsterdam
So im trying to make a boss script that when you use the lever you and your team will get teleported into the boss room and get 5 minutes to kill it before getting teleported out. Im not done yet the level requirement and the minimum of 5 players seem to work but im getting errors when checking if a team is already inside. I just can't figure out why it's giving me a nil value error.

attempt to index a nil value
stack traceback:
[C]: at 0x7ff6b82e3c60
[C]: in function 'getSpectators'

Code:
local bossConfig = {
    [34001] = {  -- ActionID
        requiredLevel = 100,

        centerRoomPosition = Position(175, 508, 11),
        northRange = 10, eastRange = 10, southRange = 10, westRange = 10,

        playerPositions = {
        Position(165, 532, 11),
        Position(165, 533, 11),
        Position(165, 534, 11),
        Position(165, 535, 11),
        Position(165, 536, 11)
        }
    }
}

function onUse(player, item, fromPosition, target, toPosition, isHotkey)
    if item.itemid == 9826 then
        local storePlayers, playerTile = {}

    local info = bossConfig[item:getActionId()]
    if not info then
        return false
    end

        for i = 1, #info.playerPositions do
            playerTile = Tile(info.playerPositions[i]):getTopCreature()
            if not playerTile or not playerTile:isPlayer() then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "You need 5 players.")
                return true
            end

            if playerTile:getLevel() < info.requiredLevel then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "All the players need to be level ".. config.requiredLevel .." or higher.")
                return true
            end     

            storePlayers[#storePlayers + 1] = playerTile
        end

    local spectators = Game.getSpectators(info.centerRoomPosition, false, false, info.westRange, info.eastRange, info.northRange, info.southRange)
    for i = 1, #spectators do
        local spectator = spectators[i]
        if spectator:isPlayer() then
            spectator:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'There is already a team inside.')
        else
            spectator:remove()
        end
    end   

    end

    item:transform(item.itemid == 9826 and 9825 or 9826)
    return true
end
 
Back
Top