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

winner name tfs 1.5

vexler222

Active Member
Joined
Apr 22, 2012
Messages
714
Solutions
15
Reaction score
46
hi, can someone add for me, to this function, a winner name and what reward won, in broadcast message?
Im triend, but everytime i got message nil value, cuz i don't know how to get winner name ;/ im tried with "rank", "rank[1]", "Player(players):getName()", "Player(players):getName(1)" etc
Code:
function terminarEvento()
    local text = "[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

        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
    end

    broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento)
    return true
end
 
Lua:
text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
Player(players):teleportTo(Player(players):getTown():getTemplePosition())
if this line is not working, then i am sure this whole part
Lua:
    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

        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end
is not working, because Player(players) not returning the player, there is no chance that Player(players):getName() is not working in this case.

try dump players table
Lua:
print(dump(CACHE_GAMEPLAYERS))

dump func:
Lua:
function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end
 
Lua:
text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
Player(players):teleportTo(Player(players):getTown():getTemplePosition())
if this line is not working, then i am sure this whole part
Lua:
    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

        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end
is not working, because Player(players) not returning the player, there is no chance that Player(players):getName() is not working in this case.

try dump players table
Lua:
print(dump(CACHE_GAMEPLAYERS))

dump func:
Lua:
function dump(o)
   if type(o) == 'table' then
      local s = '{ '
      for k,v in pairs(o) do
         if type(k) ~= 'number' then k = '"'..k..'"' end
         s = s .. '['..k..'] = ' .. dump(v) .. ','
      end
      return s .. '} '
   else
      return tostring(o)
   end
end

All work in this function bro :D But in broadcast message, it sending only text "Snowball event finished", but i want add to this message a winner name, and i tried but i anything what i tried not work :/
This function sending to player broadcast message and in blue print console, i think 5 best players.
 
Hmm, if the table is sorted by rank and its start from index 1 then winner shouldbe first, so u can try this

Lua:
function terminarEvento()
    local text = "[Snowball] Ranking:\n\n"
  
    local winnerTable = { }
  
    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SNOWBALL.premios[rank] then
            for item_id, item_ammount in pairs(SNOWBALL.premios[rank]) do
                if rank == 1 then
                   winnerTable.itemid = item_id
                   winnerTable.count = item_ammount
                end
                Player(players):addItem(item_id, item_ammount)
                Player(players):setStorageValue(STORAGEVALUE_EVENTS, 0)
            end
        end

        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
    end
  
    local winner = Player(CACHE_GAMEPLAYERS[1])
    if winner then
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento .. "\n" .. "Player " .. winner:getName() .. " won the event and received " .. winnerTable.count .. "x " .. getItemName(winnerTable.itemid) .. " Congratulations!")
    else
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento)
    end
    return true
end

not sure if i understood correctly
if not working, please show me this table
SQL:
SNOWBALL.premios
 
Last edited:
Hmm, if the table is sorted by rank and its start from index 1 then winner shouldbe first, so u can try this

Lua:
function terminarEvento()
    local text = "[Snowball] Ranking:\n\n"
 
    local winnerTable = { }
 
    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SNOWBALL.premios[rank] then
            for item_id, item_ammount in pairs(SNOWBALL.premios[rank]) do
                if rank == 1 then
                   winnerTable.itemid = item_id
                   winnerTable.count = item_ammount
                end
                Player(players):addItem(item_id, item_ammount)
                Player(players):setStorageValue(STORAGEVALUE_EVENTS, 0)
            end
        end

        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
    end
 
    local winner = Player(CACHE_GAMEPLAYERS[1])
    if winner then
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento .. "\n" .. "Player " .. winner:getName() .. " won the event and received " .. winnerTable.count .. "x " .. getItemName(winnerTable.itemid) .. " Congratulations!")
    else
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento)
    end
    return true
end

not sure if i understood correctly
if not working, please show me this table
SQL:
SNOWBALL.premios

-- Configurações de prêmios
premios = {
[1] = {[9020] = math.random(3,10), [10559] = math.random(1,3)}, -- Primeiro Lugar
},
 
Lua:
function terminarEvento()
    local text = "[Snowball] Ranking:\n\n"
    
    local winnerTable = { }
    
    local _found = false
    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SNOWBALL.premios[rank] then
            for item_id, item_ammount in pairs(SNOWBALL.premios[rank]) do
                if not _found then
                   winnerTable.itemid = item_id
                   winnerTable.count = item_ammount
                   winnerTable.id = players
                   _found = true
                end
                Player(players):addItem(item_id, item_ammount)
                Player(players):setStorageValue(STORAGEVALUE_EVENTS, 0)
            end
        end

        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
    end
    
    local winner = Player(winnerTable.id)
    if winner then
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento .. "\n" .. "Player " .. winner:getName() .. " won the event and received " .. winnerTable.count .. "x " .. getItemName(winnerTable.itemid) .. " Congratulations!")
    else
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento)
    end
    return true
end
 
Lua:
function terminarEvento()
    local text = "[Snowball] Ranking:\n\n"
   
    local winnerTable = { }
   
    local _found = false
    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SNOWBALL.premios[rank] then
            for item_id, item_ammount in pairs(SNOWBALL.premios[rank]) do
                if not _found then
                   winnerTable.itemid = item_id
                   winnerTable.count = item_ammount
                   winnerTable.id = players
                   _found = true
                end
                Player(players):addItem(item_id, item_ammount)
                Player(players):setStorageValue(STORAGEVALUE_EVENTS, 0)
            end
        end

        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
    end
   
    local winner = Player(winnerTable.id)
    if winner then
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento .. "\n" .. "Player " .. winner:getName() .. " won the event and received " .. winnerTable.count .. "x " .. getItemName(winnerTable.itemid) .. " Congratulations!")
    else
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento)
    end
    return true
end

Work in 99.5%, cuz winner got 2 rewards like in premios table, but in broadcast is only one :D
 
Lua:
function terminarEvento()
    local text = "[Snowball] Ranking:\n\n"
   
    local winnerTable = { }
    local _found = false
    for rank, players in ipairs(CACHE_GAMEPLAYERS) do
        if SNOWBALL.premios[rank] then
            if not _found then
               winnerTable.items = {}
            end          
            for item_id, item_ammount in pairs(SNOWBALL.premios[rank]) do
                if not _found then
                   winnerTable.itemid = item_id
                   winnerTable.count = item_ammount
                   winnerTable.id = players
                   local values = { itemid = item_id, count = item_ammount }
                   table.insert(winnerTable.items, values)
                end
                Player(players):addItem(item_id, item_ammount)
                Player(players):setStorageValue(STORAGEVALUE_EVENTS, 0)
            end
            _found = true
        end
        text = text .. rank .. ". " .. Player(players):getName() .. ": " .. Player(players):getStorageValue(10109) .. " pkt\n"
        Player(players):teleportTo(Player(players):getTown():getTemplePosition())
    end

    for _, cid in ipairs(CACHE_GAMEPLAYERS) do
        Player(cid):sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, text)
    end
       
    local winner = Player(winnerTable.id)
    if winner then
       local itemsString = ""
       for index, v in pairs(winnerTable.items) do
           local id = v.itemid
           local count = v.count
           local name = getItemName(id)
           if index == #winnerTable.items then
              itemsString = itemsString .. count .. "x " .. name .. "."
           else
              itemsString = itemsString .. count .. "x " .. name .. ", "
           end
       end
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento .. "\n" .. "Player " .. winner:getName() .. " won the event and received " .. itemsString .. " Congratulations!")
    else
       broadcastMessage(SNOWBALL.prefixo .. SNOWBALL.mensagemAcabouEvento)
    end
    return true
end
 
Back
Top