Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Will count redstone pulses on the right side of the pc. Will continue even if the server restarts.
- --Made by Severino
- --Tested with tekkit
- --You need to make a file in the computer's
- --program folder called count.txt and put the
- --number 0 in it first.
- term.clear()
- term.setCursorPos(1, 1)
- minerID = os.getComputerID()
- turtleName = nil
- consoleID = 0
- version = "1.0"
- function getConsoleID()
- local fname = "ConsoleID"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- consoleID = tonumber(file.readAll())
- file.close()
- print("Monitor Console ID: "..consoleID)
- else
- updateStatus("Waiting for Console ID...",true)
- term.write("Monitor Console ID: ")
- consoleID = io.read()
- file = fs.open(fname, "w")
- file.write(consoleID)
- file.close()
- consoleID = tonumber(consoleID)
- end
- end
- function updateStatus(msg, silent)
- if not rednet.isOpen("top") then rednet.open("top") end
- if rednet.isOpen("top") then
- if turtleName == nil then return end
- networkmsg = "MM:"..turtleName..": "..msg
- if consoleID == 0 then
- rednet.broadcast(networkmsg)
- else
- rednet.send(consoleID,networkmsg)
- end
- end
- if not silent then print(msg) end
- end
- function getTurtleName()
- local fname = "TurtleName"
- if fs.exists(fname) then
- file = fs.open(fname, "r")
- turtleName = file.readAll()
- file.close()
- else
- term.write("Turtle Name: ")
- turtleName = io.read()
- file = fs.open(fname, "w")
- file.write(turtleName)
- file.close()
- end
- end
- -- Main Program
- updateStatus("Starting")
- term.clear()
- term.setCursorPos(1,1)
- getTurtleName()
- getConsoleID()
- function update()
- end
- local iCount = 0
- local hMonitor = peripheral.wrap("right")
- file = io.open("count.txt","r")
- count = file:read()
- file:close()
- -- Monitor is on top of the computer
- term.redirect(hMonitor) --redirect console output to monitor
- while true do
- event = os.pullEvent()
- --Redstone from the side
- if redstone.getInput("bottom") == true then
- count = count + 1
- file = io.open("count.txt", "w")
- file:write(count)
- file:close()
- term.clear()
- term.setCursorPos(1,1)
- updateStatus("Amount of items generated so far is: " .. count)
- end
- --Current from the left will stop this
- if redstone.getInput("back") == true then
- count = 0
- term.clear()
- updateStatus("Count reset")
- term.clear()
- term.restore()
- end
- end
- term.clear()
- term.restore()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement