• 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 Event Error TFS 1.5 downgrade 8.6

Azerty

Active Member
Joined
Apr 15, 2022
Messages
301
Solutions
4
Reaction score
31
Good afternoon, I switched to TFS 1.5 and I'm having problem with some events. In this case, this is the Snowball event.
SNOWBALL ERROR.JPG

globalevents/snowball.lua
Lua:
function startGame(rounds)
    if rounds == 0 then
        if #CACHE_GAMEPLAYERS < SNOWBALL.minPlayers then
            for _, players in ipairs(CACHE_GAMEPLAYERS) do
                Player(players):teleportTo(Player(players):getTown():getTemplePosition())
            end
            broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEventoFaltaPlayer):format(SNOWBALL.minPlayers))
        else
            for _, players in ipairs(CACHE_GAMEPLAYERS) do
                local player = Player(players)
                if player then
                    player:setStorageValue(10109, 0)
                    player:setStorageValue(10108, SNOWBALL.muniInicial)
                    player:setStorageValue(STORAGEVALUE_EVENTS, 1)
                    player:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
                end
            end
            broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemInicioEvento)
            addEvent(terminarEvento, SNOWBALL.duracaoEvento * 60 * 1000)
        end

        Item(getTileItemById(SNOWBALL.posTpEntrarEvento, 1387).uid):remove(1)
        return true
    end

    if #CACHE_GAMEPLAYERS < SNOWBALL.minPlayers then
        broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds, SNOWBALL.minPlayers - #CACHE_GAMEPLAYERS))
    else
        broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds))
    end
    return addEvent(startGame, 60 * 1000, rounds - 1)
end

function onThink(interval)
    if SNOWBALL.days[os.date("%A")] then
        local hrs = tostring(os.date("%X")):sub(1, 5)
        if isInArray(SNOWBALL.days[os.date("%A")], hrs) then
            CACHE_GAMEPLAYERS = {}
            broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemEventoAberto)
            local EventTeleport = Game.createItem(1387, 1, SNOWBALL.posTpEntrarEvento)
            EventTeleport:setActionId(10101)
            addEvent(startGame, 60 * 1000, SNOWBALL.duracaoEspera)
        end
    end
    return true
end

data/Lib/snowball.lua
Lua:
SNOWBALL = {
    -- Configurações de texto
    comandoAtirar = "atirar", -- !snowball atirar
    prefixo = "[SnowBall] ",
    mensagemFoiAcertado = "Você acabou ser acertado pelo jogador %s e perdeu -%d ponto(s).\nTotal de: %d ponto(s)",
    mensagemAcertei = "Você acabou de acertar o jogador %s e ganhou +%d ponto(s).\nTotal de: %d ponto(s)",
    mensagemLider = "Você agora é o lider do ranking do SnowBall, parabéns!",
    mensagemPerdeuLider = "Você acaba de perder a primeira colocação!",
    mensagemAcabouEvento = "O Evento acabou",
    mensagemQntBolas = "Ainda restam %d bolas de neve.",
    mensagemNaoTemBola = "Você não possui bolas de neve.",
    mensagemEventoFaltaPlayer = "O evento foi cancelado por conta de não ter no minimo %d jogadores.",
    mensagemInicioEvento = "O evento foi fechado. O jogo começou.",
    mensagemEsperandoIniciar = "Faltam %d minuto(s) e %d jogador(es) para o jogo começar.",
    mensagemMinutosFaltam = "Faltam %d minuto(s) para o jogo começar.",
    mensagemEventoAberto = "O evento foi aberto, teleport se encontra em frente ao dp de Thais.",
    mensagemComprou = "Você acaba de comprar %d bolas de neve por %d\nVocê tem %d bolas de neve\nVocê tem %d ponto(s).",
    mensagemFalhaComprar = "Você não tem %d ponto(s).",
    mensagemMinComprar = "Você só pode comprar bolas de neve com o minimo de 30 bolas.",
    -- Configurações de posições
    posArena = {{x = 31436, y = 32228, z = 7}, {x = 31490, y = 32275, z = 7}},
    posEspera = {x = 31461, y = 32297, z = 7},
    posTpEntrarEvento = Position(32340, 32213, 7),
    -- Configurações de munição
    muniPreco = 1,
    muniQuant = 100, -- Quantidade de ganho a cada compra.
    muniInicial = 100, -- Começa com 100
    muniMorreu = 100, -- Caso queira desativar deixa 0
    muniVelocidade = 150, -- Velocidade de cada tiro
    muniInfinito = false,
    muniExhaust = 1, -- Segundos de espera pra usar snowball atirar
    muniDistancia = 5,
    -- Configurações de prêmios
    premios = {
    [1] = {[6527] = 2}, -- Primeiro Lugar
    },
    -- Configurações gerais
    duracaoEvento = 20,
    duracaoEspera = 5,
    minPlayers = 2,
    maxPlayers = 50,
    level = {
        active = true,
        levelMin = 150,
    },
    pontosAcerto = 1,
    pontosPerda = 1,
    days = {
        ["Sunday"] = {"17:00"},
        ["Monday"] = {"17:00"},
        ["Tuesday"] = {"17:00"},
        ["Wednesday"] = {"17:00"},
        ["Thursday"] = {"17:00"},
        ["Friday"] = {"17:00"},
        ["Saturday"] = {"17:00"},
    },
    -- Não mexa daqui pra baixo
    -- Configurações de corpos congelados
    corposCongelados = {
    [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} },
    },
    direcoes = {
    [0] = {dirPos = {x = 0, y = -1}},
    [1] = {dirPos = {x = 1, y = 0}},
    [2] = {dirPos = {x = 0, y = 1}},
    [3] = {dirPos = {x = -1, y = 0}}
    }
}

CACHE_GAMEPLAYERS = {}
CACHE_GAMEAREAPOSITIONS = {}

function carregarEvento()
    for newX = SNOWBALL.posArena[1].x, SNOWBALL.posArena[2].x do
        for newY = SNOWBALL.posArena[1].y, SNOWBALL.posArena[2].y do
            local AreaPos = {x = newX, y = newY, z = SNOWBALL.posArena[1].z}
            if getTileThingByPos(AreaPos).itemid == 0 then
                print("".. SNOWBALL.prefixo .."(x = " .. AreaPos.x .. " - y = " .. AreaPos.y .." - z = " .. AreaPos.z .. "), it was not possible to load these positions.")
                return false
            elseif isWalkable(AreaPos) then
                table.insert(CACHE_GAMEAREAPOSITIONS, AreaPos)
            end
        end
    end
   
    if getTileThingByPos(SNOWBALL.posEspera).itemid == 0 then
        print("".. SNOWBALL.prefixo .."There was a problem checking the position of the waiting room, please check the conditions.")
        return false
    end

    if getTileThingByPos(SNOWBALL.posTpEntrarEvento).itemid == 0 then
        print("".. SNOWBALL.prefixo .."There was a problem when checking the existence of the position to create the event teleport, please check the conditions.")
        return false
    end
    return true
end

function enviarSnowball(cid, pos, rounds, dir)
    local player = Player(cid)
   
    if rounds == 0 then
        return true
    end
   
    if player then
        local dirConfig = SNOWBALL.direcoes[dir]
        if dirConfig then
            local novaPos = Position(pos.x + dirConfig.dirPos.x, pos.y + dirConfig.dirPos.y, pos.z)
            if isWalkable(novaPos) then
                if Tile(novaPos):getTopCreature() then
                    local killed = Tile(novaPos):getTopCreature()
                    if Player(killed:getId()) then
                        if SNOWBALL.corposCongelados[killed:getSex()] then
                            local killed_corpse = SNOWBALL.corposCongelados[killed:getSex()][killed:getDirection()][math.random(1, #SNOWBALL.corposCongelados[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.pontosPerda))
                    killed:setStorageValue(10108, SNOWBALL.muniMorreu)
                    killed:sendTextMessage(29, (config.mensagemFoiAcertado):format(player:getName(), SNOWBALL.pontosPerda, killed:getStorageValue(10109)))
                    player:setStorageValue(10109, player:getStorageValue(10109) + SNOWBALL.pontosAcerto)
                    player:sendTextMessage(29, (SNOWBALL.mensagemAcertei):format(killed:getName(), pontosAcerto, player:getStorageValue(10109)))
                   
                    if(CACHE_GAMEPLAYERS[2] == player:getId()) and player:getStorageValue(10109) >= Player(CACHE_GAMEPLAYERS[1]):getStorageValue(10109) then
                        player:getPosition():sendMagicEffect(7)
                        player:sendTextMessage(29, SNOWBALL.mensagemLider)
                        Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
                        Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, SNOWBALL.mensagemPerdeuLider)
                    end
                   
                    table.sort(CACHE_GAMEPLAYERS, function(a, b) return Player(a):getStorageValue(10109) > Player(b):getStorageValue(10109) end)
                else
                    novaPos:sendMagicEffect(3)
                end
                return true
            end
                pos:sendDistanceEffect(newPos, 13)
                pos = novaPos
                return addEvent(enviarSnowball, SNOWBALL.muniVelocidade, player:getId(), pos, rounds - 1, dir)
            end
            novaPos:sendMagicEffect(3)
            return true
        end
    end
    return true
end

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

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

                Player(players):addItem(item_id, item_ammount)
                Player(players):setStorageValue(STORAGEVALUE_EVENTS, 0)
            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.prefixo .. SNOWBALL.mensagemAcabouEvento)
    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.posArena[1].z then
        if pos.x >= SNOWBALL.posArena[1].x and pos.y >= SNOWBALL.posArena[1].y then
            if pos.x <= SNOWBALL.posArena[2].x and pos.y <= SNOWBALL.posArena[2].y then
                return true
            end
        end
    end
    return false
end
 
Last edited:
Replace broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds)) with broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds, 0))

And for the 2nd error, make sure the positions in this table are walkable posArena = {{x = 31436, y = 32228, z = 7}, {x = 31490, y = 32275, z = 7}},
 
Replace broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds)) with broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds, 0))

And for the 2nd error, make sure the positions in this table are walkable posArena = {{x = 31436, y = 32228, z = 7}, {x = 31490, y = 32275, z = 7}},
Same error
 
Same error


I had same problem, and i changed code little and it working in my data, try this:

change it:
Code:
broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds))

to:
Code:
broadcastMessage("[Snowball]\nThe teleport will disappear in: ".. rounds .." min")
 
I had same problem, and i changed code little and it working in my data, try this:

change it:
Code:
broadcastMessage(SNOWBALL.prefixo .. (SNOWBALL.mensagemEsperandoIniciar):format(rounds))

to:
Code:
broadcastMessage("[Snowball]\nThe teleport will disappear in: ".. rounds .." min")

The problem is the second error
 
Try changing the syntax for positions, here for example:
posArena = {{x = 31436, y = 32228, z = 7}, {x = 31490, y = 32275, z = 7}},
Change to this:
posArena = {Position(31436, 32228, 7), Position(31490, 32275, 7)},
Do this for every occurence where there is a position.
 
Back
Top