• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua Zombie Event (Global.lua)

Sentinel3

New Member
Joined
Oct 16, 2014
Messages
180
Reaction score
0
Hi everyone.., again!

Using: TFS 1.0 with tibia version 10.41

I got this error starting zombie event

Error in Console:
HTML:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/global.lua:256: table index is nil
stack traceback:
        [C]: in function '__newindex'
        data/global.lua:256: in function 'setStorageValue'
        data/zombie_system.lua:69: in function 'resetVariables'
        data/zombie_system.lua:35: in function <data/zombie_system.lua:28>

/data/zombie_system.lua
HTML:
-- Zombie Variables
zeZombieName = 'Zombie Event' --Zombie Name
zombieSpawnInterval = 5 --how many seconds until a new zombie spawns
zeMaxZombies = 50 --max zombies in the arena?
zeJoinedCountGlobalStorage = 100 --Player joined event count

-- Players Variables
zeJoinStorage = 1000 --player join storage
zeMinPlayers = 2 --min players needed when time runout
zeMaxPlayers = 30 --max players to join
zeTrophy = 7369 --trophy itemid
zeJoinedCountGlobalStorage = 101 --Zombie spawned Count

-- Other Variables
zeWaitMinutes = 1 --when event has opened, how long until it starts?
zeWaitingRoomPos = Position(31374, 32306, 7) --middle of waiting room
zeZombieArena = Position(31373, 32217, 7) --when even start where should player be teleported in the zombie arena?
zeArenaFromPosition = Position(31324, 32167, 7) --pos of top left corner
zeArenaToPosition = Position(31421, 32266, 7) --pos of bottom right corner
zeMiddleZombieArena = Position(31373, 32217, 7) --Middle pos of the arena
zeWaitingRoomRadiusX = 20 --depends how big the waiting room is 20sqm to x
zeWaitingRoomRadiusY = 20 --depends how big the waiting room is 20sqm to y
zeZombieArenaRadiusX = 50 --Depends how big the zombie arena is 50sqm to x
zeZombieArenaRadiusY = 50 --Depends how big the zombie arena is 50sqm to y
zeStartedGlobalStorage = 102 -- Value: 0 == false, 1 == true, 2 == started --State of the event
zeCreateTeleportPosition = Position(32349, 32222, 7) --Where should the teleport be created?

function startZombie()
    local specs = Game.getSpectators(zeWaitingRoomPos, false, true, 0, zeWaitingRoomRadiusX, 0, zeWaitingRoomRadiusY)
        if Game.getStorageValue(zeJoinedCountGlobalStorage) == nil or 0 then
            for i = 1, #specs do
                    specs[i]:teleportTo(specs[i]:getTown():getTemplePosition(), false)
                    specs[i]:setStorageValue(zeJoinStorage, 0)
            end
            resetVariables()
            Game.broadcastMessage('Zombie Event failed to start, not enough players joined the event!', MESSAGE_STATUS_WARNING)
            return true
        end
        for i = 1, #specs do
            specs[i]:teleportTo(zeZombieArena)
        end
        Game.broadcastMessage("Zombie Event has started, good luck to all participant.", MESSAGE_STATUS_WARNING)
        Game.setStorageValue(zeStartedGlobalStorage, 2)
        doStartZombieEvasion()
end

function doSummonZombie()
        if Game.getStorageValue(zeZombieCountGlobalStorage) > zeMaxZombies then
            return false
        end
        local zombie = Game.createMonster(zeZombieName, {x = math.random(zeArenaFromPosition.x, zeArenaToPosition.x), y = math.random(zeArenaFromPosition.y, zeArenaToPosition.y), z = math.random(zeArenaFromPosition.z, zeArenaToPosition.z)})
        if zombie then
            Game.createMonster(zeZombieName, {x = math.random(zeArenaFromPosition.x, zeArenaToPosition.x), y = math.random(zeArenaFromPosition.y, zeArenaToPosition.y), z = math.random(zeArenaFromPosition.z, zeArenaToPosition.z)})
        end
        Game.setStorageValue(zeZombieCountGlobalStorage, Game.getStorageValue(zeZombieCountGlobalStorage) + 1)
end

function doStartZombieEvasion()
        if Game.getStorageValue(zeStartedGlobalStorage) == 2 then
               doSummonZombie()
            addEvent(doStartZombieEvasion, 5 * 1000)
        end
end

function resetVariables()
        Game.setStorageValue(zeJoinedCountGlobalStorage, 0)
        Game.setStorageValue(zeZombieCountGlobalStorage, 0)
        Game.setStorageValue(zeStartedGlobalStorage, 0)
end

function doClearZombieArena()
        local specs = Game.getSpectators(zeMiddleZombieArena, false, false, 0, zeZombieArenaRadiusX, 0, zeZombieArenaRadiusY)
        for i = 1, #specs do
            if specs[i]:getName() == zeZombieName then
                    specs[i]:remove()
            end
        end
end

/data/global.lua
line: 256
HTML:
function Game.setStorageValue(key, value)
    globalStorageTable[key] = value
end

I leave you one picture
Captura_zpse0ef41e0.png


Please if someone can help me with this error I will appreciate it :D
 
Change zeJoinedCountGlobalStorage = 101 --Zombie spawned Count to
Code:
zeZombieCountGlobalStorage = 101 --Zombie spawned Count
 
Change zeJoinedCountGlobalStorage = 101 --Zombie spawned Count to
Code:
zeZombieCountGlobalStorage = 101 --Zombie spawned Count


Got the same error, but it says in line 28 of /data/zombie_system.lua
HTML:
function startZombie()
    local specs = Game.getSpectators(zeWaitingRoomPos, false, true, 0, zeWaitingRoomRadiusX, 0, zeWaitingRoomRadiusY)
        if Game.getStorageValue(zeJoinedCountGlobalStorage) == nil or 0 then
            for i = 1, #specs do
                    specs[i]:teleportTo(specs[i]:getTown():getTemplePosition(), false)
                    specs[i]:setStorageValue(zeJoinStorage, 0)
            end
            resetVariables()
            Game.broadcastMessage('Zombie Event failed to start, not enough players joined the event!', MESSAGE_STATUS_WARNING)
            return true
        end
 
The error is in the function resetVariables, which is in an other function.
Code:
function resetVariables()
     Game.setStorageValue(zeJoinedCountGlobalStorage, 0)
     Game.setStorageValue(zeZombieCountGlobalStorage, 0)
     Game.setStorageValue(zeStartedGlobalStorage, 0)
end
zeZombieCountGlobalStorage is not defined in the script you posted, so it's nil, if you change the variable I posted, then it's not nil anymore.
Atm the variable zeJoinedCountGlobalStorage is defined 2x.

If it still gives the same error, you can add -- before the Game lines, this will quote it so it will skup ut like it's not there, to see what exactly gives the error.
 
The error is in the function resetVariables, which is in an other function.
Code:
function resetVariables()
     Game.setStorageValue(zeJoinedCountGlobalStorage, 0)
     Game.setStorageValue(zeZombieCountGlobalStorage, 0)
     Game.setStorageValue(zeStartedGlobalStorage, 0)
end
zeZombieCountGlobalStorage is not defined in the script you posted, so it's nil, if you change the variable I posted, then it's not nil anymore.
Atm the variable zeJoinedCountGlobalStorage is defined 2x.

If it still gives the same error, you can add -- before the Game lines, this will quote it so it will skup ut like it's not there, to see what exactly gives the error.

Right now the console doesnt give anymore the error that I got, but I can't enter in teleport. (I left you a picture in thread)
 
Here it is, script /data/movements/scripts/zombie_teleport.lua

HTML:
dofile('data/zombie_system.lua')

function onStepIn(cid, item, position, fromPosition)
        local player = Player(cid)
    if not player then
            return false
        end
 
        if Game.getStorageValue(zeStartedGlobalStorage) == 2 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event has already started.')
            player:teleportTo(fromPosition, true)
            return false
        end
 
        if Game.getStorageValue(zeStartedGlobalStorage) == 0 then
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event has not started yet.')
            player:teleportTo(fromPosition, true)
            return false
        end
 
       if Game.getStorageValue(zeZombieCountGlobalStorage) > zeMaxPlayers then
            player:teleportTo(fromPosition, true)
            player:sendTextMessage(MESSAGE_INFO_DESCR, 'The Zombie Event is already full! ['.. Game.getStorageValue(zeZombieCountGlobalStorage) ..'/'.. zeMaxPlayers ..']')
            return false
        end
 
        player:teleportTo(zeWaitingRoomPos)
        Game.setStorageValue(zeZombieCountGlobalStorage, Game.getStorageValue(zeZombieCountGlobalStorage) + 1)
        Game.broadcastMessage(string.format('%s has joined the Zombie Event! [%s/'.. zeMaxPlayers ..'].', player:getName(), Game.getStorageValue(zeZombieCountGlobalStorage)), MESSAGE_STATUS_WARNING)
        player:setStorageValue(zeJoinStorage, 1)
        return true
end
 
Here it is, script /data/globalevents/scripts/zombie_think.lua
HTML:
dofile('data/zombie_system.lua')

function onThink(interval, lastExecution, thinkInterval)
    if Game.getStorageValue(zeStartedGlobalStorage) < 1 then
        local teleport = Game.createItem(1387, 1, zeCreateTeleportPosition)
        if teleport then
            teleport:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, 7000)
        end
        Game.setStorageValue(zeStartedGlobalStorage, 1)
        print('Zombie Event has started & waiting for players to join! Min: '.. zeMinPlayers ..'/'.. zeMaxPlayers ..'.')
        Game.broadcastMessage('The Zombie Event has started! You have '.. zeWaitMinutes ..' minutes to join!', MESSAGE_STATUS_WARNING)
        addEvent(startZombie, zeWaitMinutes * 60 * 1000)
    end
    return true
end

--> Updated <--

Post the globalevent script, the storage value needs to be set to 1 or at least not be 0 or 2.

It's already done, the value is 1
 
Last edited:
Here it is, script /data/globalevents/scripts/zombie_think.lua
HTML:
dofile('data/zombie_system.lua')

function onThink(interval, lastExecution, thinkInterval)
    if Game.getStorageValue(zeStartedGlobalStorage) < 1 then
        local teleport = Game.createItem(1387, 1, zeCreateTeleportPosition)
        if teleport then
            teleport:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, 7000)
        end
        Game.setStorageValue(zeStartedGlobalStorage, 1)
        print('Zombie Event has started & waiting for players to join! Min: '.. zeMinPlayers ..'/'.. zeMaxPlayers ..'.')
        Game.broadcastMessage('The Zombie Event has started! You have '.. zeWaitMinutes ..' minutes to join!', MESSAGE_STATUS_WARNING)
        addEvent(startZombie, zeWaitMinutes * 60 * 1000)
    end
    return true
end



I have the same problem with that madafaker function onThink(interval, lastExecution, thinkInterval) :(
any idea how to fix?
 
Back
Top