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

Snowball tfs 1.5 Problem

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
217
Reaction score
15
GitHub
Jarek123
Hello Guys I use Tfs 1.5 Tibia 8.60 And I have problem because to teleport players from waiting room to event map and I have error in console
Like that

Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
attempt to index a nil value
stack traceback:
        [C]: at 0x55d042be5ce0
        [C]: in function 'teleportTo'
        data/globalevents/scripts/events/SnowBall_Event.lua:12: in function <data/globalevents/scripts/events/SnowBall_Event.lua:1>

My scripts is

Code:
-- This script is part of Snow Ball War
-- Copyright by Ciroc Developer
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

-- //

SnowBall_Configurations = {
    Event_Duration = 1, -- Minutos de duraçăo do jogo.
    Event_WaitGame = 3, -- Minutos de espera para o inicio do jogo, dentro da sala.
    Event_MinPlayers = 2, -- Minimo de jogadores para o jogo começar, caso contrário, o jogo é cancelado.
    Event_GainPoint = 1, -- Ganho de pontos a cada acerto no jogo.
    Event_LostPoints = 1, -- Perca de pontos a cada morte no jogo. // Para desativar, valor = 0.
    Event_Days = {1, 2, 3, 4, 5, 6, 7}, -- Dias que irá ocorrer o evento (seguindo a ordem de 1 = domingo, 7 = sabado)

    Area_Configurations = {
        Area_Arena = {{x = 38859, y = 59, z = 7}, {x = 38870, y = 84, z = 7}}, -- Area da arena do jogo, ({Canto Superior Esquerdo}, {Canto Inferior Direito})
        Position_WaitRoom = {x = 38820, y = 60, z = 7}, -- Posiçăo da sala de espera do jogo
        Position_ExitWaitRoom = {x = 160, y = 54, z = 7}, -- Posiçăo do teleport que sairá da sala de espera do jogo
        Position_EventTeleport = {x = 158, y = 49, z = 7}, -- Posiçăo de onde será criado o teleport para os participantes irem para a sala de espera.
    },

    Ammo_Configurations = {
        Ammo_Price = 1, -- Preço da municaçăo em pontos do jogo.
        Ammo_Ammount = 100, -- Quantidade de ganho a cada compra.
        Ammo_Start = 100, -- Quantidade de municaçăo de cada jogador ao inicio do jogo.
        Ammo_Restart = 100, -- Quantidade de municaçăo do jogador, caso ele morra. // Caso queira desativar, valor = 0.
        Ammo_Speed = 150, -- Velocidade de cada tiro
        Ammo_Infinity = true, -- Se as muniçőes serăo infinitas ou năo (True / False)
        Ammo_Exhaust = 1, -- Segundos de espera para utilizar novamente o comando !snowball atirar
        Ammo_Distance = 5, -- Quantidade de tiles que o tiro irá alcançars
    },

    Positions_Rewards = {
        [1] = { -- Prémios do primeiro lugar
            [2160] = 100,
            [2152] = 1,
        },
        [2] = { -- Prémios do segundo lugar
            [2160] = 50,
        },
        [3] = { -- Prémios do terceiro lugar
            [2160] = 10,
        },
        --[[ Caso queira adicionar prémios para outras posiçőes basta seguir o exemplo:
        [Posiçăo] = {
            [Item_ID] = Item_Ammount,
        },
        ]]--
    },
}

-- ################# SnowBall Functions -- Por favor, năo mexer. Desenvolvido inteiramente por Tony Araújo (OrochiElf) ################# --
CACHE_GAMEPLAYERS = {}
CACHE_GAMEAREAPOSITIONS = {}

function loadEvent()
    print("[SnowBall Event]: Carregando a area da arena.")
    for newX = SnowBall_Configurations.Area_Configurations.Area_Arena[1].x, SnowBall_Configurations.Area_Configurations.Area_Arena[2].x do
        for newY = SnowBall_Configurations.Area_Configurations.Area_Arena[1].y, SnowBall_Configurations.Area_Configurations.Area_Arena[2].y do
            local AreaPos = {x = newX, y = newY, z = SnowBall_Configurations.Area_Configurations.Area_Arena[1].z}
            if getTileThingByPos(AreaPos).itemid == 0 then
                print("[SnowBall Event]: Houve um problema ao carregar a posicao (x = " .. AreaPos.x .. " - y = " .. AreaPos.y .." - z = " .. AreaPos.z .. ") da arena do evento, por favor verifique as condicoes.")
                return false
            elseif isWalkable(AreaPos) then
                table.insert(CACHE_GAMEAREAPOSITIONS, AreaPos)
            end
        end
    end
    print("[SnowBall Event]: Carregamento da area da arena concluido com sucesso.")

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_WaitRoom).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicao da sala de espera, por favor verifique as condicoes.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicao do teleport da sala de espera, por favor verifique as condicoes.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_EventTeleport).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicoo para criaçao do teleport do evento, por favor verifique as condicoes.")
        return false
    end

    print("[SnowBall Event]: Carregamento do evento concluido com sucesso.")
    return true
end

local sampleConfigs = {
    [0] = {dirPos = {x = 0, y = -1}},
    [1] = {dirPos = {x = 1, y = 0}},
    [2] = {dirPos = {x = 0, y = 1}},
    [3] = {dirPos = {x = -1, y = 0}},
}

local iced_Corpses = {
    [0] = {
        [0] = {7303},
        [1] = {7306},
        [2] = {7303},
        [3] = {7306},
    },
    [1] = {
        [0] = {7305, 7307, 7309, 7311},
        [1] = {7308, 7310, 7312},
        [2] = {7305, 7307, 7309, 7311},
        [3] = {7308, 7310, 7312},
    },
}

function Event_sendSnowBall(cid, pos, rounds, dir)
    local player = Player(cid)

    if rounds == 0 then
        return true
    end

    if player then
        local sampleCfg = sampleConfigs[dir]

        if sampleCfg then
            local newPos = Position(pos.x + sampleCfg.dirPos.x, pos.y + sampleCfg.dirPos.y, pos.z)

            if isWalkable(newPos) then
                if Tile(newPos):getTopCreature() then
                    local killed = Tile(newPos):getTopCreature()

                    if Player(killed:getId()) then
                        if iced_Corpses[killed:getSex()] then
                            local killed_corpse = iced_Corpses[killed:getSex()][killed:getDirection()][math.random(1, #iced_Corpses[killed:getSex()][killed:getDirection()])]

                            Game.createItem(killed_corpse, 1, killed:getPosition())
                            local item = Item(getTileItemById(killed:getPosition(), killed_corpse).uid)
                            addEvent(function() item:remove(1) end, 3000)
                        end

                        killed:getPosition():sendMagicEffect(3)
                        killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
                        killed:getPosition():sendMagicEffect(50)
                        killed:setStorageValue(10109, killed:getStorageValue(10109) - SnowBall_Configurations.Event_LostPoints)
                        killed:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Restart)
                        killed:sendTextMessage(29, "Vocę acabou ser acertado pelo jogador " .. player:getName() .. " e perdeu -" .. SnowBall_Configurations.Event_LostPoints .." ponto(s).\nTotal de: " .. killed:getStorageValue(10109) .. " ponto(s)")

                        player:setStorageValue(10109, player:getStorageValue(10109) + SnowBall_Configurations.Event_GainPoint)
                        player:sendTextMessage(29, "Vocę acabou de acertar o jogador " .. killed:getName() .. " e ganhou +" .. SnowBall_Configurations.Event_GainPoint .." ponto(s).\nTotal de: " .. player:getStorageValue(10109) .. " ponto(s)")

                        if(CACHE_GAMEPLAYERS[2] == player:getId()) and player:getStorageValue(10109) >= Player(CACHE_GAMEPLAYERS[1]):getStorageValue(10109) then
                            player:getPosition():sendMagicEffect(7)
                            player:sendTextMessage(29, "Vocę agora é o lider do ranking do SnowBall, parabéns!")
                            Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
                            Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, "Vocę acaba de perder a primeira colocaçăo!")
                        end

                        table.sort(CACHE_GAMEPLAYERS, function(a, b) return Player(a):getStorageValue(10109) > Player(b):getStorageValue(10109) end)
                    else

                        newPos:sendMagicEffect(3)
                    end
                    return true
                end

                pos:sendDistanceEffect(newPos, 13)
                pos = newPos
                return addEvent(Event_sendSnowBall, SnowBall_Configurations.Ammo_Configurations.Ammo_Speed, player:getId(), pos, rounds - 1, dir)
            end

            newPos:sendMagicEffect(3)
            return true
        end
    end
    return true
end

function Event_endGame()
    local str = "       ## -> SnowBall Ranking <- ##\n\n"

    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SnowBall_Configurations.Positions_Rewards[rank] then
            for item_id, item_ammount in pairs(SnowBall_Configurations.Positions_Rewards[rank]) do

                Player(players):addItem(item_id, item_ammount)
            end
        end

        str = str .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " ponto(s)\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):showTextDialog(2111, str)
    end

    broadcastMessage("[Snowball Event]: O evento terminou.")
    return true
end

function isWalkable(pos) --- New Function by Tony Araújo (OrochiElf)
    for i = 0, 255 do
        pos.stackpos = i

        local item = Item(getTileThingByPos(pos).uid)
        if item ~= nil then
            if item:hasProperty(2) or item:hasProperty(3) or item:hasProperty(7) then
                return false
            end
        end
    end
    return true
end

function isInArena(player)
    local pos = player:getPosition()

    if pos.z == SnowBall_Configurations.Area_Configurations.Area_Arena[1].z then
        if pos.x >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].x and pos.y >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].y then
            if pos.x <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].x and pos.y <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].y then
                return true
            end
        end
    end
    return false
end
Can help me ?please
Post automatically merged:

and no remove teleport from temple;/
 
Last edited:
Try replacing:
Lua:
killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])


for:

Lua:
if killed and killed:isPlayer() then
    killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
end
 
is the same
Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
attempt to index a nil value
stack traceback:
        [C]: at 0x55936597cce0
        [C]: in function 'teleportTo'
        data/globalevents/scripts/events/SnowBall_Event.lua:12: in function <data/globalevents/scripts/events/SnowBall_Event.lua:1>
I Thing is something wrong line 199

Code:
 Player(players):teleportTo(Player(players):getTown():getTemplePosition())
Post automatically merged:

Can you help me?
 
Last edited:
lib
Lua:
-- This script is part of Snow Ball War
-- Copyright by Ciroc Developer
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program.  If not, see <http://www.gnu.org/licenses/>.

-- //

SnowBall_Configurations = {
    Event_Duration = 1, -- Minutos de duraçăo do jogo.
    Event_WaitGame = 3, -- Minutos de espera para o inicio do jogo, dentro da sala.
    Event_MinPlayers = 2, -- Minimo de jogadores para o jogo começar, caso contrário, o jogo é cancelado.
    Event_GainPoint = 1, -- Ganho de pontos a cada acerto no jogo.
    Event_LostPoints = 1, -- Perca de pontos a cada morte no jogo. // Para desativar, valor = 0.
    Event_Days = {1, 2, 3, 4, 5, 6, 7}, -- Dias que irá ocorrer o evento (seguindo a ordem de 1 = domingo, 7 = sabado)

    Area_Configurations = {
        Area_Arena = {{x = 38859, y = 59, z = 7}, {x = 38870, y = 84, z = 7}}, -- Area da arena do jogo, ({Canto Superior Esquerdo}, {Canto Inferior Direito})
        Position_WaitRoom = {x = 38820, y = 60, z = 7}, -- Posiçăo da sala de espera do jogo
        Position_ExitWaitRoom = {x = 160, y = 54, z = 7}, -- Posiçăo do teleport que sairá da sala de espera do jogo
        Position_EventTeleport = {x = 158, y = 49, z = 7}, -- Posiçăo de onde será criado o teleport para os participantes irem para a sala de espera.
    },

    Ammo_Configurations = {
        Ammo_Price = 1, -- Preço da municaçăo em pontos do jogo.
        Ammo_Ammount = 100, -- Quantidade de ganho a cada compra.
        Ammo_Start = 100, -- Quantidade de municaçăo de cada jogador ao inicio do jogo.
        Ammo_Restart = 100, -- Quantidade de municaçăo do jogador, caso ele morra. // Caso queira desativar, valor = 0.
        Ammo_Speed = 150, -- Velocidade de cada tiro
        Ammo_Infinity = true, -- Se as muniçőes serăo infinitas ou năo (True / False)
        Ammo_Exhaust = 1, -- Segundos de espera para utilizar novamente o comando !snowball atirar
        Ammo_Distance = 5, -- Quantidade de tiles que o tiro irá alcançars
    },

    Positions_Rewards = {
        [1] = { -- Prémios do primeiro lugar
            [2160] = 100,
            [2152] = 1,
        },
        [2] = { -- Prémios do segundo lugar
            [2160] = 50,
        },
        [3] = { -- Prémios do terceiro lugar
            [2160] = 10,
        },
        --[[ Caso queira adicionar prémios para outras posiçőes basta seguir o exemplo:
        [Posiçăo] = {
            [Item_ID] = Item_Ammount,
        },
        ]]--
    },
}

-- ################# SnowBall Functions -- Por favor, năo mexer. Desenvolvido inteiramente por Tony Araújo (OrochiElf) ################# --
CACHE_GAMEPLAYERS = {}
CACHE_GAMEAREAPOSITIONS = {}

function loadEvent()
    print("[SnowBall Event]: Carregando a area da arena.")
    for newX = SnowBall_Configurations.Area_Configurations.Area_Arena[1].x, SnowBall_Configurations.Area_Configurations.Area_Arena[2].x do
        for newY = SnowBall_Configurations.Area_Configurations.Area_Arena[1].y, SnowBall_Configurations.Area_Configurations.Area_Arena[2].y do
            local AreaPos = {x = newX, y = newY, z = SnowBall_Configurations.Area_Configurations.Area_Arena[1].z}
            if getTileThingByPos(AreaPos).itemid == 0 then
                print("[SnowBall Event]: Houve um problema ao carregar a posicao (x = " .. AreaPos.x .. " - y = " .. AreaPos.y .." - z = " .. AreaPos.z .. ") da arena do evento, por favor verifique as condicoes.")
                return false
            elseif isWalkable(AreaPos) then
                table.insert(CACHE_GAMEAREAPOSITIONS, AreaPos)
            end
        end
    end
    print("[SnowBall Event]: Carregamento da area da arena concluido com sucesso.")

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_WaitRoom).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicao da sala de espera, por favor verifique as condicoes.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicao do teleport da sala de espera, por favor verifique as condicoes.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_EventTeleport).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicoo para criaçao do teleport do evento, por favor verifique as condicoes.")
        return false
    end

    print("[SnowBall Event]: Carregamento do evento concluido com sucesso.")
    return true
end

local sampleConfigs = {
    [0] = {dirPos = {x = 0, y = -1}},
    [1] = {dirPos = {x = 1, y = 0}},
    [2] = {dirPos = {x = 0, y = 1}},
    [3] = {dirPos = {x = -1, y = 0}},
}

local iced_Corpses = {
    [0] = {
        [0] = {7303},
        [1] = {7306},
        [2] = {7303},
        [3] = {7306},
    },
    [1] = {
        [0] = {7305, 7307, 7309, 7311},
        [1] = {7308, 7310, 7312},
        [2] = {7305, 7307, 7309, 7311},
        [3] = {7308, 7310, 7312},
    },
}

function Event_sendSnowBall(cid, pos, rounds, dir)
    local player = Player(cid)

    if rounds == 0 then
        return true
    end

    if player then
        local sampleCfg = sampleConfigs[dir]

        if sampleCfg then
            local newPos = Position(pos.x + sampleCfg.dirPos.x, pos.y + sampleCfg.dirPos.y, pos.z)

            if isWalkable(newPos) then
                if Tile(newPos):getTopCreature() then
                    local killed = Tile(newPos):getTopCreature()

                    if Player(killed:getId()) then
                        if iced_Corpses[killed:getSex()] then
                            local killed_corpse = iced_Corpses[killed:getSex()][killed:getDirection()][math.random(1, #iced_Corpses[killed:getSex()][killed:getDirection()])]

                            Game.createItem(killed_corpse, 1, killed:getPosition())
                            local item = Item(getTileItemById(killed:getPosition(), killed_corpse).uid)
                            addEvent(function() item:remove(1) end, 3000)
                        end

                        killed:getPosition():sendMagicEffect(3)
                        if killed and killed:isPlayer() then
    killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
end
                        killed:getPosition():sendMagicEffect(50)
                        killed:setStorageValue(10109, killed:getStorageValue(10109) - SnowBall_Configurations.Event_LostPoints)
                        killed:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Restart)
                        killed:sendTextMessage(29, "Vocę acabou ser acertado pelo jogador " .. player:getName() .. " e perdeu -" .. SnowBall_Configurations.Event_LostPoints .." ponto(s).\nTotal de: " .. killed:getStorageValue(10109) .. " ponto(s)")

                        player:setStorageValue(10109, player:getStorageValue(10109) + SnowBall_Configurations.Event_GainPoint)
                        player:sendTextMessage(29, "Vocę acabou de acertar o jogador " .. killed:getName() .. " e ganhou +" .. SnowBall_Configurations.Event_GainPoint .." ponto(s).\nTotal de: " .. player:getStorageValue(10109) .. " ponto(s)")

                        if(CACHE_GAMEPLAYERS[2] == player:getId()) and player:getStorageValue(10109) >= Player(CACHE_GAMEPLAYERS[1]):getStorageValue(10109) then
                            player:getPosition():sendMagicEffect(7)
                            player:sendTextMessage(29, "Vocę agora é o lider do ranking do SnowBall, parabéns!")
                            Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
                            Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, "Vocę acaba de perder a primeira colocaçăo!")
                        end

                        table.sort(CACHE_GAMEPLAYERS, function(a, b) return Player(a):getStorageValue(10109) > Player(b):getStorageValue(10109) end)
                    else

                        newPos:sendMagicEffect(3)
                    end
                    return true
                end

                pos:sendDistanceEffect(newPos, 13)
                pos = newPos
                return addEvent(Event_sendSnowBall, SnowBall_Configurations.Ammo_Configurations.Ammo_Speed, player:getId(), pos, rounds - 1, dir)
            end

            newPos:sendMagicEffect(3)
            return true
        end
    end
    return true
end

function Event_endGame()
    local str = "       ## -> SnowBall Ranking <- ##\n\n"

    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SnowBall_Configurations.Positions_Rewards[rank] then
            for item_id, item_ammount in pairs(SnowBall_Configurations.Positions_Rewards[rank]) do

                Player(players):addItem(item_id, item_ammount)
            end
        end

        str = str .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " ponto(s)\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):showTextDialog(2111, str)
    end

    broadcastMessage("[Snowball Event]: O evento terminou.")
    return true
end

function isWalkable(pos) --- New Function by Tony Araújo (OrochiElf)
    for i = 0, 255 do
        pos.stackpos = i

        local item = Item(getTileThingByPos(pos).uid)
        if item ~= nil then
            if item:hasProperty(2) or item:hasProperty(3) or item:hasProperty(7) then
                return false
            end
        end
    end
    return true
end

function isInArena(player)
    local pos = player:getPosition()

    if pos.z == SnowBall_Configurations.Area_Configurations.Area_Arena[1].z then
        if pos.x >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].x and pos.y >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].y then
            if pos.x <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].x and pos.y <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].y then
                return true
            end
        end
    end
    return false
end
globalevents
Code:
function startGame(rounds)
    if rounds == 0 then
        if #CACHE_GAMEPLAYERS < SnowBall_Configurations.Event_MinPlayers then
            for _, players in ipairs(CACHE_GAMEPLAYERS) do
                Player(players):teleportTo(Player(players):getTown():getTemplePosition())
            end
            broadcastMessage("[Snowball Event]: O evento foi cancelado por conta de năo ter no minimo ".. SnowBall_Configurations.Event_MinPlayers.." jogadores.")
        else
            for _, players in ipairs(CACHE_GAMEPLAYERS) do
                Player(players):setStorageValue(10109, 0)
                Player(players):setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Start)
                Player(players):teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
            end
            broadcastMessage("[Snowball Event]: O evento foi fechado. O jogo começou.")
            addEvent(Event_endGame, SnowBall_Configurations.Event_Duration * 60 * 1000)
        end

        Item(getTileItemById(SnowBall_Configurations.Area_Configurations.Position_EventTeleport, 1387).uid):remove(1)
        Item(getTileItemById(SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom, 1387).uid):remove(1)
        return true
    end

    if #CACHE_GAMEPLAYERS < SnowBall_Configurations.Event_MinPlayers then
        broadcastMessage("[Snowball Event]: Faltam ".. rounds .. " minuto(s) e " .. SnowBall_Configurations.Event_MinPlayers - #CACHE_GAMEPLAYERS .." jogador(es) para o jogo começar.")
    else
        broadcastMessage("[Snowball Event]: Faltam ".. rounds .. " minuto(s) para o jogo começar.")
    end
    return addEvent(startGame, 60 * 1000, rounds - 1)
end

function onTime(interval)
    if not SnowBall_Configurations.Event_Days[os.date("%w") + 1] then
        return true
    end

    CACHE_GAMEPLAYERS = {}

    local EventTeleport = Game.createItem(1387, 1, SnowBall_Configurations.Area_Configurations.Position_EventTeleport)
    EventTeleport:setActionId(10101)

    local ExitWaitRoom = Game.createItem(1387, 1, SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom)
    ExitWaitRoom:setActionId(10102)

    broadcastMessage("[Snowball Event]: O evento foi aberto, vá até o templo para participar.")
    addEvent(startGame, 60 * 1000, SnowBall_Configurations.Event_WaitGame)
    return true
end
Post automatically merged:

any one?guys
 
Last edited:
Lua:
Player(players):teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])

It tries to teleport players to a random position within CACHE_GAMEAREAPOSITIONS. The error could be due to:

Player(players) returning nil.
The random position from CACHE_GAMEAREAPOSITIONS being nil.

Id suggest you to add nil checks and prints to your code to identify where the problem occurs:
Lua:
for _, players in ipairs(CACHE_GAMEPLAYERS) do
    local playerObj = Player(players)
    if playerObj then
        playerObj:setStorageValue(10109, 0)
        playerObj:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Start)
        local randomPos = CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)]
        if randomPos then
            playerObj:teleportTo(randomPos)
        else
            print("Error: Random position is nil for player ID: " .. players)
        end
    else
        print("Error: Player(players) returned nil for player ID: " .. players)
    end
end

These prints will, probably, show you where the issue is. You can post the result here if you want and I'll try to help you again.
 
Last edited:
So where I have add this ?

This:
Lua:
for _, players in ipairs(CACHE_GAMEPLAYERS) do
    Player(players):setStorageValue(10109, 0)
    Player(players):setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Start)
    Player(players):teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
end

To this:
Code:
for _, players in ipairs(CACHE_GAMEPLAYERS) do
    local playerObj = Player(players)
    if playerObj then
        playerObj:setStorageValue(10109, 0)
        playerObj:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Start)
        local randomPos = CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)]
        if randomPos then
            playerObj:teleportTo(randomPos)
        else
            print("Error: Random position is nil for player ID: " .. players)
        end
    else
        print("Error: Player(players) returned nil for player ID: " .. players)
    end
end

Do what was causing the error again and check the logs.
 
in data/logs donthave nothing but in console is error

Lua:
Error: Random position is nil for player ID: 268435472
Error: Random position is nil for player ID: 268435473
Yea sorry, by logs I meant console.

So now you know that the problem is that your code is not receiving the random positions that should come from CACHE_GAMEAREAPOSITIONS, and it doesn't know where to teleport players.

By any chance you have this in your console?

Houve um problema ao carregar a posicao (x = " .. AreaPos.x .. " - y = " .. AreaPos.y .." - z = " .. AreaPos.z .. ") da arena do evento, por favor verifique as condicoes.")

Or any other similar message.
 
Only this one

Lua:
> Broadcasted message: "[Snowball Event]: O evento foi aberto, v� at� o templo para participar.".
Jarpen has logged out.
Rrrrrrr has logged in.
> Broadcasted message: "[Snowball Event]: Faltam 3 minuto(s) e 1 jogador(es) para o jogo come�ar.".
Emanienko has logged in.
> Broadcasted message: "[Snowball Event]: Faltam 2 minuto(s) para o jogo come�ar.".
> Broadcasted message: "[Snowball Event]: Faltam 1 minuto(s) para o jogo come�ar.".
Error: Random position is nil for player ID: 268435472
Error: Random position is nil for player ID: 268435473
> Broadcasted message: "[Snowball Event]: O evento foi fechado. O jogo come�ou.".
> Broadcasted message: "[Snowball Event]: O evento terminou.".

Error: Random position is nil for player ID: 268435472
Error: Random position is nil for player ID: 268435473
;/
 
Did you set the Area_Configuration position correctly?

Lua:
    Area_Configurations = {
        Area_Arena = {{x = 38859, y = 59, z = 7}, {x = 38870, y = 84, z = 7}}, -- Area da arena do jogo, ({Canto Superior Esquerdo}, {Canto Inferior Direito})
        Position_WaitRoom = {x = 38820, y = 60, z = 7}, -- Posiçăo da sala de espera do jogo
        Position_ExitWaitRoom = {x = 160, y = 54, z = 7}, -- Posiçăo do teleport que sairá da sala de espera do jogo
        Position_EventTeleport = {x = 158, y = 49, z = 7}, -- Posiçăo de onde será criado o teleport para os participantes irem para a sala de espera.
    },
 
try..
Lua:
SnowBall_Configurations = {
    Event_Duration = 1, -- Minutos de duraçăo do jogo.
    Event_WaitGame = 3, -- Minutos de espera para o inicio do jogo, dentro da sala.
    Event_MinPlayers = 2, -- Minimo de jogadores para o jogo começar, caso contrário, o jogo é cancelado.
    Event_GainPoint = 1, -- Ganho de pontos a cada acerto no jogo.
    Event_LostPoints = 1, -- Perca de pontos a cada morte no jogo. -- Para desativar, valor = 0.
    Event_Days = {1, 2, 3, 4, 5, 6, 7}, -- Dias que irá ocorrer o evento (seguindo a ordem de 1 = domingo, 7 = sabado)

    Area_Configurations = {
        Area_Arena = {{x = 38859, y = 59, z = 7}, {x = 38870, y = 84, z = 7}}, -- Area da arena do jogo, ({Canto Superior Esquerdo}, {Canto Inferior Direito})
        Position_WaitRoom = {x = 38820, y = 60, z = 7}, -- Posiçăo da sala de espera do jogo
        Position_ExitWaitRoom = {x = 160, y = 54, z = 7}, -- Posiçăo do teleport que sairá da sala de espera do jogo
        Position_EventTeleport = {x = 158, y = 49, z = 7}, -- Posiçăo de onde será criado o teleport para os participantes irem para a sala de espera.
    },

    Ammo_Configurations = {
        Ammo_Price = 1, -- Preço da municaçăo em pontos do jogo.
        Ammo_Ammount = 100, -- Quantidade de ganho a cada compra.
        Ammo_Start = 100, -- Quantidade de municaçăo de cada jogador ao inicio do jogo.
        Ammo_Restart = 100, -- Quantidade de municaçăo do jogador, caso ele morra. -- Caso queira desativar, valor = 0.
        Ammo_Speed = 150, -- Velocidade de cada tiro
        Ammo_Infinity = true, -- Se as muniçőes serăo infinitas ou năo (True / False)
        Ammo_Exhaust = 1, -- Segundos de espera para utilizar novamente o comando !snowball atirar
        Ammo_Distance = 5, -- Quantidade de tiles que o tiro irá alcançars
    },

    Positions_Rewards = {
        [1] = { -- Prémios do primeiro lugar
            [2160] = 100,
            [2152] = 1,
        },
        [2] = { -- Prémios do segundo lugar
            [2160] = 50,
        },
        [3] = { -- Prémios do terceiro lugar
            [2160] = 10,
        },
        --[[ Caso queira adicionar prémios para outras posiçőes basta seguir o exemplo:
        [Posiçăo] = {
            [Item_ID] = Item_Ammount,
        },
        ]]--
    },
}

-- ################# SnowBall Functions -- Por favor, năo mexer. Desenvolvido inteiramente por Tony Araújo (OrochiElf) ################# --
CACHE_GAMEPLAYERS = {}
CACHE_GAMEAREAPOSITIONS = {}

function loadEvent()
    print("[SnowBall Event]: Carregando a area da arena.")
    for newX = SnowBall_Configurations.Area_Configurations.Area_Arena[1].x, SnowBall_Configurations.Area_Configurations.Area_Arena[2].x do
        for newY = SnowBall_Configurations.Area_Configurations.Area_Arena[1].y, SnowBall_Configurations.Area_Configurations.Area_Arena[2].y do
            local AreaPos = {x = newX, y = newY, z = SnowBall_Configurations.Area_Configurations.Area_Arena[1].z}
            if getTileThingByPos(AreaPos).itemid == 0 then
                print("[SnowBall Event]: Houve um problema ao carregar a posicao (x = " .. AreaPos.x .. " - y = " .. AreaPos.y .." - z = " .. AreaPos.z .. ") da arena do evento, por favor verifique as condicoes.")
                return false
            elseif isWalkable(AreaPos) then
                table.insert(CACHE_GAMEAREAPOSITIONS, AreaPos)
            end
        end
    end
    print("[SnowBall Event]: Carregamento da area da arena concluido com sucesso.")

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_WaitRoom).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicao da sala de espera, por favor verifique as condicoes.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicao do teleport da sala de espera, por favor verifique as condicoes.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_EventTeleport).itemid == 0 then
        print("[SnowBall Event]: Houve um problema ao verificar a existencia da posicoo para criaçao do teleport do evento, por favor verifique as condicoes.")
        return false
    end

    print("[SnowBall Event]: Carregamento do evento concluido com sucesso.")
    return true
end

local sampleConfigs = {
    [0] = {dirPos = {x = 0, y = -1}},
    [1] = {dirPos = {x = 1, y = 0}},
    [2] = {dirPos = {x = 0, y = 1}},
    [3] = {dirPos = {x = -1, y = 0}},
}

local iced_Corpses = {
    [0] = {
        [0] = {7303},
        [1] = {7306},
        [2] = {7303},
        [3] = {7306},
    },
    [1] = {
        [0] = {7305, 7307, 7309, 7311},
        [1] = {7308, 7310, 7312},
        [2] = {7305, 7307, 7309, 7311},
        [3] = {7308, 7310, 7312},
    },
}

function Event_sendSnowBall(cid, pos, rounds, dir)
    local player = Player(cid)

    if rounds == 0 then
        return true
    end

    if player then
        local sampleCfg = sampleConfigs[dir]

        if sampleCfg then
            local newPos = Position(pos.x + sampleCfg.dirPos.x, pos.y + sampleCfg.dirPos.y, pos.z)

            if isWalkable(newPos) then
                if Tile(newPos):getTopCreature() then
                    local killed = Tile(newPos):getTopCreature()

                    if Player(killed:getId()) then
                        if iced_Corpses[killed:getSex()] then
                            local killed_corpse = iced_Corpses[killed:getSex()][killed:getDirection()][math.random(1, #iced_Corpses[killed:getSex()][killed:getDirection()])]

                            Game.createItem(killed_corpse, 1, killed:getPosition())
                            local item = Item(getTileItemById(killed:getPosition(), killed_corpse).uid)
                            addEvent(function() item:remove(1) end, 3000)
                        end

                        killed:getPosition():sendMagicEffect(3)
                        killed:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
                        killed:getPosition():sendMagicEffect(50)
                        killed:setStorageValue(10109, killed:getStorageValue(10109) - SnowBall_Configurations.Event_LostPoints)
                        killed:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Restart)
                        killed:sendTextMessage(29, "Vocę acabou ser acertado pelo jogador " .. player:getName() .. " e perdeu -" .. SnowBall_Configurations.Event_LostPoints .." ponto(s).\nTotal de: " .. killed:getStorageValue(10109) .. " ponto(s)")

                        player:setStorageValue(10109, player:getStorageValue(10109) + SnowBall_Configurations.Event_GainPoint)
                        player:sendTextMessage(29, "Vocę acabou de acertar o jogador " .. killed:getName() .. " e ganhou +" .. SnowBall_Configurations.Event_GainPoint .." ponto(s).\nTotal de: " .. player:getStorageValue(10109) .. " ponto(s)")

                        if(CACHE_GAMEPLAYERS[2] == player:getId()) and player:getStorageValue(10109) >= Player(CACHE_GAMEPLAYERS[1]):getStorageValue(10109) then
                            player:getPosition():sendMagicEffect(7)
                            player:sendTextMessage(29, "Vocę agora é o lider do ranking do SnowBall, parabéns!")
                            Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
                            Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, "Vocę acaba de perder a primeira colocaçăo!")
                        end

                        table.sort(CACHE_GAMEPLAYERS, function(a, b) return Player(a):getStorageValue(10109) > Player(b):getStorageValue(10109) end)
                    else

                        newPos:sendMagicEffect(3)
                    end
                    return true
                end

                pos:sendDistanceEffect(newPos, 13)
                pos = newPos
                return addEvent(Event_sendSnowBall, SnowBall_Configurations.Ammo_Configurations.Ammo_Speed, player:getId(), pos, rounds - 1, dir)
            end

            newPos:sendMagicEffect(3)
            return true
        end
    end
    return true
end

function Event_endGame()
    local str = "       ## -> SnowBall Ranking <- ##\n\n"

    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SnowBall_Configurations.Positions_Rewards[rank] then
            for item_id, item_ammount in pairs(SnowBall_Configurations.Positions_Rewards[rank]) do

                Player(players):addItem(item_id, item_ammount)
            end
        end

        str = str .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " ponto(s)\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):showTextDialog(2111, str)
    end

    broadcastMessage("[Snowball Event]: O evento terminou.")
    return true
end

function isWalkable(pos)
    for i = 0, 255 do
        pos.stackpos = i

        local item = Item(getTileThingByPos(pos).uid)
        if item ~= nil then
            if item:hasProperty(2) or item:hasProperty(3) or item:hasProperty(7) then
                return false
            end
        end
    end
    return true
end

function isInArena(player)
    local pos = player:getPosition()

    if pos.z == SnowBall_Configurations.Area_Configurations.Area_Arena[1].z then
        if pos.x >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].x and pos.y >= SnowBall_Configurations.Area_Configurations.Area_Arena[1].y then
            if pos.x <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].x and pos.y <= SnowBall_Configurations.Area_Configurations.Area_Arena[2].y then
                return true
            end
        end
    end
    return false
end
 
Niw is defrent error like that

Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
attempt to index a nil value
stack traceback:
        [C]: at 0x55e820216ce0
        [C]: in function 'teleportTo'
        data/globalevents/scripts/events/SnowBall_Event.lua:12: in function <data/globalevents/scripts/events/SnowBall_Event.lua:1>
Post automatically merged:

and no remove teleport in temple;/
 
replace just that part.

Lua:
function Event_endGame()
    local str = "       ## -> SnowBall Ranking <- ##\n\n"

    for rank, playerID in ipairs(CACHE_GAMEPLAYERS) do
        local player = Player(playerID)
        if player then
            local playerName = player:getName()
            local playerStorage = player:getStorageValue(10109)

            if SnowBall_Configurations.Positions_Rewards[rank] then
                for item_id, item_ammount in pairs(SnowBall_Configurations.Positions_Rewards[rank]) do
                    player:addItem(item_id, item_ammount)
                end
            end

            str = str .. rank .. ". " .. playerName .. ": " .. playerStorage .. " ponto(s)\n"
            local templePosition = player:getTown():getTemplePosition()
            if templePosition then
                player:teleportTo(templePosition)
            else
                print("[SnowBall Event]: O templo não está configurado corretamente.")
              
            end
        else
            print("[SnowBall Event]: Jogador inválido na posição " .. rank)
          
        end
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        local player = Player(cid)
        if player then
            player:showTextDialog(2111, str)
        end
    end

    broadcastMessage("[Snowball Event]: O evento terminou.")
    return true
end
 
Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
attempt to index a nil value
stack traceback:
        [C]: at 0x5591cc06ace0
        [C]: in function 'teleportTo'
        data/globalevents/scripts/events/SnowBall_Event.lua:12: in function <data/globalevents/scripts/events/SnowBall_Event.lua:1>
;/
 
 
not working i change this and no working is the same

Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
attempt to index a nil value
stack traceback:
        [C]: at 0x5591cc06ace0
        [C]: in function 'teleportTo'
        data/globalevents/scripts/events/SnowBall_Event.lua:12: in function <data/globalevents/scripts/events/SnowBall_Event.lua:1>
;/
Quote ReplyReport
Upvote
0
 
Back
Top