Bolodefchoco_LUAXML

[Function] system.rank

Apr 3rd, 2016
378
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.05 KB | None | 0 0
  1. --Creator: Bolodefchoco
  2. --Made in: 03/04/2016
  3. --Last update: 26/05/2016
  4. --[[ Notes:
  5.     Does:
  6.         Retorna um ranking.
  7.     Args:
  8.         players --> Tabela de jogadores para o rank
  9.         fromValue --> Base de pontos para o rank (Exemplo: {mice,"score"} pega o valor mice[jogador].score)
  10.         showPos --> Caso true, mostrará a posição do jogador ao lado de seu nome
  11.         showPoints --> Caso true, mostrará os pontos do jogador ao lado de seu nome
  12.         pointsName --> O nome dos pontos
  13.         lim --> Máximo de jogadores no rank
  14. ]]--
  15.  
  16. system.rank=function(players,fromValue,showPos,showPoints,pointsName,lim)
  17.     local p,rank = {},""
  18.     fromValue,lim = fromValue or {tfm.get.room.playerList,"score"},tonumber(lim) or 100
  19.     for n in next,players do
  20.         p[#p+1] = {name=n,v=fromValue[1][n][fromValue[2]]}
  21.     end
  22.     table.sort(p,function(f,s) return f.v>s.v end)
  23.     for o,n in next,p do
  24.         if o <= lim then
  25.             rank = rank .. (showPos and "<J>"..o..". " or "") .. "<V>" .. n.name .. (showPoints and " <BL>- <VP>" .. n.v .. " "..(pointsName or "points") .."\n" or "\n")
  26.         end
  27.     end
  28.     return rank
  29. end
Advertisement
Add Comment
Please, Sign In to add comment