• 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.X+ Problem with a creaturescript when players dead.

Eduardo170

Well-Known Member
Joined
Jan 7, 2014
Messages
422
Solutions
3
Reaction score
66
Location
Caracas, Venezuela
This script works, but when you die outside the event, this does the same as if you died inside.
I think it is a storage problem or maybe it have to add a room range. I don't know.

Source: NEW Zombie Event [TFS 1.x] (https://otland.net/threads/new-zombie-event-tfs-1-x.239287/)

Code:
function onDeath(monster, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    -- Send text and effect
    monster:say("I WILL BE BACK!", TALKTYPE_MONSTER_YELL)
    monster:getPosition():sendMagicEffect(CONST_ME_MORTAREA)

    -- Remove zombie count, when it dies
    Game.setStorageValue(ze_zombieCountGlobalStorage, getZombieEventZombieCount() - 1)

    -- Store player kills
    local killerId = killer:getId()
    if zombieKillCount[killerId] ~= nil then
        zombieKillCount[killerId] = zombieKillCount[killerId] + 1
    else
        zombieKillCount[killerId] = 1
    end

    return true
end

function onPrepareDeath(player, killer)
    -- Remove player from count
    local count = getZombieEventJoinedCount()
    Game.setStorageValue(ze_joinCountGlobalStorage, count - 1)

    -- Reset player after death
    player:teleportTo(player:getTown():getTemplePosition())
    player:setStorageValue(ze_joinStorage, 0)
    player:addHealth(player:getMaxHealth())
    player:addMana(player:getMaxMana())
    player:unregisterEvent("ZombiePlayerDeath")

    -- Let's reward the 3 last players
    if count <= 3 then
        local playerName =  player:getName()

        local trophy = ze_trophiesTable[count]
        local item = player:addItem(trophy.itemid, 1)
        if item then
            item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, string.format("%s %s\n%s.", playerName, trophy.description, os.date("%x")))
        end

        -- Store kill count and remove from table to avoid memory leak
        local playerId, killCount = player:getId(), 0
        if zombieKillCount[playerId] ~= nil then
            killCount = zombieKillCount[playerId]
            zombieKillCount[playerId] = nil
        end

        -- Broadcast
        Game.broadcastMessage(string.format("%d place goes to %s of Zombie Event versus %d Zombies and slained %d Zombies.", count, playerName, getZombieEventZombieCount(), killCount))

        -- The last player died, let's reset the event
        if count <= 1 then
            resetZombieEvent()
        end
    end

    return false
end
 
You didn't add a room range as in the script setup?
You should change waiting room x y z and zombie arena x y z
 
You didn't add a room range as in the script setup?
You should change waiting room x y z and zombie arena x y z
Yes I did, but I don't know why if you left the event, and you keep dying, it sends you to the temple and shows you the message
Yes, but I don't know why if you left the event, and you keep dying, it sends you to the temple and shows you the message
I WILL BE BACK!

monster:say("I WILL BE BACK!", TALKTYPE_MONSTER_YELL)
 
paste zombieEvent.lua file
I don't know why if you die outside the event, you keep doing the same thing, and while I remove it, doesn't bother me.
PD: I try to change storages, but still.


Code:
-- Store player kills
if zombieKillCount == nil then
    zombieKillCount = {}
end

-- Zombie Variables
ze_zombieName = "Zombie" -- Zombie name
ze_timeToStartInvasion = 30 -- When should the first zombie be summoned [seconds]
ze_zombieSpawnInerval = 5 -- The interval of each zombie that will get summoned
ze_zombieMaxSpawn = 20 -- Max zombies in the arena
ze_zombieCountGlobalStorage = 100 -- Use empty global storage

-- Player Variables
ze_joinStorage = 2350 -- Storage that will be added, when player join
ze_minPlayers = 1 -- Minimum players that have to join
ze_maxPlayers = 50 -- Maxnimum players that can join
ze_joinCountGlobalStorage = 2352 -- Use empty global storage

-- States
ze_stateGlobalStorage = 2353 -- Use empty global storage
ze_EVENT_CLOSED = 0
ze_EVENT_STATE_STARTUP = 1
ze_EVENT_STARTED = 2

-- Waiting room
ze_WaitingRoomStartPosition = Position(641, 1830, 7) -- Where should player be teleport in waiting room
ze_waitingRoomCenterPosition = Position(641, 1830, 7) -- Center of the waiting room
ze_waitingRoomRadiusX = 5 -- Depends how big the arena room is 25sqm to x
ze_waitingRoomRadiusY = 5 -- Depends how big the arena room is 25sqm to y

-- Zombie arena
ze_zombieArenaStartPosition = Position(619, 1965, 7) -- When even start where should player be teleported in the zombie arena?
ze_arenaCenterPosition = Position(619, 1965, 7) -- Center position of the arena
ze_arenaFromPosition = Position(598, 1954, 7) -- Pos of top left corner
ze_arenaToPosition = Position(641, 1978, 7) -- Pos of bottom right corner
ze_arenaRoomRadiusX = 20 -- Depends how big the arena room is 50sqm to x
ze_arenaRoomRadiusY = 11 -- Depends how big the arena room is 50sqm to y
ze_arenaRoomMultifloor = false -- Does the arena have more floors than one?

-- Other variables
ze_waitTime = 5 -- How long until the event begin?
ze_createTeleportPosition = Position(999, 995, 7) -- Where should the teleport be created?
ze_teleportActionId = 7000 -- Actionid of the teleport
ze_trophiesTable = {
    [1] = {itemid = 7369, description = "won first place on Zombie Event."},
    [2] = {itemid = 7370, description = "won second place on Zombie Event."},
    [3] = {itemid = 7371, description = "won third place on Zombie Event."}
}

-- Get methods
function getZombieEventZombieCount()
    return Game.getStorageValue(ze_zombieCountGlobalStorage)
end

function getZombieEventJoinedCount()
    return Game.getStorageValue(ze_joinCountGlobalStorage)
end

function setZombieEventState(value)
    Game.setStorageValue(ze_stateGlobalStorage, value)
end

function getZombieEventState()
    return Game.getStorageValue(ze_stateGlobalStorage) or ze_EVENT_CLOSED
end

function resetZombieEvent()
    -- Reset variables
    Game.setStorageValue(ze_zombieCountGlobalStorage, 0)
    Game.setStorageValue(ze_joinCountGlobalStorage, 0)
    setZombieEventState(ze_EVENT_CLOSED)

    -- Clear the arena from zombies
    local spectator = Game.getSpectators(ze_arenaCenterPosition, ze_arenaRoomMultifloor, false, 0, ze_arenaRoomRadiusX, 0, ze_arenaRoomRadiusY)
    for i = 1, #spectator do
        if spectator[i]:isMonster() then
            spectator[i]:remove()
        end
    end
end

function startZombieEvent()
    local spectator = Game.getSpectators(ze_waitingRoomCenterPosition, ze_arenaRoomMultifloor, false, 0, ze_waitingRoomRadiusX, 0, ze_waitingRoomRadiusY)
    if getZombieEventJoinedCount() < ze_minPlayers then
        for i = 1, #spectator do
            spectator[i]:teleportTo(spectator[i]:getTown():getTemplePosition())
            spectator[i]:setStorageValue(ze_joinStorage, 0)
        end

        resetZombieEvent()
        Game.broadcastMessage("Zombie event failed to start, due to not enough of participants.")
    else
        for i = 1, #spectator do
            spectator[i]:teleportTo(ze_zombieArenaStartPosition)
            spectator[i]:registerEvent("ZombiePlayerDeath")
        end

        Game.broadcastMessage("Zombie Event has started, good luck to all participants.")
        setZombieEventState(ze_EVENT_STARTED)
        addEvent(startZombieInvasion, ze_timeToStartInvasion * 1000)
    end

    -- Remove Teleport
    local item = Tile(ze_createTeleportPosition):getItemById(1387)
    if item:isTeleport() then
        item:remove()
    end
end

function startZombieInvasion()
    if getZombieEventState() == ze_EVENT_STARTED then
        local random = math.random
        local zombie = Game.createMonster(ze_zombieName, Position(random(ze_arenaFromPosition.x, ze_arenaToPosition.x), random(ze_arenaFromPosition.y, ze_arenaToPosition.y), random(ze_arenaFromPosition.z, ze_arenaToPosition.z)))
        if zombie then
            Game.setStorageValue(ze_zombieCountGlobalStorage, getZombieEventZombieCount() + 1)
        end

        addEvent(startZombieInvasion, ze_zombieSpawnInerval * 1000)
    end
end

function Player.joinZombieEvent(self)
    -- Set storage and teleport
    self:teleportTo(ze_WaitingRoomStartPosition)
    ze_WaitingRoomStartPosition:sendMagicEffect(CONST_ME_TELEPORT)
    self:setStorageValue(ze_joinStorage, 1)

    -- Add count and broadcast
    local count = getZombieEventJoinedCount()
    Game.setStorageValue(ze_joinCountGlobalStorage, count + 1)
    Game.broadcastMessage(string.format("%s has joined the Zombie Event! [%d/%d].", self:getName(), count + 1, ze_maxPlayers))
end

function setupZombieEvent(minPlayers, maxPlayers, waitTime)
    -- Event is not closed, then stop from start new one
    if getZombieEventState() ~= ze_EVENT_CLOSED then
        return
    end

    -- Create teleport and set the respective action id
    local item = Game.createItem(1387, 1, ze_createTeleportPosition)
    if item:isTeleport() then
        item:setAttribute(ITEM_ATTRIBUTE_ACTIONID, ze_teleportActionId)
    end

    -- Change the variables, to the new ones
    ze_minPlayers = minPlayers
    ze_maxPlayers = maxPlayers
    ze_waitTime = waitTime

    -- Set the counts, state, broadcast and delay the start of the event.
    Game.setStorageValue(ze_zombieCountGlobalStorage, 0)
    Game.setStorageValue(ze_joinCountGlobalStorage, 0)
    setZombieEventState(ze_EVENT_STATE_STARTUP)
    Game.broadcastMessage(string.format("The Zombie Event has started! The event require atleast %d and max %d players, you have %d minutes to join.", minPlayers, maxPlayers, waitTime))
    addEvent(startZombieEvent, waitTime * 60 * 1000)
end
From
1iHt1ST.png

to
4tNwNoT.png
 
Last edited:
Try change this
Code:
function onDeath(monster, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    -- Send text and effect
    monster:say("I WILL BE BACK!", TALKTYPE_MONSTER_YELL)
    monster:getPosition():sendMagicEffect(CONST_ME_MORTAREA)

    -- Remove zombie count, when it dies
    Game.setStorageValue(ze_zombieCountGlobalStorage, getZombieEventZombieCount() - 1)

    -- Store player kills
    local killerId = killer:getId()
    if zombieKillCount[killerId] ~= nil then
        zombieKillCount[killerId] = zombieKillCount[killerId] + 1
    else
        zombieKillCount[killerId] = 1
    end

    return true
end

to this:

Code:
function onDeath(monster, corpse, killer, mostDamage, unjustified, mostDamage_unjustified)
    -- Send text and effect
    if isMonster() then
    monster:say("I WILL BE BACK!", TALKTYPE_MONSTER_YELL)
    monster:getPosition():sendMagicEffect(CONST_ME_MORTAREA)

    -- Remove zombie count, when it dies
    Game.setStorageValue(ze_zombieCountGlobalStorage, getZombieEventZombieCount() - 1)

    -- Store player kills
    local killerId = killer:getId()
    if zombieKillCount[killerId] ~= nil then
        zombieKillCount[killerId] = zombieKillCount[killerId] + 1
    else
        zombieKillCount[killerId] = 1
    end

    return true
    end
end
 
Monsters
Still bug, Now, if you died for some monster from my server,its send you to the temple without loss anything..

PVP
Never die
It causes the server to fall.
Code:
Lua Script Error: [CreatureScript Interface]
data/creaturescripts/scripts/zombie_arena/zombieEventDeath.lua:onPrepareDeath
...reaturescripts/scripts/zombie_arena/zombieEventDeath.lua:25: attempt to perform arithmetic on local 'count' (a nil value)
stack traceback:
        [C]: in function '__sub'
        ...reaturescripts/scripts/zombie_arena/zombieEventDeath.lua:25: in function <...reaturescripts/scripts/zombie_arena/zombieEventDeath.lua:22>
        [C]: at 0x7ff77920eb00
 
Lua:
local count = getZombieEventJoinedCount()
Game.setStorageValue(ze_joinCountGlobalStorage, count - 1)

Your error points to this line. "count" varaible is nil which means it's either not finding the getZombieEventJoinedCount() function or that function is returning nil.
 
Back
Top