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

RevScripts i need auto zombie system

Gaber Zen

Well-Known Member
Joined
Apr 22, 2023
Messages
224
Reaction score
51
Location
Egypt
hello everyone
some one help me, everytime need to open event zombie use!zombiestart
how i can add auto? like globalevents
0.4
<talkaction log="yes" words="/zombiestart" access="4" event="script" value="zombie/onsay.lua"/>

Lua:
function onSay(cid, words, param, channel)
    if(getStorage(ZE_STATUS) ~= 2) then
        local players_on_arena_count = #getZombiesEventPlayers()
        if(param == 'force') then
            if(players_on_arena_count > 0) then
                setZombiesEventPlayersLimit(players_on_arena_count  )
                addZombiesEventBlockEnterPosition()
                doSetStorage(ZE_STATUS, 2)
                doBroadcastMessage("Zombie Arena Event started.")
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Zombies event started.")
            else
                doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Cannot start Zombies event. There is no players on arena.")
            end
        else
            if(param ~= '' and tonumber(param) > 0) then
                setZombiesEventPlayersLimit(tonumber(param))
            end
            removeZombiesEventBlockEnterPosition()
            doSetStorage(ZE_STATUS, 1)
            doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Event started.")
            doPlayerBroadcastMessage(cid, "Zombie Arena Event teleport is opened. We are waiting for " .. getZombiesEventPlayersLimit() - players_on_arena_count .. " players to start.")
        end
    else
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_BLUE, "Zombies event is already running.")
    end
    return true
end
<globalevent name="ZombieGlobalStartup" type="start" event="script" value="zombie/onstartup.lua"/>
Lua:
function onStartup()
    db.executeQuery("UPDATE `player_storage` SET `value` = 0 WHERE `key` = " .. ZE_isOnZombieArea .. ";")
    doSetStorage(ZE_STATUS, 0)
    doSetStorage(ZE_PLAYERS_NUMBER, ZE_DEFAULT_NUMBER_OF_PLAYERS)
    doSetStorage(ZE_ZOMBIES_TO_SPAWN, 0)
    doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
    addZombiesEventBlockEnterPosition()
    return true
end
lib
Lua:
-- CONFIG
ZE_DEFAULT_NUMBER_OF_PLAYERS = 3
ZE_ACCESS_TO_IGNORE_ARENA = 1
-- POSITIONS
ZE_blockEnterItemPosition = {x= 997, y=1013, z=7}
ZE_enterPosition = {x = 1002, y = 1011, z = 7}
ZE_kickPosition = {x=1000, y=1000, z=7}
ZE_spawnFromPosition = {x = 1678, y = 1691, z = 7}
ZE_spawnToPosition =  {x = 1721, y = 1731, z = 7}
-- ITEM IDS
ZE_blockEnterItemID = 1546
-- STORAGES
-- - player
ZE_isOnZombieArea = 34370
-- - global
ZE_STATUS = 34370 -- =< 0 - off, 1 - waiting for players, 2 - is running
ZE_PLAYERS_NUMBER = 34371
ZE_ZOMBIES_TO_SPAWN = 34372
ZE_ZOMBIES_SPAWNED = 34373

-- FUNCTION

function setZombiesEventPlayersLimit(value)
    doSetStorage(ZE_PLAYERS_NUMBER, value)
end

function getZombiesEventPlayersLimit()
    return getStorage(ZE_PLAYERS_NUMBER)
end

function addPlayerToZombiesArea(cid)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    doTeleportThing(cid, ZE_enterPosition, true)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    if(getPlayerAccess(cid) < ZE_ACCESS_TO_IGNORE_ARENA) then
        setPlayerZombiesEventStatus(cid, os.time())
    end
end

function kickPlayerFromZombiesArea(cid)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    doTeleportThing(cid, ZE_kickPosition, true)
    doSendMagicEffect(getThingPosition(cid), CONST_ME_TELEPORT)
    setPlayerZombiesEventStatus(cid, 0)
end

function getPlayerZombiesEventStatus(cid)
    return getCreatureStorage(cid, ZE_isOnZombieArea)
end

function setPlayerZombiesEventStatus(cid, value)
    doCreatureSetStorage(cid, ZE_isOnZombieArea, value)
end

function getZombiesEventPlayers()
    local players = {}
    for i, cid in pairs(getPlayersOnline()) do
        if(getPlayerZombiesEventStatus(cid) > 0) then
            table.insert(players, cid)
        end
    end
    return players
end

function getZombiesCount()
    return getStorage(ZE_ZOMBIES_SPAWNED)
end

function addZombiesCount()
    doSetStorage(ZE_ZOMBIES_SPAWNED, getStorage(ZE_ZOMBIES_SPAWNED)+1)
end

function resetZombiesCount()
    doSetStorage(ZE_ZOMBIES_SPAWNED, 0)
end

function getZombiesToSpawnCount()
    return getStorage(ZE_ZOMBIES_TO_SPAWN)
end

function setZombiesToSpawnCount(count)
    doSetStorage(ZE_ZOMBIES_TO_SPAWN, count)
end

function addZombiesEventBlockEnterPosition()
    if(getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID).uid == 0) then
        doCreateItem(ZE_blockEnterItemID, 1, ZE_blockEnterItemPosition)
    end
end

function removeZombiesEventBlockEnterPosition()
    local item = getTileItemById(ZE_blockEnterItemPosition, ZE_blockEnterItemID)
    if(item.uid ~= 0) then
        doRemoveItem(item.uid)
    end
end

function spawnNewZombie()
    local posx = {}
    local posy = {}
    local posz = {}
    local pir = {}
    for i=1, 5 do
        local posx_tmp = math.random(ZE_spawnFromPosition.x ,ZE_spawnToPosition.x)
        local posy_tmp = math.random(ZE_spawnFromPosition.y ,ZE_spawnToPosition.y)
        local posz_tmp = math.random(ZE_spawnFromPosition.z ,ZE_spawnToPosition.z)
        local pir_tmp = 0
        local spec = getSpectators({x=posx_tmp, y=posy_tmp, z=posz_tmp}, 3, 3, false)
        if(spec and #spec > 0) then
            for z, pid in pairs(spec) do
                if(isPlayer(pid)) then
                    pir_tmp = pir_tmp + 1
                end
            end
        end
        posx[i] = posx_tmp
        posy[i] = posy_tmp
        posz[i] = posz_tmp
        pir[i] = pir_tmp
    end
    local lowest_i = 1
    for i=2, 5 do
        if(pir[i] < pir[lowest_i]) then
            lowest_i = i
        end
    end
    local ret = (type(doCreateMonster("Zombie Event", {x=posx[lowest_i], y=posy[lowest_i], z=posz[lowest_i]}, false)) == 'number')
    if(ret) then
        addZombiesCount()
    end
    return ret
end
 
Last edited:
Is this a simple script? I found another forum where there is a script that works automatically for TFS 0.4, and more experienced people said it works fine.


As I understand it, this tag is responsible for starting the event automatically.
Lua:
<globalevent name="Zombie_Start" interval="60000" event="script">
 
i want add time like 19:00,
New Script working good, but 0 player in event and Start with more zombie more spam monster
just need fix code like no one player in event, get off
<globalevent name="zombie_event" time="15:59" script="onsay.lua"/>
Lua:
function onTime(interval)
local players_on_arena_count = #getZombiesEventPlayers()

local function start()
setZombiesEventPlayersLimit(players_on_arena_count )
addZombiesEventBlockEnterPosition()
doSetStorage(ZE_STATUS, 2)
doBroadcastMessage("Zombie Arena Event started")
return true
end
setZombiesEventPlayersLimit(35)
doBroadcastMessage("Zombie Event Is Waiting For " .. getZombiesEventPlayersLimit() - players_on_arena_count .. " To Join.Zombie Will Start In 3 Minutes")
removeZombiesEventBlockEnterPosition()
addEvent(start,3*60*1000)
doSetStorage(ZE_STATUS, 1)
return true
end
 
Lua:
function onTime(interval)
    local players_on_arena_count = #getZombiesEventPlayers()

    local function start()
        setZombiesEventPlayersLimit(players_on_arena_count)
        addZombiesEventBlockEnterPosition()
        doSetStorage(ZE_STATUS, 2)
        doBroadcastMessage("Zombie Arena Event started")
        return true
    end

    -- Check if there are no players in the event
    if players_on_arena_count == 0 then
        -- Set the number of players to start the event
        local desiredPlayers = 35
        setZombiesEventPlayersLimit(desiredPlayers)
        doBroadcastMessage("Zombie Event is waiting for " .. desiredPlayers .. " players to join. Zombie will start in 3 minutes.")
        removeZombiesEventBlockEnterPosition()
        addEvent(start, 3 * 60 * 1000)
        doSetStorage(ZE_STATUS, 1)
        return true
    end

    return interval
end

or

Lua:
function onTime(interval)
    local players_on_arena_count = #getZombiesEventPlayers()

    local function start()
        setZombiesEventPlayersLimit(players_on_arena_count)
        addZombiesEventBlockEnterPosition()
        doSetStorage(ZE_STATUS, 2)
        doBroadcastMessage("Zombie Arena Event started")
        return true
    end

    -- Set event start time to 19:00 (server time)
    local desiredHour = 19
    local currentHour = tonumber(os.date("%H"))

   -- Checks that it is the correct time to start the event and that there are no players in the event
    if currentHour == desiredHour and players_on_arena_count == 0 then
      -- Set the number of players to start the event
        local desiredPlayers = 35
        setZombiesEventPlayersLimit(desiredPlayers)
        doBroadcastMessage("Zombie Event is waiting for " .. desiredPlayers .. " players to join. Zombie will start in 3 minutes.")
        removeZombiesEventBlockEnterPosition()
        addEvent(start, 3 * 60 * 1000)
        doSetStorage(ZE_STATUS, 1)
        return true
    end

    return interval
end

Lua:
<globalevent name="zombie_event" time="19:00" script="onsay.lua"/>

I don't know if it will work
 
If there are no players in the event, wait until the next break

Lua:
function onTime(interval)
    local players_on_arena_count = #getZombiesEventPlayers()

    local function start()
        setZombiesEventPlayersLimit(players_on_arena_count)
        addZombiesEventBlockEnterPosition()
        doSetStorage(ZE_STATUS, 2)
        doBroadcastMessage("Zombie Arena Event started")
        return true
    end

    
    local desiredHour = 19
    local currentHour = tonumber(os.date("%H"))

  
    if currentHour == desiredHour and players_on_arena_count > 0 then
        setZombiesEventPlayersLimit(players_on_arena_count)
        addZombiesEventBlockEnterPosition()
        doSetStorage(ZE_STATUS, 2)
        doBroadcastMessage("Zombie Arena Event started")
        return true
    end

  
    if players_on_arena_count == 0 then
        return interval
    end

  
    local desiredPlayers = 35
    setZombiesEventPlayersLimit(desiredPlayers)
    doBroadcastMessage("Zombie Event is waiting for " .. desiredPlayers .. " players to join. Zombie will start in 3 minutes.")
    removeZombiesEventBlockEnterPosition()
    addEvent(start, 3 * 60 * 1000)
    doSetStorage(ZE_STATUS, 1)

    return true
end
 
why you add time in script?
i`m use
<globalevent name="zombie_event" time="19:00" script="onsay.lua"/>
we never test with time in script, becouse when i add 19:02 < get erro
Remove timer from script
local desiredHour = 19
i can`t test it < its no open with timer globalevent :S
event is no open
 
Last edited:
why you add time in script?
i`m use
<globalevent name="zombie_event" time="19:00" script="onsay.lua"/>
we never test with time in script, becouse when i add 19:02 < get erro
Remove timer from script
local desiredHour = 19
i can`t test it < its no open with timer globalevent :S
event is no open
Sorry, I added the time function in the script. I removed the time function and kept the rest of the script. It should work now


It has to be a player to test, don't test with your own GOD or GM account, just with normal players.
Lua:
function onTime(interval)
    local players_on_arena_count = #getZombiesEventPlayers()

    local function start()
        setZombiesEventPlayersLimit(players_on_arena_count)
        addZombiesEventBlockEnterPosition()
        doSetStorage(ZE_STATUS, 2)
        doBroadcastMessage("Zombie Arena Event started")
        return true
    end

  
    if players_on_arena_count == 0 then
      
        local desiredPlayers = 35
        setZombiesEventPlayersLimit(desiredPlayers)
        doBroadcastMessage("Zombie Event is waiting for " .. desiredPlayers .. " players to join. Zombie will start in 3 minutes.")
        removeZombiesEventBlockEnterPosition()
        addEvent(start, 3 * 60 * 1000)
        doSetStorage(ZE_STATUS, 1)
        return true
    end

    return interval
end
 
event is start auto, im no join with gm or character.
but he start after 3 min no one join.
So, for example, if no one joins, the event will be canceled and take place in the next hour or day. Is this what you want? Or wait more than 3 minutes if no one comes in, and even a few more minutes. If no one enters, it is automatically canceled and rescheduled for the next time/day?
Post automatically merged:

Lua:
local eventScheduled = false  -- Variable to control if the event is scheduled
local eventStarted = false  -- Variable to control whether the event was started

function onTime(interval)
    local players_on_arena_count = #getZombiesEventPlayers()

    local function start()
        setZombiesEventPlayersLimit(players_on_arena_count)
        addZombiesEventBlockEnterPosition()
        doSetStorage(ZE_STATUS, 2)
        doBroadcastMessage("Zombie Arena Event started")
        eventStarted = true
        return true
    end

    
    if eventStarted then
        return interval 
    end

  
    if players_on_arena_count == 0 then
        
        if not eventScheduled then
          
            local desiredPlayers = 35
            setZombiesEventPlayersLimit(desiredPlayers)
            doBroadcastMessage("Zombie Event is waiting for " .. desiredPlayers .. " players to join. Zombie will start in 3 minutes.")
            removeZombiesEventBlockEnterPosition()
            addEvent(start, 3 * 60 * 1000)
            doSetStorage(ZE_STATUS, 1)
            eventScheduled = true  -- Event is scheduled
        end
    else
       -- If there are players in the event, cancel the scheduled event
        if eventScheduled then
            cancelEvent(start)  -- Cancels the scheduled event
            eventScheduled = false  -- Event is no longer scheduled
        end
    end

    return interval
end
 
Last edited:
Friend, yesterday I already sent a link to another forum where the scripts are working fine. You could have taken some of these scripts and tested them on your server. They are bug free and work well, including automatic functionality. There is a system for dealing with players who have nothing, canceling the event and scheduling it for the next hour or another day, for example.
 
Back
Top