Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- m = peripheral.wrap("top")
- rednet.open("right")
- woodTimer = 7200
- lapTimer = 2800
- x, y = m.getSize()
- name = 1
- channel = 2
- tMsg = 3
- xPos = 4
- yPos = 5
- zPos = 6
- hPos = 7
- tabSize = math.floor(x / 7)
- iTurtle = {}
- iTurtle[1] = 1
- jobTab = {}
- function getData()
- if fs.exists("tData") then
- data = fs.open("tData", "r")
- tData = textutils.unserialize(data.readAll())
- data.close()
- else
- tData = {}
- tData[1] = {}
- tData[1][name] = "Name:"
- tData[1][channel] = "ID:"
- tData[1][tMsg] = "Status:"
- tData[1][xPos] = "X:"
- tData[1][yPos] = "Y:"
- tData[1][zPos] = "Z:"
- tData[1][hPos] = "H:"
- end
- end
- function dumpFile(msg)
- data = fs.open("tSheet", "w")
- data.write(msg)
- data.close()
- end
- function readFile()
- data = fs.open("tSheet", "r")
- tx = data.readLine()
- ty = data.readLine()
- tz = data.readLine()
- th = data.readLine()
- tName = data.readLine()
- tState = data.readLine()
- data.close()
- if tState == "idle" then
- iTurtle[1] = id
- end
- end
- function saveData()
- data = fs.open("tData", "w")
- data.writeLine(textutils.serialize(tData))
- data.close()
- end
- function addTurtle()
- newMax = #tData + 1
- tData[newMax] = {}
- tData[newMax][name] = tName
- tData[newMax][channel] = id
- tData[newMax][tMsg] = tState
- tData[newMax][xPos] = tx
- tData[newMax][yPos] = ty
- tData[newMax][zPos] = tz
- tData[newMax][hPos] = th
- end
- function checkList()
- readFile()
- listEntry = false
- for i = 1, #tData do
- if id == tData[i][channel] then
- tData[i][name] = tName
- tData[i][channel] = id
- tData[i][tMsg] = tState
- tData[i][xPos] = tx
- tData[i][yPos] = ty
- tData[i][zPos] = tz
- tData[i][hPos] = th
- listEntry = true
- break
- end
- end
- if not listEntry then
- addTurtle()
- end
- saveData()
- end
- function centerText(stX, maX, tY, bCol, tCol, text)
- boundry = maX - stX
- width = (boundry / 2) - (string.len(text) / 2)
- m.setBackgroundColor(bCol)
- m.setTextColor(tCol)
- m.setCursorPos(width + stX, tY)
- m.write(text)
- end
- function drawScreen()
- m.setBackgroundColor(colors.black)
- m.setTextColor(colors.lime)
- m.clear()
- for i = 1, #tData do
- alter = true
- if alter then
- sx = 1
- ex = tabSize
- for j = 1, #tData[i] do
- centerText(sx, ex, i, colors.black, colors.white, tData[i][j])
- sx = sx + tabSize
- ex = ex + tabSize
- end
- else
- sx = 1
- ex = tabSize
- for j = 1, #tData[i] do
- centerText(sx, ex, i, colors.white, colors.black, tData[i][j])
- sx = sx + tabSize
- ex = ex + tabSize
- end
- end
- end
- end
- function check()
- event, p1, p2, p3, p4, p5 = os.pullEvent()
- if event == "rednet_message" then
- id = p1
- dumpFile(p2)
- checkList()
- elseif event == "timer" then
- woodTimer = woodTimer - 1
- lapTimer = lapTimer - 1
- if woodTimer == 0 then
- rednet.send(2, "chop wood")
- woodTimer = 7200
- elseif lapTimer == 0 then
- rednet.send(2, "farm 90 lapis")
- lapTimer = 2800
- end
- os.startTimer(1)
- end
- end
- getData()
- os.startTimer(1)
- while true do
- term.clear()
- term.setCursorPos(1, 1)
- print("Wood timer: "..woodTimer)
- print("Lapis timer: "..lapTimer)
- check()
- drawScreen()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement