Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Awake
- print("Mining server awake: Hello World!")
- -- Setup wireless
- local modemSide = "left"
- local modem = peripheral.wrap(modemSide)
- -- 5 Server -> Client
- -- 6 Client -> Server
- -- 7 Server -> Pocket Computer
- modem.open(11)
- modem.open(12)
- modem.open(13)
- modem.open(14)
- print("Channel 11 and 12 are open, as well as 13 and 14")
- -- Setup sending wireless messages
- function SendMessage(message)
- modem.transmit(11, 12, message)
- end
- function SendMessageToPocketComputer(message)
- modem.transmit(13, 13, message)
- end
- --Pocket computer helper
- function printf(m)
- print(m)
- SendMessageToPocketComputer(m)
- end
- printf("Link to pocket computer established. Hello")
- -- Setup receiving wireless messages
- function WaitForMessage(messageCompare)
- while true do
- local
- a,b,c,d,e,f = os.pullEvent("modem_message")
- printf("Message received: " .. tostring(e))
- if(e == messageCompare) then
- break
- end
- end
- end
- -- Get turtle amount from users
- printf("How many turtles are mining? >>")
- local desiredTurtleCount = tonumber(read())
- -- Get cycle amount from users
- printf("How many cycles should they mine for? >>")
- local desiredCycleCount = tonumber(read())
- -- Send awake signal
- printf("Sending awake signal to all turtles...")
- SendMessage("_ServerAwake")
- -- Wait for all turtles to register
- -- Accept and continue from user
- printf("Waiting for turtles to register...")
- local turtleCount = 0
- while true do
- WaitForMessage("_TurtleRegistered")
- turtleCount = turtleCount + 1
- printf("Turtle registered. Count is " .. tostring(turtleCount))
- if(turtleCount == desiredTurtleCount) then break end
- end
- printf("All turtles registered")
- printf("Sending reset Y signal")
- SendMessage("_ResetY")
- -- Wait for all turtles to reset their y pos
- printf("Waiting for turtles to be ready to mine...")
- local turtleCount = 0
- while true do
- WaitForMessage("_TurtleReadyToMine")
- turtleCount = turtleCount + 1
- printf("Turtle ready to mine. Count is " .. tostring(turtleCount))
- if(turtleCount == desiredTurtleCount) then break end
- end
- printf("All turtles ready to mine")
- -- Begin managing mine operations
- printf("Mining...")
- SendMessage("_Begin")
- local readyCount = 0
- local cycleCount = 1
- while true do
- printf("Starting mine cycle #" .. tostring(cycleCount))
- modem.transmit(8, 8, "Starting mine cycle #" .. tostring(cycleCount))
- SendMessage("_StartNextCycle")
- printf("Waiting for turtles to be ready for next cycle...")
- readyCount = 0
- while true do
- WaitForMessage("_ReadyForNextCycle")
- readyCount = readyCount + 1
- printf("A turtle is ready. Ready count is " .. tostring(readyCount))
- if(readyCount == turtleCount) then
- printf("All turtles ready")
- break
- end
- end
- if(cycleCount == desiredCycleCount) then
- printf("All cycle complete")
- break
- end
- cycleCount = cycleCount + 1
- printf(">>")
- printf(">>")
- printf(">>")
- end
- -- Done
- printf("Goodbye >>")
- read()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement