Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local players = {"master39","BombBloke"} -- Fill this table however you like.
- commands.scoreboard("objectives add Kills totalKillCount") -- Sample objective.
- commands.scoreboard("objectives setDisplay sidebar Kills") -- Makes the counter visible to players (once they start).
- local maxVal = 100 -- Highest value you expect a player to reach.
- local function getKillCount(playerName)
- if not commands.xp("0 "..playerName) then return 0 end -- In case the player is not online.
- local minGuess, maxGuess, curGuess = 0, maxVal, math.floor(maxVal / 2)
- while curGuess >= minGuess and curGuess < maxGuess do
- if commands.testfor("@a[name="..playerName..",score_Kills="..tostring(curGuess).."]") then
- -- Score is equal to or less than curGuess.
- maxGuess = curGuess
- curGuess = minGuess + math.floor((maxGuess - minGuess) / 2)
- else
- -- Score is greater than curGuess.
- minGuess = curGuess
- curGuess = math.max(minGuess + 1, minGuess + math.floor((maxGuess - minGuess) / 2))
- end
- end
- return curGuess
- end
- -- A primitive score display loop:
- while true do
- term.clear()
- term.setCursorPos(1,1)
- for i = 1, #players do print(players[i]..": "..getKillCount(players[i])) end
- sleep(30) -- Or however many seconds you want between updates.
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement