antonsavov

tracker v2.5

Dec 7th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.81 KB | None | 0 0
  1. --PLAYER TRACKING HELP SCRIPTS
  2.  
  3. function getScore(playername,scorename)
  4.     local result,message = commands.scoreboard("players","add",playername,scorename,0)
  5.     --if result == false then print(result,message[1]) end
  6.     if result then
  7.         local wordpattern = "[^, ]+"
  8.         local words = {}
  9.         for word in string.gmatch(message[1], wordpattern) do table.insert(words,word) end
  10.         local scoreobj = {name=scorename,count=tonumber(words[#words])}
  11.         --print(message[1])
  12.         --print("Score: "..scoreobj.name.." : "..scoreobj.count)
  13.         return scoreobj
  14.     end
  15.    
  16.     return {name=score,count=0}
  17. end
  18.  
  19. --for player name, create a lua object of all scoreboard scores
  20. local function tallyScores(name,boards)
  21.     local tally = {}
  22.     for i,board in ipairs(boards) do
  23.         table.insert(tally,getScore(name,board))
  24.     end
  25.     return tally
  26. end
  27.  
  28. --provide a list of reoccuring strings and return a list with unique strings and a count
  29. function tallyTable(list)
  30.     local tally = {}
  31.     for _,item in ipairs(list) do
  32.         if tally[item] then
  33.             tally[item] = tally[item] +1
  34.         else
  35.             tally[item] = 1
  36.         end
  37.     end
  38.     return tally
  39. end
  40.  
  41. local function printRecord(record)
  42.     print(record.name)
  43.     for i, score in ipairs(record.scores) do
  44.         print("-->  "..score.name..":  "..score.count)
  45.     end
  46. end
  47.  
  48. --creates a list of all scores sorted by player
  49. local function tallyPlayers(playerlist,boards)
  50.     local results = {}
  51.    
  52.     for i, player in ipairs(playerlist) do
  53.         table.insert(results,{name=player.name,scores=tallyScores(player.name,boards)})
  54.     end
  55.     return results
  56. end
  57.  
  58. local function createTotals(tallies)
  59.     local results = {}
  60.     for i, record in ipairs(tallies) do
  61.         local count = 0
  62.         for j, score in ipairs(record.scores) do
  63.             if score.count > 0 then
  64.                 count = count +1
  65.             end
  66.         end
  67.         table.insert(results,{name=record.name,total=count})
  68.     end
  69.     return results
  70. end
Add Comment
Please, Sign In to add comment