• 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
185
Reaction score
9
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:
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
Did you add CACHE_GAMEAREAPOSITIONS = {} to data/global.lua as @WibbenZ suggested? As we figured in the prints added before, the problem you have is that your script can't access the random positions. It might help.
 
yes i do it bro;/no working:(
Post automatically merged:

Are there any more scripts you have that are related to this?
yes
movements
Lua:
function onStepIn(creature, item, position, fromPosition)
    local player = creature:getPlayer()

    if item:getActionId() == 10101 then

        table.insert(CACHE_GAMEPLAYERS, player:getId())
        player:teleportTo(SnowBall_Configurations.Area_Configurations.Position_WaitRoom)
    elseif item:getActionId() == 10102 then

        player:teleportTo(player:getTown():getTemplePosition())
        for pos, players in ipairs(CACHE_GAMEPLAYERS) do
            if player:getId() == players then

                table.remove(CACHE_GAMEPLAYERS, pos)
                return true
            end
        end
    end
    return true
end

talkaction
Code:
function onSay(player, words, param)
    if not isInArena(player) then
        return false
    end

    if param == "atirar" then
        if player:getExhaustion(10107) > 1 then
            return true
        end

        if not SnowBall_Configurations.Ammo_Configurations.Ammo_Infinity then
            if player:getStorageValue(10108) > 0 then
                player:setStorageValue(10108, player:getStorageValue(10108) - 1)
                player:sendCancelMessage("Ainda restam ".. player:getStorageValue(10108) .." bolas de neve.")
            else
                player:sendCancelMessage("Vocę está sem bolas de neve.")
                return true
            end
        end

        player:setExhaustion(10107, SnowBall_Configurations.Ammo_Configurations.Ammo_Exhaust)
        Event_sendSnowBall(player:getId(), player:getPosition(), SnowBall_Configurations.Ammo_Configurations.Ammo_Distance, player:getDirection())
        return false
    elseif param == "info" then
        local str = "     ## -> Player Infos <- ##\n\nPontos: ".. player:getStorageValue(10109) .."\nBolas de neve: ".. player:getStorageValue(10108)

        str = str .. "\n\n          ## -> Ranking <- ##\n\n"
        for i = 1, 5 do
            if CACHE_GAMEPLAYERS[i] then
                str  = str .. i .. ". " .. Player(CACHE_GAMEPLAYERS[i]):getName() .."\n"
            end
        end
        for pos, players in ipairs(CACHE_GAMEPLAYERS) do
            if player:getId() == players then
                str = str .. "My Ranking Pos: " .. pos
            end
        end

        player:showTextDialog(2111, str)
        return false
    end
end

global.lua

Code:
CACHE_GAMEAREAPOSITIONS = {}
 
tested and works perfect ok

For those who are experiencing the issue, simply change the location from where it was in data/lib/ 'dofile('data/lib/events/SnowBall_Configurations.lua')' to global.lua, and I tested it without alterations to the other scripts, and it worked perfectly, just that simple.


replace all:
talkaction

SnowBall_Event.lua

Lua:
function onSay(player, words, param)
    if not isInArena(player) then
        return false
    end

    if param == "shoot" then
        local cooldownTime = 1

        if player:getStorageValue(10107) + cooldownTime > os.time() then
            player:sendCancelMessage("Wait to use this command again.")
            return true
        end

        if not SnowBall_Configurations.Ammo_Configurations.Ammo_Infinity then
            if player:getStorageValue(10108) > 0 then
                player:setStorageValue(10108, player:getStorageValue(10108) - 1)
                player:sendCancelMessage("You still have " .. player:getStorageValue(10108) .. " snowballs.")
            else
                player:sendCancelMessage("You're out of snowballs.")
                return true
            end
        end

        player:setStorageValue(10107, os.time())
        Event_sendSnowBall(player:getId(), player:getPosition(), SnowBall_Configurations.Ammo_Configurations.Ammo_Distance, player:getDirection())
        return false
    elseif param == "info" then
            local str = "     ## -> Player Infos <- ##\n\nPoints: " .. player:getStorageValue(10109) .. "\nSnowballs: " .. player:getStorageValue(10108)

            str = str .. "\n\n          ## -> Ranking <- ##\n\n"
            for i = 1, 5 do
                if CACHE_GAMEPLAYERS[i] then
                    str = str .. i .. ". " .. Player(CACHE_GAMEPLAYERS[i]):getName() .. "\n"
                end
            end
            for pos, players in ipairs(CACHE_GAMEPLAYERS) do
                if player:getId() == players then
                    str = str .. "My Ranking Pos: " .. pos
                end
            end

            player:showTextDialog(2111, str)
            return false
        end
    end
 
Last edited:
For me nie działa;/
[KOD=lua]
posiadasz stosu:
[C]: pod adresem 0x564361dcbce0
[C]: w funkcji 'teleportTo'
data/globalevents/scripts/events/SnowBall_Event.lua:12: w funkcji <data/globalevents/scripts/events/SnowBall_Event.lua:1>
[/KOD]
 
For me nie działa;/
[KOD=lua]
posiadasz stosu:
[C]: pod adresem 0x564361dcbce0
[C]: w funkcji 'teleportTo'
data/globalevents/scripts/events/SnowBall_Event.lua:12: w funkcji <data/globalevents/scripts/events/SnowBall_Event.lua:1>
[/KOD]
Did you change the path from 'lib/lib' to 'global'? 'lib' doesn't work; it always gives an error. I haven't modified anything in 'SnowBall_Configurations.lua'. Is it correct to put it in 'global.lua'? It will read directly from 'data/lib/events/SnowBall_Configurations.lua,' and it's working perfectly fine for me, okay? I obtained this system and created a RevScript. I'll open a topic for those who want to use it faster and practically without errors or headaches.

global.lua
dofile('data/lib/events/SnowBall_Configurations.lua')
 
Last edited:
See if this changes anything:
Lua:
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
    loadEvent()
    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
 
See if this changes anything:
Lua:
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
    loadEvent()
    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
Thank you bro , teleporting working teleport players on event map , but All players a got Debug Client after meybe 30 seconds
 
Last edited:
I added loadEvent() temporary in there to see if you had called that function anywhere since I could not find it in any of the scripts you sent. You should probably remove that from line 32 and add it on startup instead.
Just something like this:
data/scripts
Lua:
local globalEvent = GlobalEvent("loadSnowball")

function globalEvent.onStartup()
    loadEvent()
    return true
end

globalEvent:register()
 
Lua:
Fragers has logged in.
Tester Ed has logged in.
> Broadcasted message: "[Snowball Event]: Faltam 1 minuto(s) para o jogo come�ar.".
> Broadcasted message: "[Snowball Event]: O evento foi fechado. O jogo come�ou.".
> Broadcasted message: "[Snowball Event]: O evento terminou.".
Tester Ed has logged out.
Fragers has logged out.
 
Try this 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()
    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
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    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
 
Working Perfect ,thank you guys :)
Post automatically merged:

Thank you very much, I appreciate your time and help ;)
I did remove the text box that pops up after the event has ended to show the rankings since I figured that's what was debugging the client.
Just a heads up.
 
Back
Top