Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --PLAYER TRACKING HELP SCRIPTS
- function getScore(playername,scorename)
- local result,message = commands.scoreboard("players","add",playername,scorename,0)
- --if result == false then print(result,message[1]) end
- if result then
- local wordpattern = "[^, ]+"
- local words = {}
- for word in string.gmatch(message[1], wordpattern) do table.insert(words,word) end
- local scoreobj = {name=scorename,count=tonumber(words[#words])}
- --print(message[1])
- --print("Score: "..scoreobj.name.." : "..scoreobj.count)
- return scoreobj
- end
- return {name=score,count=0}
- end
- --for player name, create a lua object of all scoreboard scores
- local function tallyScores(name,boards)
- local tally = {}
- for i,board in ipairs(boards) do
- table.insert(tally,getScore(name,board))
- end
- return tally
- end
- --provide a list of reoccuring strings and return a list with unique strings and a count
- function tallyTable(list)
- local tally = {}
- for _,item in ipairs(list) do
- if tally[item] then
- tally[item] = tally[item] +1
- else
- tally[item] = 1
- end
- end
- return tally
- end
- local function printRecord(record)
- print(record.name)
- for i, score in ipairs(record.scores) do
- print("--> "..score.name..": "..score.count)
- end
- end
- --creates a list of all scores sorted by player
- local function tallyPlayers(playerlist,boards)
- local results = {}
- for i, player in ipairs(playerlist) do
- table.insert(results,{name=player.name,scores=tallyScores(player.name,boards)})
- end
- return results
- end
- local function createTotals(tallies)
- local results = {}
- for i, record in ipairs(tallies) do
- local count = 0
- for j, score in ipairs(record.scores) do
- if score.count > 0 then
- count = count +1
- end
- end
- table.insert(results,{name=record.name,total=count})
- end
- return results
- end
Add Comment
Please, Sign In to add comment