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

Zombie Event TFS 1.5, Zombie dont teleport the player when hit

Knutte

New Member
Joined
Jan 4, 2024
Messages
10
Reaction score
0
Hello,
Im using @Snavy Zombie event for me TFS 1.5 server with some small changes.
Thread

zombie.lua
Lua:
local function secondsToReadable(s)
    local hours   = math.floor(s / 3600)
    local minutes = math.floor((s % 3600) / 60)  --- Changed from original
    local seconds = math.floor(s % 60)  ---- Changed from original
    return (hours   > 0 and (hours   .. ' hour'   .. (hours   > 1 and 's ' or ' ')) or '') ..
           (minutes > 0 and (minutes .. ' minute' .. (minutes > 1 and 's ' or ' ')) or '') ..
           (seconds > 0 and (seconds .. ' second' .. (seconds > 1 and 's ' or ' ')) or '')
end

local zombie = {}
-- keeps track of players & zombies
zombie.players = {}
zombie.zombies = {}
--#
zombie.config  = {
    startTime = '15:32:00', -- Hours:minutes:seconds
    -- How many players needed to start the event.
    minimumPlayers = 2,
    -- How many players can enter at most.
    maximumPlayers = 10,
    -- %chance of a player dying from zombie attack
    playerDeathChance = 20, -- %
    -- How many zombies should spawn in the beginning?
    zombieStartAmount = 5,
    -- Name of the monster to be spawned
    zombieName = 'zombski',
    -- This is used to check if zombie event has started.
    storageEventStarted = 191817,
    -- Position for the teleport which is going..
    -- ..to send players to the waiting room.
    teleportSpawnPosition = Position(32484, 32426, 8),
    waitingRoom = {
        topLeft     = Position(32476, 32408, 8),
        bottomRight = Position(32485, 32417, 8)
    },
    -- How long players will wait in the waiting room.
    waitingTime = 10, -- 10 seconds
    teleportId = 1387, -- ID of teleport item
    teleportActionId = 1071, -- action ID used on the teleport for detecting players
    -- Zombie arena; Where players will try to survive
    arena = {
        topLeft     = Position(32400, 32518, 7),
        bottomRight = Position(32417, 32535, 7)
    },
    -- set to `true` if you want the rewards..
    -- ..to be given randomly instead of all at once.
    randomReward = false,
    rewardBagId = 1987,
    rewards = {
        {2160, 1}, -- Crystal Coin
        {2159, 2}, -- Scarab Coin
        {9020, 5}  -- Vampire Token
    }
}
--#
zombie.initEvent = function(self)
    print("Initializing the Zombie Event...")
    local teleportItem = Game.createItem(self.config.teleportId, 1, self.config.teleportSpawnPosition)
    teleportItem:setActionId(self.config.teleportActionId)
    Teleport(teleportItem.uid):setDestination(Position(
        math.random(self.config.waitingRoom.topLeft.x, self.config.waitingRoom.bottomRight.x),
        math.random(self.config.waitingRoom.topLeft.y, self.config.waitingRoom.bottomRight.y),
        self.config.waitingRoom.topLeft.z
    ))
    Game.broadcastMessage('Zombie event will begin in, Hurry up!')
    addEvent(function(z)
        local tpTile = Tile(z.config.teleportSpawnPosition)
        local tpItem = tpTile:getItemById(z.config.teleportId)
        if tpItem then
            tpItem:remove()
        end
        if z:countPlayers() < z.config.minimumPlayers then
            Game.broadcastMessage('Zombie event shutting down... not enough players.', MESSAGE_STATUS_CONSOLE_RED)
            z:kickPlayers()
            return
        end
        z:startEvent()
    end, self.config.waitingTime * 1000, self)
end
--#
zombie.startEvent = function(self)
    print("Starting the Zombie Event...")
    Game.setStorageValue(self.config.storageEventStarted, 1)
    Game.broadcastMessage('Zombie event has begun, Good luck!')
    for _, player in pairs(self.players) do
        if player then
            player:teleportTo(Position(
                math.random(self.config.arena.topLeft.x, self.config.arena.bottomRight.x),
                math.random(self.config.arena.topLeft.y, self.config.arena.bottomRight.y),
                self.config.arena.topLeft.z
            ))
        end
    end
    for i = self.config.zombieStartAmount, 1, -1 do
        self:spawnZombie(Position(
            math.random(self.config.arena.topLeft.x, self.config.arena.bottomRight.x),
            math.random(self.config.arena.topLeft.y, self.config.arena.bottomRight.y),
            self.config.arena.topLeft.z
        ))
    end
end
--#
zombie.stopEvent = function(self)
    print("Stopping the Zombie Event...")
    Game.setStorageValue(self.config.storageEventStarted, -1)
    local winner = self:getWinner()
    if not winner then return end
    local depot = winner:getDepotChest(winner:getTown():getId(), true)
    local bag   = Game.createItem(self.config.rewardBagId, 1)
    local itemId = nil
    local itemCount = nil
    if self.config.randomReward then
        local randomRewardItem = self.config.rewards[math.random(1, #self.config.rewards)]
        itemId = randomRewardItem[1]
        itemCount = randomRewardItem[2]
        bag:addItemEx(Game.createItem(itemId, itemCount), INDEX_WHEREEVER, FLAG_NOLIMIT)
        depot:addItemEx(bag)
        winner:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Zombie] You have received a reward item. Check your depot.')
        return
    end
    for _, reward in pairs(self.config.rewards) do
        itemId = reward[1]
        itemCount = reward[2]
        bag:addItemEx(Game.createItem(itemId, itemCount), INDEX_WHEREEVER, FLAG_NOLIMIT)
    end
    depot:addItemEx(bag)
    winner:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Zombie] You have received reward items. Check your depot.')
    Game.broadcastMessage(winner:getName() .. ' has won zombie event.')
    zombie:kickPlayers()
    zombie:clearZombies()
end
--#
zombie.addPlayer = function(self, p)
    print("Adding player: " .. p:getName())
    self.players[p:getId()] = p
end
--#
zombie.removePlayer = function(self, player)
    print("Removing player: " .. player:getName())
    self.players[player:getId()] = nil
    player:teleportTo(player:getTown():getTemplePosition())
    player:addHealth(player:getMaxHealth())
    if self:countPlayers() == 1 then
        self:stopEvent()
    end
end
--#
zombie.countPlayers = function(self)
    local n = 0
    for _, player in pairs(self.players) do
        if player then n = n + 1 end
    end
        print("Counting players: ")
    return n
end
--#
zombie.kickPlayers = function(self)
    print("Kicking all players...")
    for _, player in pairs(self.players) do
        if player then
            self:removePlayer(player)
        end
    end
    self.players = {}
end
--#
zombie.getWinner = function(self)
    for _, player in pairs(self.players) do
        if player then
                    print("Winner: ")
            return player
        end
    end
    return nil
end
--#
zombie.clearZombies = function(self)
    print("Clearing all zombies...")
    for _, zombski in pairs(self.zombies) do
        if zombski then
            zombski:remove()
        end
    end
end
--#
zombie.spawnZombie = function(self, position)
    print("Spawning a zombie at position: ")
    local zombie = Game.createMonster(self.config.zombieName, position, false, true)
    self.zombies[zombie:getId()] = zombie
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
end
--#
local ge = GlobalEvent('zombieStart')
    print("Global event triggered at interval: ")
function ge.onTime(interval)
    local eventStorage = Game.getStorageValue(zombie.config.storageEventStarted)
    local hasStarted = (eventStorage and (eventStorage == 1)) or false
    if hasStarted then
        print('[Error - ZombieEvent:onTime] The event has already started.')
        return true
    end
    local tile = Tile(zombie.config.teleportSpawnPosition)
    if not tile then
        print('[Error - ZombieEvent:onTime] Could not create teleport, tile not found!')
        return true
    end
    zombie:initEvent()
    return true
end
ge:time(zombie.config.startTime)
ge:register()
--#
local enterZombie = MoveEvent('enterZombie')
function enterZombie.onStepIn(player, item, position, fromPosition)
    if not item:getId() == zombie.config.teleportId then
        return true
    end
    zombie:addPlayer(player)
       print(player:getName() .. " has entered the Zombie Event teleport.")
    Game.broadcastMessage(player:getName() .. ' has entered zombie event.', MESSAGE_STATUS_CONSOLE_RED)
    if zombie:countPlayers() >= zombie.config.maximumPlayers then
        Game.broadcastMessage('Zombie event will begin in a moment... Get ready!')
        addEvent(function() zombie:startEvent() end, 3 * 1000)
    end
    return true
end
enterZombie:aid(zombie.config.teleportActionId)
enterZombie:register()
--#
local eventCallback = EventCallback
function eventCallback.onTargetCombat(creature, target)
    print("eventcallback 1")
    if (not creature:isMonster())
    or (creature:getName():lower() ~= zombie.config.zombieName:lower())
    or (not target:isPlayer()) then
        print("eventcallback 2")
        return true
    end
    local deathChance = zombie.config.playerDeathChance
        print("deathchance 1")
    math.randomseed(os.time())
    if math.random(1, 100) <= deathChance then
        local targetPos = target:getPosition()
        targetPos:sendMagicEffect(CONST_ME_MORTAREA)
        targetPos:sendMagicEffect(CONST_ME_BIGPLANTS)
        target:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have been killed by a zombie.')
        zombie:spawnZombie(targetPos)
        zombie:removePlayer(target)
        return true
    end
        print("Combat event triggered between ")
    target:say('!survived!', TALKTYPE_MONSTER_SAY)
    target:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    return true
end
print("zombie register")
eventCallback:register(0)


I dont get eventCallback to print anything in the function and the Zombies does not teleport out the player when they hit it over and over.
i found a similar post with the same error as me, and that solution was to put this:
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
in event.xml
I already had it there and adding it didnt do anything for me execpt for showing up on two places in the same XML.

Any ideas whats wrong with the code? have i missed something?

The "Zombski's" is getting summon via Lua script, and i havent done a zombski.xml file since it worked anyway. I had it when i started testing this out and it still didnt work so i removed the XML since it did nothing. Do i need that Zombski.xml and need to add anything to it over the usual code thats in a monster.xml?
Zombski.lua file is unchange from what Snavy posted.
 
Last edited:
Hello,
Im using @Snavy Zombie event for me TFS 1.5 server with some small changes.
Thread

zombie.lua
Lua:
local function secondsToReadable(s)
    local hours   = math.floor(s / 3600)
    local minutes = math.floor((s % 3600) / 60)  --- Changed from original
    local seconds = math.floor(s % 60)  ---- Changed from original
    return (hours   > 0 and (hours   .. ' hour'   .. (hours   > 1 and 's ' or ' ')) or '') ..
           (minutes > 0 and (minutes .. ' minute' .. (minutes > 1 and 's ' or ' ')) or '') ..
           (seconds > 0 and (seconds .. ' second' .. (seconds > 1 and 's ' or ' ')) or '')
end

local zombie = {}
-- keeps track of players & zombies
zombie.players = {}
zombie.zombies = {}
--#
zombie.config  = {
    startTime = '15:32:00', -- Hours:minutes:seconds
    -- How many players needed to start the event.
    minimumPlayers = 2,
    -- How many players can enter at most.
    maximumPlayers = 10,
    -- %chance of a player dying from zombie attack
    playerDeathChance = 20, -- %
    -- How many zombies should spawn in the beginning?
    zombieStartAmount = 5,
    -- Name of the monster to be spawned
    zombieName = 'zombski',
    -- This is used to check if zombie event has started.
    storageEventStarted = 191817,
    -- Position for the teleport which is going..
    -- ..to send players to the waiting room.
    teleportSpawnPosition = Position(32484, 32426, 8),
    waitingRoom = {
        topLeft     = Position(32476, 32408, 8),
        bottomRight = Position(32485, 32417, 8)
    },
    -- How long players will wait in the waiting room.
    waitingTime = 10, -- 10 seconds
    teleportId = 1387, -- ID of teleport item
    teleportActionId = 1071, -- action ID used on the teleport for detecting players
    -- Zombie arena; Where players will try to survive
    arena = {
        topLeft     = Position(32400, 32518, 7),
        bottomRight = Position(32417, 32535, 7)
    },
    -- set to `true` if you want the rewards..
    -- ..to be given randomly instead of all at once.
    randomReward = false,
    rewardBagId = 1987,
    rewards = {
        {2160, 1}, -- Crystal Coin
        {2159, 2}, -- Scarab Coin
        {9020, 5}  -- Vampire Token
    }
}
--#
zombie.initEvent = function(self)
    print("Initializing the Zombie Event...")
    local teleportItem = Game.createItem(self.config.teleportId, 1, self.config.teleportSpawnPosition)
    teleportItem:setActionId(self.config.teleportActionId)
    Teleport(teleportItem.uid):setDestination(Position(
        math.random(self.config.waitingRoom.topLeft.x, self.config.waitingRoom.bottomRight.x),
        math.random(self.config.waitingRoom.topLeft.y, self.config.waitingRoom.bottomRight.y),
        self.config.waitingRoom.topLeft.z
    ))
    Game.broadcastMessage('Zombie event will begin in, Hurry up!')
    addEvent(function(z)
        local tpTile = Tile(z.config.teleportSpawnPosition)
        local tpItem = tpTile:getItemById(z.config.teleportId)
        if tpItem then
            tpItem:remove()
        end
        if z:countPlayers() < z.config.minimumPlayers then
            Game.broadcastMessage('Zombie event shutting down... not enough players.', MESSAGE_STATUS_CONSOLE_RED)
            z:kickPlayers()
            return
        end
        z:startEvent()
    end, self.config.waitingTime * 1000, self)
end
--#
zombie.startEvent = function(self)
    print("Starting the Zombie Event...")
    Game.setStorageValue(self.config.storageEventStarted, 1)
    Game.broadcastMessage('Zombie event has begun, Good luck!')
    for _, player in pairs(self.players) do
        if player then
            player:teleportTo(Position(
                math.random(self.config.arena.topLeft.x, self.config.arena.bottomRight.x),
                math.random(self.config.arena.topLeft.y, self.config.arena.bottomRight.y),
                self.config.arena.topLeft.z
            ))
        end
    end
    for i = self.config.zombieStartAmount, 1, -1 do
        self:spawnZombie(Position(
            math.random(self.config.arena.topLeft.x, self.config.arena.bottomRight.x),
            math.random(self.config.arena.topLeft.y, self.config.arena.bottomRight.y),
            self.config.arena.topLeft.z
        ))
    end
end
--#
zombie.stopEvent = function(self)
    print("Stopping the Zombie Event...")
    Game.setStorageValue(self.config.storageEventStarted, -1)
    local winner = self:getWinner()
    if not winner then return end
    local depot = winner:getDepotChest(winner:getTown():getId(), true)
    local bag   = Game.createItem(self.config.rewardBagId, 1)
    local itemId = nil
    local itemCount = nil
    if self.config.randomReward then
        local randomRewardItem = self.config.rewards[math.random(1, #self.config.rewards)]
        itemId = randomRewardItem[1]
        itemCount = randomRewardItem[2]
        bag:addItemEx(Game.createItem(itemId, itemCount), INDEX_WHEREEVER, FLAG_NOLIMIT)
        depot:addItemEx(bag)
        winner:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Zombie] You have received a reward item. Check your depot.')
        return
    end
    for _, reward in pairs(self.config.rewards) do
        itemId = reward[1]
        itemCount = reward[2]
        bag:addItemEx(Game.createItem(itemId, itemCount), INDEX_WHEREEVER, FLAG_NOLIMIT)
    end
    depot:addItemEx(bag)
    winner:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Zombie] You have received reward items. Check your depot.')
    Game.broadcastMessage(winner:getName() .. ' has won zombie event.')
    zombie:kickPlayers()
    zombie:clearZombies()
end
--#
zombie.addPlayer = function(self, p)
    print("Adding player: " .. p:getName())
    self.players[p:getId()] = p
end
--#
zombie.removePlayer = function(self, player)
    print("Removing player: " .. player:getName())
    self.players[player:getId()] = nil
    player:teleportTo(player:getTown():getTemplePosition())
    player:addHealth(player:getMaxHealth())
    if self:countPlayers() == 1 then
        self:stopEvent()
    end
end
--#
zombie.countPlayers = function(self)
    local n = 0
    for _, player in pairs(self.players) do
        if player then n = n + 1 end
    end
        print("Counting players: ")
    return n
end
--#
zombie.kickPlayers = function(self)
    print("Kicking all players...")
    for _, player in pairs(self.players) do
        if player then
            self:removePlayer(player)
        end
    end
    self.players = {}
end
--#
zombie.getWinner = function(self)
    for _, player in pairs(self.players) do
        if player then
                    print("Winner: ")
            return player
        end
    end
    return nil
end
--#
zombie.clearZombies = function(self)
    print("Clearing all zombies...")
    for _, zombski in pairs(self.zombies) do
        if zombski then
            zombski:remove()
        end
    end
end
--#
zombie.spawnZombie = function(self, position)
    print("Spawning a zombie at position: ")
    local zombie = Game.createMonster(self.config.zombieName, position, false, true)
    self.zombies[zombie:getId()] = zombie
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
end
--#
local ge = GlobalEvent('zombieStart')
    print("Global event triggered at interval: ")
function ge.onTime(interval)
    local eventStorage = Game.getStorageValue(zombie.config.storageEventStarted)
    local hasStarted = (eventStorage and (eventStorage == 1)) or false
    if hasStarted then
        print('[Error - ZombieEvent:onTime] The event has already started.')
        return true
    end
    local tile = Tile(zombie.config.teleportSpawnPosition)
    if not tile then
        print('[Error - ZombieEvent:onTime] Could not create teleport, tile not found!')
        return true
    end
    zombie:initEvent()
    return true
end
ge:time(zombie.config.startTime)
ge:register()
--#
local enterZombie = MoveEvent('enterZombie')
function enterZombie.onStepIn(player, item, position, fromPosition)
    if not item:getId() == zombie.config.teleportId then
        return true
    end
    zombie:addPlayer(player)
       print(player:getName() .. " has entered the Zombie Event teleport.")
    Game.broadcastMessage(player:getName() .. ' has entered zombie event.', MESSAGE_STATUS_CONSOLE_RED)
    if zombie:countPlayers() >= zombie.config.maximumPlayers then
        Game.broadcastMessage('Zombie event will begin in a moment... Get ready!')
        addEvent(function() zombie:startEvent() end, 3 * 1000)
    end
    return true
end
enterZombie:aid(zombie.config.teleportActionId)
enterZombie:register()
--#
local eventCallback = EventCallback
function eventCallback.onTargetCombat(creature, target)
    print("eventcallback 1")
    if (not creature:isMonster())
    or (creature:getName():lower() ~= zombie.config.zombieName:lower())
    or (not target:isPlayer()) then
        print("eventcallback 2")
        return true
    end
    local deathChance = zombie.config.playerDeathChance
        print("deathchance 1")
    math.randomseed(os.time())
    if math.random(1, 100) <= deathChance then
        local targetPos = target:getPosition()
        targetPos:sendMagicEffect(CONST_ME_MORTAREA)
        targetPos:sendMagicEffect(CONST_ME_BIGPLANTS)
        target:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have been killed by a zombie.')
        zombie:spawnZombie(targetPos)
        zombie:removePlayer(target)
        return true
    end
        print("Combat event triggered between ")
    target:say('!survived!', TALKTYPE_MONSTER_SAY)
    target:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    return true
end
print("zombie register")
eventCallback:register(0)


I dont get eventCallback to print anything in the function and the Zombies does not teleport out the player when they hit it over and over.
i found a similar post with the same error as me, and that solution was to put this:
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
in event.xml
I already had it there and adding it didnt do anything for me execpt for showing up on two places in the same XML.

Any ideas whats wrong with the code? have i missed something?

The "Zombski's" is getting summon via Lua script, and i havent done a zombski.xml file since it worked anyway. I had it when i started testing this out and it still didnt work so i removed the XML since it did nothing. Do i need that Zombski.xml and need to add anything to it over the usual code thats in a monster.xml?
Zombski.lua file is unchange from what Snavy posted.
Hello, you found solution of to this? i have same problem with monster is not teleport attack of me thanks
 
can somebody share the zombie event map pls?

Looks like you open your map with RME or equivalent software, make a room (however you like) and set the arena coordinates yourself:
Lua:
arena = {
        topLeft     = Position(61, 388, 7),
        bottomRight = Position(74, 395, 7)
    }

Seems like a funny event, lots of possibilities
Post automatically merged:

Hello, you found solution of to this? i have same problem with monster is not teleport attack of me thanks
seems like it's easy to test, spawn a zombski and see what events fire, I'm new so I have no idea how to obtain a client for the latest version to test so i'm using otclient and TFS 1.4.2.
 
i was looking for the otb file but nvm i found it
Post automatically merged:

Hello,
Im using @Snavy Zombie event for me TFS 1.5 server with some small changes.
Thread

zombie.lua
Lua:
local function secondsToReadable(s)
    local hours   = math.floor(s / 3600)
    local minutes = math.floor((s % 3600) / 60)  --- Changed from original
    local seconds = math.floor(s % 60)  ---- Changed from original
    return (hours   > 0 and (hours   .. ' hour'   .. (hours   > 1 and 's ' or ' ')) or '') ..
           (minutes > 0 and (minutes .. ' minute' .. (minutes > 1 and 's ' or ' ')) or '') ..
           (seconds > 0 and (seconds .. ' second' .. (seconds > 1 and 's ' or ' ')) or '')
end

local zombie = {}
-- keeps track of players & zombies
zombie.players = {}
zombie.zombies = {}
--#
zombie.config  = {
    startTime = '15:32:00', -- Hours:minutes:seconds
    -- How many players needed to start the event.
    minimumPlayers = 2,
    -- How many players can enter at most.
    maximumPlayers = 10,
    -- %chance of a player dying from zombie attack
    playerDeathChance = 20, -- %
    -- How many zombies should spawn in the beginning?
    zombieStartAmount = 5,
    -- Name of the monster to be spawned
    zombieName = 'zombski',
    -- This is used to check if zombie event has started.
    storageEventStarted = 191817,
    -- Position for the teleport which is going..
    -- ..to send players to the waiting room.
    teleportSpawnPosition = Position(32484, 32426, 8),
    waitingRoom = {
        topLeft     = Position(32476, 32408, 8),
        bottomRight = Position(32485, 32417, 8)
    },
    -- How long players will wait in the waiting room.
    waitingTime = 10, -- 10 seconds
    teleportId = 1387, -- ID of teleport item
    teleportActionId = 1071, -- action ID used on the teleport for detecting players
    -- Zombie arena; Where players will try to survive
    arena = {
        topLeft     = Position(32400, 32518, 7),
        bottomRight = Position(32417, 32535, 7)
    },
    -- set to `true` if you want the rewards..
    -- ..to be given randomly instead of all at once.
    randomReward = false,
    rewardBagId = 1987,
    rewards = {
        {2160, 1}, -- Crystal Coin
        {2159, 2}, -- Scarab Coin
        {9020, 5}  -- Vampire Token
    }
}
--#
zombie.initEvent = function(self)
    print("Initializing the Zombie Event...")
    local teleportItem = Game.createItem(self.config.teleportId, 1, self.config.teleportSpawnPosition)
    teleportItem:setActionId(self.config.teleportActionId)
    Teleport(teleportItem.uid):setDestination(Position(
        math.random(self.config.waitingRoom.topLeft.x, self.config.waitingRoom.bottomRight.x),
        math.random(self.config.waitingRoom.topLeft.y, self.config.waitingRoom.bottomRight.y),
        self.config.waitingRoom.topLeft.z
    ))
    Game.broadcastMessage('Zombie event will begin in, Hurry up!')
    addEvent(function(z)
        local tpTile = Tile(z.config.teleportSpawnPosition)
        local tpItem = tpTile:getItemById(z.config.teleportId)
        if tpItem then
            tpItem:remove()
        end
        if z:countPlayers() < z.config.minimumPlayers then
            Game.broadcastMessage('Zombie event shutting down... not enough players.', MESSAGE_STATUS_CONSOLE_RED)
            z:kickPlayers()
            return
        end
        z:startEvent()
    end, self.config.waitingTime * 1000, self)
end
--#
zombie.startEvent = function(self)
    print("Starting the Zombie Event...")
    Game.setStorageValue(self.config.storageEventStarted, 1)
    Game.broadcastMessage('Zombie event has begun, Good luck!')
    for _, player in pairs(self.players) do
        if player then
            player:teleportTo(Position(
                math.random(self.config.arena.topLeft.x, self.config.arena.bottomRight.x),
                math.random(self.config.arena.topLeft.y, self.config.arena.bottomRight.y),
                self.config.arena.topLeft.z
            ))
        end
    end
    for i = self.config.zombieStartAmount, 1, -1 do
        self:spawnZombie(Position(
            math.random(self.config.arena.topLeft.x, self.config.arena.bottomRight.x),
            math.random(self.config.arena.topLeft.y, self.config.arena.bottomRight.y),
            self.config.arena.topLeft.z
        ))
    end
end
--#
zombie.stopEvent = function(self)
    print("Stopping the Zombie Event...")
    Game.setStorageValue(self.config.storageEventStarted, -1)
    local winner = self:getWinner()
    if not winner then return end
    local depot = winner:getDepotChest(winner:getTown():getId(), true)
    local bag   = Game.createItem(self.config.rewardBagId, 1)
    local itemId = nil
    local itemCount = nil
    if self.config.randomReward then
        local randomRewardItem = self.config.rewards[math.random(1, #self.config.rewards)]
        itemId = randomRewardItem[1]
        itemCount = randomRewardItem[2]
        bag:addItemEx(Game.createItem(itemId, itemCount), INDEX_WHEREEVER, FLAG_NOLIMIT)
        depot:addItemEx(bag)
        winner:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Zombie] You have received a reward item. Check your depot.')
        return
    end
    for _, reward in pairs(self.config.rewards) do
        itemId = reward[1]
        itemCount = reward[2]
        bag:addItemEx(Game.createItem(itemId, itemCount), INDEX_WHEREEVER, FLAG_NOLIMIT)
    end
    depot:addItemEx(bag)
    winner:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, '[Zombie] You have received reward items. Check your depot.')
    Game.broadcastMessage(winner:getName() .. ' has won zombie event.')
    zombie:kickPlayers()
    zombie:clearZombies()
end
--#
zombie.addPlayer = function(self, p)
    print("Adding player: " .. p:getName())
    self.players[p:getId()] = p
end
--#
zombie.removePlayer = function(self, player)
    print("Removing player: " .. player:getName())
    self.players[player:getId()] = nil
    player:teleportTo(player:getTown():getTemplePosition())
    player:addHealth(player:getMaxHealth())
    if self:countPlayers() == 1 then
        self:stopEvent()
    end
end
--#
zombie.countPlayers = function(self)
    local n = 0
    for _, player in pairs(self.players) do
        if player then n = n + 1 end
    end
        print("Counting players: ")
    return n
end
--#
zombie.kickPlayers = function(self)
    print("Kicking all players...")
    for _, player in pairs(self.players) do
        if player then
            self:removePlayer(player)
        end
    end
    self.players = {}
end
--#
zombie.getWinner = function(self)
    for _, player in pairs(self.players) do
        if player then
                    print("Winner: ")
            return player
        end
    end
    return nil
end
--#
zombie.clearZombies = function(self)
    print("Clearing all zombies...")
    for _, zombski in pairs(self.zombies) do
        if zombski then
            zombski:remove()
        end
    end
end
--#
zombie.spawnZombie = function(self, position)
    print("Spawning a zombie at position: ")
    local zombie = Game.createMonster(self.config.zombieName, position, false, true)
    self.zombies[zombie:getId()] = zombie
    position:sendMagicEffect(CONST_ME_MAGIC_RED)
end
--#
local ge = GlobalEvent('zombieStart')
    print("Global event triggered at interval: ")
function ge.onTime(interval)
    local eventStorage = Game.getStorageValue(zombie.config.storageEventStarted)
    local hasStarted = (eventStorage and (eventStorage == 1)) or false
    if hasStarted then
        print('[Error - ZombieEvent:onTime] The event has already started.')
        return true
    end
    local tile = Tile(zombie.config.teleportSpawnPosition)
    if not tile then
        print('[Error - ZombieEvent:onTime] Could not create teleport, tile not found!')
        return true
    end
    zombie:initEvent()
    return true
end
ge:time(zombie.config.startTime)
ge:register()
--#
local enterZombie = MoveEvent('enterZombie')
function enterZombie.onStepIn(player, item, position, fromPosition)
    if not item:getId() == zombie.config.teleportId then
        return true
    end
    zombie:addPlayer(player)
       print(player:getName() .. " has entered the Zombie Event teleport.")
    Game.broadcastMessage(player:getName() .. ' has entered zombie event.', MESSAGE_STATUS_CONSOLE_RED)
    if zombie:countPlayers() >= zombie.config.maximumPlayers then
        Game.broadcastMessage('Zombie event will begin in a moment... Get ready!')
        addEvent(function() zombie:startEvent() end, 3 * 1000)
    end
    return true
end
enterZombie:aid(zombie.config.teleportActionId)
enterZombie:register()
--#
local eventCallback = EventCallback
function eventCallback.onTargetCombat(creature, target)
    print("eventcallback 1")
    if (not creature:isMonster())
    or (creature:getName():lower() ~= zombie.config.zombieName:lower())
    or (not target:isPlayer()) then
        print("eventcallback 2")
        return true
    end
    local deathChance = zombie.config.playerDeathChance
        print("deathchance 1")
    math.randomseed(os.time())
    if math.random(1, 100) <= deathChance then
        local targetPos = target:getPosition()
        targetPos:sendMagicEffect(CONST_ME_MORTAREA)
        targetPos:sendMagicEffect(CONST_ME_BIGPLANTS)
        target:sendTextMessage(MESSAGE_EVENT_ADVANCE, 'You have been killed by a zombie.')
        zombie:spawnZombie(targetPos)
        zombie:removePlayer(target)
        return true
    end
        print("Combat event triggered between ")
    target:say('!survived!', TALKTYPE_MONSTER_SAY)
    target:getPosition():sendMagicEffect(CONST_ME_HOLYAREA)
    return true
end
print("zombie register")
eventCallback:register(0)


I dont get eventCallback to print anything in the function and the Zombies does not teleport out the player when they hit it over and over.
i found a similar post with the same error as me, and that solution was to put this:
XML:
<event class="Creature" method="onTargetCombat" enabled="1" />
in event.xml
I already had it there and adding it didnt do anything for me execpt for showing up on two places in the same XML.

Any ideas whats wrong with the code? have i missed something?

The "Zombski's" is getting summon via Lua script, and i havent done a zombski.xml file since it worked anyway. I had it when i started testing this out and it still didnt work so i removed the XML since it did nothing. Do i need that Zombski.xml and need to add anything to it over the usual code thats in a monster.xml?
Zombski.lua file is unchange from what Snavy posted.
same issue here i have capture the flag event, ingame too don't know is this is causing the error i haven ontarget enabled to 1 in events.xml
Lua:
function Creature:onTargetCombat(target)
    local player = Player(self)
    if player and target and CTF_STATUS == 2 then
        if isGreenTeam(player:getName()) and isGreenTeam(target:getName()) then
            return false
        elseif isRedTeam(player:getName()) and isRedTeam(target:getName()) then
            return false
        end
    end

    if hasEventCallback(EVENT_CALLBACK_ONTARGETCOMBAT) then
        return EventCallback(EVENT_CALLBACK_ONTARGETCOMBAT, self, target)
    else
        return RETURNVALUE_NOERROR
    end
end

function Cr
 

Attachments

  • zombie_atualizado.rar
    23.5 KB · Views: 5 · VirusTotal
Last edited:
Back
Top