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

Solved Zombie event need help with small fix

therrax

Member
Joined
Jul 12, 2012
Messages
262
Solutions
1
Reaction score
11
Hi.
Information: TFS 0.3.7 [8.6]

I am using this Zombie Event:
http://otland.net/threads/zombie-event-new-version-bug-free-updated.128664/

My problem.
When someone enter to the Zombie Event it works correctly, but when starts and there is no participants it doesn't stop event. Then it rightly print this error:
Code:
[23:13:41.431] [Error - GlobalEvent Interface]
[23:13:41.431] data/globalevents/scripts/zombie/onthink.lua:onThink
[23:13:41.431] Description:
[23:13:41.431] (LuaInterface::luaDoCreateMonster) Cannot create monster: Zombie
Event

How can I stop the event?

My scripts [not all but i think these need to change]:
globalevents/scripts/onthink.lua:
Code:
function onThink(interval, lastExecution, thinkInterval)
if(getStorage(ZE_STATUS) == 2) then
setZombiesToSpawnCount(getZombiesToSpawnCount()+1)
local players = getZombiesEventPlayers()
for i=1, getZombiesToSpawnCount() * 2 do
if(getZombiesToSpawnCount() > 0 and spawnNewZombie()) then
setZombiesToSpawnCount(getZombiesToSpawnCount()-1)
end
end
end
return true
end

lib/zombie_event.lua:
Code:
-- CONFIG
ZE_DEFAULT_NUMBER_OF_PLAYERS = 20
ZE_ACCESS_TO_IGNORE_ARENA = 3
-- POSITIONS
ZE_blockEnterItemPosition = {x = 767, y = 988, z = 7}
ZE_enterPosition = {x = 656, y = 909, z = 10}
ZE_kickPosition = {x = 1046, y = 1001, z = 6}
ZE_spawnFromPosition = {x = 633, y = 894, z = 10}
ZE_spawnToPosition = {x = 678, y = 926, z = 10}
-- ITEM IDS
ZE_blockEnterItemID = 2700
-- 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], stackpos = 253})) == 'number')
    if(ret) then
        addZombiesCount()
    end
    return ret
end
creaturescripts/scripts/onthink.lua
Code:
function onThink(cid)
local target = getCreatureTarget(cid)
if(target ~= 0 and not isPlayer(target)) then
doRemoveCreature(target)
end
return true
end
 
How do you let the event start? From reading the scripts it only starts if the global storage value from ZE_STATUS is 2 and this happens if it reaches the player amount in of players entering the event or when you use a talkaction.
 
@Limos Thanks for your message.
By zombieauto.lua in global added with interval:
Code:
local autoStartsTable = {
{["day_of_week"] = 0, ["hour"] = 11, ["minute"] = 00, ["storage"] = 7862},
{["day_of_week"] = 0, ["hour"] = 19, ["minute"] = 00, ["storage"] = 7863},
{["day_of_week"] = 0, ["hour"] = 22, ["minute"] = 00, ["storage"] = 7864},
{["day_of_week"] = 0, ["hour"] = 00, ["minute"] = 00, ["storage"] = 7865},
{["day_of_week"] = 0, ["hour"] = 02, ["minute"] = 00, ["storage"] = 7866},
{["day_of_week"] = 1, ["hour"] = 11, ["minute"] = 00, ["storage"] = 7867},
{["day_of_week"] = 1, ["hour"] = 19, ["minute"] = 00, ["storage"] = 7868},
{["day_of_week"] = 6, ["hour"] = 02, ["minute"] = 00, ["storage"] = 7896}
}

function shouldExecuteEvent(configTable)
for _, config in pairs(configTable) do
if(tonumber(os.date("%d")) ~= getStorage(config.storage) and tonumber(os.date("%w")) == config.day_of_week) then
if(tonumber(os.date("%H")) == config.hour and tonumber(os.date("%M")) == config.minute) then
doSetStorage(config.storage, tonumber(os.date("%d")))
return true
end
end
end
return false
end

function onThink(interval, lastExecution, thinkInterval)
if(shouldExecuteEvent(autoStartsTable)) then
if(getStorage(ZE_STATUS) ~= 1 and getStorage(ZE_STATUS) ~= 2) then
removeZombiesEventBlockEnterPosition()
doSetStorage(ZE_STATUS, 1)
doBroadcastMessage("Zombie Arena Event teleport will be open for 2 minutes. We are waiting for " .. getZombiesEventPlayersLimit() - #getZombiesEventPlayers() .. " players to start.")
addEvent(startArenaEvent, 120 * 1000)
end
end
return true
end

function startArenaEvent()
if(getStorage(ZE_STATUS) == 1) then
addZombiesEventBlockEnterPosition()
doSetStorage(ZE_STATUS, 2)
doBroadcastMessage("Zombie Arena Event started.")
end
end
 
Code:
function startArenaEvent()
     if getStorage(ZE_STATUS) == 1 then
         if #getZombiesEventPlayers() > 1 then
             addZombiesEventBlockEnterPosition()
             doSetStorage(ZE_STATUS, 2)
             doBroadcastMessage("Zombie Arena Event started.")
         else
             doBroadcastMessage("Zombie Arena Event did not start because there where not enough players.")
             doSetStorage(ZE_STATUS, 0)
         end
     end
end
 
Code:
function startArenaEvent()
     if getStorage(ZE_STATUS) == 1 then
         if #getZombiesEventPlayers() > 1 then
             addZombiesEventBlockEnterPosition()
             doSetStorage(ZE_STATUS, 2)
             doBroadcastMessage("Zombie Arena Event started.")
         else
             doBroadcastMessage("Zombie Arena Event did not start because there where not enough players.")
             doSetStorage(ZE_STATUS, 0)
         end
     end
end
I checked now this script I have problem again.
When 1 player enter to the event it should kick him after waiting time. But player is still inside event.
Then I changed it
Code:
if #getZombiesEventPlayers() > 1 then
to
Code:
if #getZombiesEventPlayers() >= 1 then
but I have errors:
1 player inside active arena
Code:
> Broadcasted message: "Zombie Arena Event started.".

[20:48:12.608] [Error - GlobalEvent Interface]
[20:48:12.608] data/globalevents/scripts/zombie/onthink.lua:onThink
[20:48:12.608] Description:
[20:48:12.608] (LuaInterface::luaDoCreateMonster) Cannot create monster: Zombie
Event
> Broadcasted message: "Zombie arena event finished! No one win?!?!?! WTF!".
 
You can use isInRange and getPlayerOnline.
Add under else and change the positions.
Code:
for _, cid in ipairs(getPlayersOnline()) do
     if isInRange(getPlayerPosition(cid), {x = 1000, y = 1000, z = 7}, {x = 1010, y = 1010, z = 7}) then
         doTeleportThing(cid, {x = 100, y = 100, z = 7})
     end
end
Keep it to > 1.
 
Back
Top