Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- This program is made by Engineer on these forums: http://www.computercraft.info/forums2/
- When this program is being used please credit to the author; no legal actions will be taken in any way. Even when this is not done, but it would be nice.
- ]]--
- if not os.loadAPI("redtracker") then
- local urlHandle = http.get("http://pastebin.com/raw.php?i=ANDVZV8V")
- local fileHandle = fs.open("redtracker", "w")
- fileHandle.write(urlHandle.readAll())
- urlHandle.close()
- fileHandle.close()
- os.loadAPI("redtracker")
- end
- local tArgs = { ... }
- if #tArgs == 0 then
- print("No arguments given")
- return
- end
- local shouldCount = true
- local order = {}
- local tracker = {}
- local runUntilKey = false
- local count = 100
- local function checkSide( sSide )
- for _, side in pairs(rs.getSides()) do
- if sSide == side or string.find(side, sSide) then
- return side
- end
- end
- return false
- end
- local function updateScreen()
- term.setBackgroundColour(colours.white)
- term.setTextColour(colours.black)
- term.clear()
- term.setCursorPos(1, 1)
- local w, h = term.getSize()
- for index, side in pairs(order) do
- print(string.format("Player %d", index))
- term.setBackgroundColour(math.pow(2, index + 1))
- local clicks = tostring(tracker[side])
- local width = math.floor(tracker[side] / count * w)
- write(clicks)
- if width > #clicks then
- write(string.rep(" ", width - #clicks))
- end
- print()
- term.setBackgroundColour(colours.white)
- end
- end
- local function callback(side, active)
- if active and shouldCount then
- tracker[side] = 1 + tracker[side]
- if tracker[side] == count then
- shouldCount = false
- end
- updateScreen()
- end
- end
- for _, option in pairs( tArgs ) do
- if option:sub(1, 2) == "s:" then
- local side = checkSide(option:sub(3, #option))
- if side then
- order[#order + 1] = side
- tracker[side] = 0
- redtracker.addCallback(callback, side)
- end
- elseif option:sub(1, 2) == "m:" then
- local side = option:sub(3, #option)
- if peripheral.isPresent(side) and peripheral.getType(side) == "monitor" then
- term.redirect(peripheral.wrap(side))
- end
- elseif option:sub(1, 2) == "c:" then
- local countInput = tonumber(option:sub(3, #option))
- if countInput > 0 then
- count = countInput
- end
- elseif option == "rununtilkey" then
- runUntilKey = not runUntilKey
- end
- end
- repeat
- updateScreen()
- while shouldCount do
- local event = os.pullEvent()
- if event == "redstone" then
- redtracker.update()
- elseif event == "key" and runUntilKey then
- runUntilKey = false
- elseif event == "monitor_resize" or event == "term_resize" then
- updateScreen()
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- for index, side in pairs(order) do
- if tracker[side] == count then
- print(string.format("Player %d wins!", index))
- print("Touch the screen to continue")
- os.pullEvent("monitor_touch")
- break
- end
- end
- for side, clicks in pairs(tracker) do
- tracker[side] = 0
- end
- shouldCount = true
- until not runUntilKey
- term.setBackgroundColour(colours.black)
- term.clear()
- if term.restore then
- term.restore()
- else
- term.redirect(term.native())
- end
Advertisement
Add Comment
Please, Sign In to add comment