• 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 problem tfs1.5

jareczekjsp

Member
Joined
Jan 30, 2023
Messages
213
Reaction score
14
GitHub
Jarek123
Hello guys I have snowball event and I have problem because when snowball start is error in console

Lua:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
luaAddEvent(). callback parameter should be a function.
stack traceback:
        [C]: in function 'addEvent'
        data/globalevents/scripts/events/SnowBall_Event.lua:17: in function <data/globalevents/scripts/events/SnowBall_Event.lua:1>
and event no finish all the time players is in event in snowball map

my script globalevents

Code:
function startGame(rounds)
    if rounds == 0 then
        if #CACHE_GAMEPLAYERS < SnowBall_Configurations.Event_MinPlayers then
            for _, player in ipairs(CACHE_GAMEPLAYERS) do
                local playerObj = Player(player)
                playerObj:teleportTo(playerObj:getTown():getTemplePosition())
            end
            broadcastMessage("[Snowball Event]: The event was canceled due to not having at least " .. SnowBall_Configurations.Event_MinPlayers .. " players.")
        else
            for _, player in ipairs(CACHE_GAMEPLAYERS) do
                local playerObj = Player(player)
                playerObj:setStorageValue(10109, 0)
                playerObj:setStorageValue(10108, SnowBall_Configurations.Ammo_Configurations.Ammo_Start)
                playerObj:teleportTo(CACHE_GAMEAREAPOSITIONS[math.random(1, #CACHE_GAMEAREAPOSITIONS)])
            end
            broadcastMessage("[Snowball Event]: The event was closed. The game started.")
            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

    local missingPlayers = math.max(0, SnowBall_Configurations.Event_MinPlayers - #CACHE_GAMEPLAYERS)
    local pluralSuffix = missingPlayers == 1 and "" or "s"

    if #CACHE_GAMEPLAYERS < SnowBall_Configurations.Event_MinPlayers then
        broadcastMessage("[Snowball Event]: Missing " .. rounds .. " minute(s) and " .. missingPlayers .. " player(s) for the game to start.")
    else
        broadcastMessage("[Snowball Event]: Missing " .. rounds .. " minute(s) for the game to start.")
    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]: The event has opened, go to the temple to participate.")
    addEvent(startGame, 60 * 1000, SnowBall_Configurations.Event_WaitGame)

    return true
end

LIB

Code:
SnowBall_Configurations = {
    Event_Duration = 1, -- Duration of the game in minutes.
    Event_WaitGame = 3, -- Waiting time in minutes before the start of the game, inside the room.
    Event_MinPlayers = 2, -- Minimum number of players for the game to start; otherwise, the game is canceled.
    Event_GainPoint = 1, -- Points gained for each hit in the game.
    Event_LostPoints = 1, -- Points lost for each death in the game. // To deactivate, set value = 0.
    Event_Days = {1, 2, 3, 4, 5, 6, 7}, -- Days the event will occur (following the order of 1 = Sunday, 7 = Saturday)

    Area_Configurations = {
        Area_Arena = {{x = 999, y = 1488, z = 7}, {x = 1014, y = 1514, z = 7}}, -- Area da arena do jogo, ({Canto Superior Esquerdo}, {Canto Inferior Direito})
        Position_WaitRoom = {x = 964, y = 1492, z = 7}, -- Posiçăo da sala de espera do jogo
        Position_ExitWaitRoom = {x = 989, y = 999, z = 5}, -- Posiçăo do teleport que sairá da sala de espera do jogo
        Position_EventTeleport = {x = 909, y = 930, z = 8}, -- Posiçăo de onde será criado o teleport para os participantes irem para a sala de espera.
    },

  Ammo_Configurations = {
        Ammo_Price = 1, -- Price of ammunition in game points.
        Ammo_Ammount = 100, -- Amount gained per purchase.
        Ammo_Start = 100, -- Starting ammunition quantity for each player at the beginning of the game.
        Ammo_Restart = 100, -- Player's ammunition quantity in case of death. // Set value = 0 to deactivate.
        Ammo_Speed = 150, -- Speed of each shot
        Ammo_Infinity = false, -- Whether ammunition is infinite or not (True / False)
        Ammo_Exhaust = 1, -- Seconds to wait to use the !snowball shoot command again
        Ammo_Distance = 5, -- Number of tiles the shot will reach
    },
 
}

CACHE_GAMEPLAYERS = {}
CACHE_GAMEAREAPOSITIONS = {}

function loadEvent()
    print("[SnowBall Event]: Loading the arena area.")
    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]: There was a problem loading position (x = " .. AreaPos.x .. " - y = " .. AreaPos.y .." - z = " .. AreaPos.z .. ") of the event's arena, please check the conditions.")
                return false
            elseif isWalkable(AreaPos) then
                table.insert(CACHE_GAMEAREAPOSITIONS, AreaPos)
            end
        end
    end
    print("[SnowBall Event]: Arena area loading completed successfully.")

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_WaitRoom).itemid == 0 then
        print("[SnowBall Event]: There was a problem checking the existence of the waiting room position, please verify the conditions.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_ExitWaitRoom).itemid == 0 then
        print("[SnowBall Event]: There was a problem checking the existence of the exit teleport position from the waiting room, please verify the conditions.")
        return false
    end

    if getTileThingByPos(SnowBall_Configurations.Area_Configurations.Position_EventTeleport).itemid == 0 then
        print("[SnowBall Event]: There was a problem checking the existence of the position for creating the event's teleport, please verify the conditions.")
        return false
    end

    print("[SnowBall Event]: Event loading completed successfully.")
    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, "You were hit by player " .. player:getName() .. " and lost -" .. SnowBall_Configurations.Event_LostPoints .." point(s).\nTotal: " .. killed:getStorageValue(10109) .. " point(s)")

                        player:setStorageValue(10109, player:getStorageValue(10109) + SnowBall_Configurations.Event_GainPoint)
                        player:sendTextMessage(29, "You hit player " .. killed:getName() .. " and gained +" .. SnowBall_Configurations.Event_GainPoint .." point(s).\nTotal: " .. player:getStorageValue(10109) .. " point(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, "You are now the leader of the SnowBall ranking, congratulations!")
                            Player(CACHE_GAMEPLAYERS[1]):getPosition():sendMagicEffect(16)
                            Player(CACHE_GAMEPLAYERS[1]):sendTextMessage(29, "You have just lost the first place!")
                        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 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
 
In 17 line of LIB it calls Event_endGame:
Code:
addEvent(Event_endGame, SnowBall_Configurations.Event_Duration * 60 * 1000)
and there is no such function in files you've posted.
Is there any other Snow Event file or someone who posted it forgot to post this function?
 
Back
Top