Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --pastebin get p8QcFC8H startup
- -- Awake
- print("Tunnel Server Alive: Hello World!")
- -- Setup wireless
- local modem = peripheral.wrap("right")
- -- 210 Server -> Client
- -- 220 Client -> Server
- modem.open(210)
- modem.open(220)
- print("Channel 210 and 220 are open")
- -- Setup sending wireless messages
- function SendMessage(message)
- modem.transmit(210, 220, message)
- end
- -- Setup receiving wireless messages
- function WaitForMessage(messageCompare)
- while true do
- local
- a,b,c,d,e,f = os.pullEvent("modem_message")
- print("Message received: " .. tostring(e))
- if(e == messageCompare) then
- break
- end
- end
- end
- -- Get turtle amount from user
- print("How many turtles are mining? >>")
- local desiredTurtleCount = tonumber(read())
- -- Get skip checks from user
- print("Skip handshake? (y/n) >>")
- local skipHandshake = read()
- if skipHandshake == "n" then
- -- Send awake signal
- print("Sending awake signal to all turtles...")
- SendMessage("_ServerAwake")
- -- Wait for all turtles to register
- print("Waiting for turtles to register...")
- local turtleCount = 0
- while true do
- WaitForMessage("_TurtleRegistered")
- turtleCount = turtleCount + 1
- print("Turtle registered. Count is " .. tostring(turtleCount))
- if(turtleCount == desiredTurtleCount) then break end
- end
- print("All turtles registered")
- -- Wait for all turtles to reset their y pos
- print("Waiting for turtles to be ready to mine...")
- local turtleCount = 0
- while true do
- WaitForMessage("_TurtleReadyToMine")
- turtleCount = turtleCount + 1
- print("Turtle ready to mine. Count is " .. tostring(turtleCount))
- if(turtleCount == desiredTurtleCount) then break end
- end
- print("All turtles ready to mine")
- -- Begin managing mine operations
- print("Mining...")
- SendMessage("_Begin")
- end
- local readyCount = 0
- local cycleCount = 1
- local emptyCount = 0
- while true do
- print("Starting mine cycle #" .. tostring(cycleCount))
- if emptyCount == 64 then
- SendMessage("_Empty")
- emptyCount = 0
- else
- os.sleep(0.05)
- SendMessage("_StartNextCycle")
- end
- print("Waiting for turtles to be ready for next cycle...")
- readyCount = 0
- while true do
- WaitForMessage("_ReadyForNextCycle")
- readyCount = readyCount + 1
- print("A turtle is ready. Ready count is " .. tostring(readyCount))
- if(readyCount == desiredTurtleCount) then
- print("All turtles ready")
- break
- end
- end
- cycleCount = cycleCount + 1
- emptyCount = emptyCount + 1
- print(">>")
- print(">>")
- print(">>")
- end
- -- Done
- print("Goodbye >>")
- read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement