• 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] Globalevents onTime create a teleport for a zombie event.

I don't know anything much about scripts, I applied the logic a bit and this is what has come out.
I don't know if the structure is right.
Code:
function onTime(interval, lastExecution)
    local minPlayers = 1
    local maxPlayers = 2
    local waitTime = 5
   
    local playersOnline = getOnlinePlayers()

    if playersOnline > maxPlayers then --How do I set this correctly?
        -- If it's a staff member, just teleport inside and do not count as a participant
        if player:getGroup():getAccess() then
            player:teleportTo(ze_WaitingRoomStartPosition)
            return false
        end

        -- If the state of the event is closed or started, stop them from join
        if isInArray({ze_EVENT_CLOSED, ze_EVENT_STARTED}, getZombieEventState()) then
            return false
        end

        -- If player got pz, forbid them to join
        if player:isPzLocked() then
            player:sendCancelMessage("You cannot join while your in a fight.")
            return false
        end

        -- If there is max players joined, stop them from join
        if getZombieEventJoinedCount() >= ze_maxPlayers then
            player:sendCancelMessage("The event is already full.")
            return false
        end

        -- Set the new variables and setup the event
        setupZombieEvent(minPlayers, maxPlayers, waitTime)
    end

    return false
end
Error
Code:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/zombie_arena.lua:onTime
data/globalevents/scripts/zombie_arena.lua:8: attempt to compare number with table
stack traceback:
        [C]: in function '__lt'
        data/globalevents/scripts/zombie_arena.lua:8: in function <data/globalevents/scripts/zombie_arena.lua:1>
 
I guess this function "getOnlinePlayers" returns a table with the id and the name of the player, so maybe try change:

Lua:
local playersOnline = getOnlinePlayers()
to
Lua:
local playersOnline = #getOnlinePlayers()
 
I guess this function "getOnlinePlayers" returns a table with the id and the name of the player, so maybe try change:

Lua:
local playersOnline = getOnlinePlayers()
to
Lua:
local playersOnline = #getOnlinePlayers()
Update: I did it. Thank you.
Code:
function onTime(interval, lastExecution)
    local minPlayers = 3 --
    local maxPlayers = 3 --
    local waitTime = 1 --
    
    local playersOnline = #getOnlinePlayers()

    if playersOnline >= maxPlayers then
        Game.broadcastMessage("Zombie Event it's coming...", MESSAGE_STATUS_WARNING)
        print('...Game.broadcastMessage("Zombie Event Starting...", MESSAGE_STATUS_WARNING)...')
        -- Set the new variables and setup the event
        setupZombieEvent(minPlayers, maxPlayers, waitTime)
    else
      Game.broadcastMessage("[Zombie Event]: Insufficient online players to open the event", MESSAGE_STATUS_WARNING)
      print('[Zombie Event]: Insufficient online players to open the event')
    end
    
    return false
end
 
Last edited:
Back
Top