toast_account_i_made

Miner Crew

Jun 24th, 2021 (edited)
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.12 KB | None | 0 0
  1. local crewId = 0
  2. local mineTaskDist = 0
  3. local startMine = false
  4. local mineTaskRemain = 0
  5. local raisedUp = false
  6.  
  7. math.randomseed(os.time())
  8.  
  9. print("Attempting bootup of cakesoft CREW miner, hold CTRL+T to terminate - DO NOT DISTRIBUTE")
  10.  
  11. local modem = peripheral.wrap("left")
  12. modem.open(8972) -- general broadcast
  13. modem.open(8973) -- only for dm to captain
  14.  
  15. function BootupRight()
  16. local comp = peripheral.wrap("right")
  17. comp.turnOn()
  18. end
  19.  
  20. if pcall(BootupRight) then
  21. print("Booted up right computer succsesfuly")
  22. else
  23. modem.transmit(8972, 8972, "FINBOOT")
  24. end
  25.  
  26. local wait = true
  27.  
  28. while wait do
  29. print("Waiting")
  30. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  31. if event then
  32. wait = false
  33. print("Got begining message: "..message)
  34. crewId = math.floor(math.random()*1000)
  35. end
  36. end
  37.  
  38.  
  39.  
  40.  
  41.  
  42. function CORE()
  43. while true do
  44. os.sleep(0)
  45.  
  46. if (mineTaskRemain > 0) then
  47. turtle.forward()
  48. turtle.dig()
  49. turtle.digUp()
  50. turtle.digDown()
  51. mineTaskRemain = mineTaskRemain - 1
  52. print(mineTaskRemain)
  53. end
  54. end
  55. end
  56. function FUELANDLABEL()
  57. while true do
  58. print("FUELANDLABEL S")
  59. local fuel = turtle.getFuelLevel()
  60. os.setComputerLabel("Crew ID"..crewId.." | Fuel level: "..fuel)
  61.  
  62. coroutine.yield()
  63.  
  64. if turtle.getFuelLevel() < 100 then
  65. print("Fuel level below 100, attempting refuel")
  66. local refuelled = false
  67. for n = 1, 16 do -- edited from refuel.lua rom/programs
  68. -- Stop if we've reached the limit, or are fully refuelled.
  69. if turtle.getFuelLevel() >= turtle.getFuelLimit() then
  70. break
  71. end
  72.  
  73. turtle.select(n)
  74. if turtle.refuel() then
  75. refuelled = true
  76. end
  77. end
  78.  
  79. if not refuelled then
  80. modem.transmit(8973, 8973, "FUEL CRITICALY LOW - INPUT COAL (Computer Id = "..crewId..")")
  81. print("Uh oh - could not refuel")
  82. end
  83. end
  84. end
  85. end
  86.  
  87. function MODEMCORE()
  88. while true do
  89. local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
  90.  
  91. if event then
  92. local args = {}
  93. print("Got message '"..message.."'")
  94. for i in string.gmatch(message, "%S+") do
  95. table.insert(args, i)
  96. end
  97.  
  98. print("Got order: "..args[1])
  99. if (args[1] == "MF") then --MF means to go however much the 2nd arg is
  100. mineTaskDist = tonumber(args[2])
  101. print(tonumber(args[2]))
  102. mineTaskRemain = mineTaskDist
  103.  
  104. if not raisedUp then
  105. turtle.up()
  106. raisedUp = true
  107. end
  108. end
  109.  
  110. end
  111.  
  112. end
  113. end
  114. print("Running cakesoft miner (Crew)")
  115. parallel.waitForAny(CORE, FUELANDLABEL, MODEMCORE)
Add Comment
Please, Sign In to add comment