fishermedders

Turtle Slave Power

Feb 12th, 2017
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. rednet.open("right")
  2. m = peripheral.wrap("top")
  3. m.setTextScale(0.5)
  4.  
  5. mid = 1352
  6.  
  7. function updatetime(time)
  8. tfile = fs.open("time","w")
  9. tfile.write(time)
  10. tfile.close()
  11. end
  12.  
  13. function gettime()
  14. tfile = fs.open("time","r")
  15. time = tfile.readAll()
  16. tfile.close()
  17. return tonumber(time)
  18. end
  19.  
  20. function updatecname(name)
  21. cnfile = fs.open("cname","w")
  22. cnfile.write(name)
  23. cnfile.close()
  24. end
  25.  
  26. function getcname()
  27. cnfile = fs.open("cname","r")
  28. cn = cnfile.readAll()
  29. cnfile.close()
  30. return cn
  31. end
  32.  
  33. color = {}
  34. color.vc1 = colors.yellow
  35. color.vc2 = colors.white
  36.  
  37. function writemon()
  38. term.redirect(m)
  39. term.clear()
  40. term.setCursorPos(1,1)
  41. term.setTextColor(color.vc1)
  42. print("Player:")
  43. term.setTextColor(color.vc2)
  44. print(getcname())
  45. term.setTextColor(color.vc1)
  46. print("Remaining Time:")
  47. term.setTextColor(color.vc2)
  48. print(gettime().." sec.")
  49. size = {term.getSize()}
  50. term.setCursorPos(1,size[2])
  51. term.setTextColor(color.vc1)
  52. term.write("Slave ID: ")
  53. term.setTextColor(color.vc2)
  54. term.write(os.getComputerID())
  55. term.restore()
  56. end
  57.  
  58. if not fs.exists("time") then
  59. updatetime(0)
  60. end
  61. if not fs.exists("cname") then
  62. updatecname("No Player!")
  63. end
  64.  
  65. ctime = gettime()
  66. writemon()
  67. os.startTimer(1)
  68. while true do
  69. evnt = {os.pullEvent()}
  70. if evnt[1] == "rednet_message" then
  71. for i = 1,#evnt do
  72. print(evnt[i])
  73. end
  74. print("EOF")
  75. if evnt[3]:find(":") then
  76. args = {}
  77. for arg in string.gmatch(evnt[3], '([^:]+)') do
  78. table.insert(args,arg)
  79. end
  80. if evnt[2] == mid then
  81. if args[1] == "ms" and args[2] == "gs" then
  82. rednet.send(evnt[2],os.getComputerID())
  83. elseif args[1] == "ms" then
  84. if args[2] == tostring(os.getComputerID()) then
  85. if args[3] == "break" then
  86. turtle.dig()
  87. elseif args[3] == "place" then
  88. turtle.place()
  89. elseif args[3] == "rn" then
  90. print("I have been renamed to: "..args[4])
  91. updatecname(args[4])
  92. writemon()
  93. elseif args[3] == "stime" then
  94. updatetime(args[4])
  95. end
  96. end
  97. end
  98. end
  99. end
  100. elseif evnt[1] == "timer" then
  101. if gettime() ~= 0 then
  102. updatetime(gettime()-1)
  103. turtle.place()
  104. else
  105. turtle.dig()
  106. end
  107. os.startTimer(1)
  108. print("Timer started")
  109. writemon()
  110. end
  111. end
Add Comment
Please, Sign In to add comment