Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nbMiners = 8
- local nbLoaders = 1
- -- MODEM CONFIG
- local idChannel = 10
- local idRespChannel = 11
- local cmdChannel = 12
- local cmdRespChannel = 13
- -- MONITOR CONFIG
- os.loadAPI("button")
- local modem = peripheral.wrap("right")
- local monitor = peripheral.wrap("top")
- -- MONITOR MAIN TABLE
- function fillMainTable()
- button.setTable("getIds", bgetIds, 10,20,3,5)
- button.setTable("mine", bmine, 22,32,3,5)
- button.screen()
- end
- -- MONITOR TOUCH EVENT
- function getClick()
- event, side, x, y = os.pullEvent("monitor_touch")
- button.checkxy(x,y)
- end
- -- BUTTON GETIDS
- function bgetIds()
- button.flash("getIds")
- getWorkersId()
- end
- -- BUTTON MINE
- function bmine()
- button.toggleButton("mine")
- mine()
- button.toggleButton("mine")
- end
- -- MINING PROCESS
- function mine()
- modem.open(cmdRespChannel)
- local op={name="mine", mode=1}
- modem.transmit(cmdChannel,cmdRespChannel,textutils.serialize(op))
- local repMinerCount = 0
- local repLoaderCount = 0
- local waiting = true
- while ( waiting ) do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- if ( modemSide == "right") then
- local rep=textutils.unserialize(message)
- if (rep.name == "waiting" ) then
- print("ID:"..(rep.ID).."label:"..(rep.label).."type:"..(rep.wType))
- if ( rep.wType == "miner" ) then
- repMinerCount = repMinerCount + 1
- elseif ( rep.wType == "chunkLoader" ) then
- repLoaderCount = repLoaderCount +1
- end
- end
- if ( repMinerCount == nbMiners and repLoaderCount == nbLoaders ) then
- waiting = false
- modem.close(cmdRespChannel)
- print(repMinerCount.." miners waiting.")
- print(repLoaderCount.." chunk loaders identified.")
- end
- end
- end
- modem.close(cmdRespChannel)
- end
- -- GATHER WORKERS DATA
- function getWorkersId()
- print("open idRespChannel")
- modem.open(idRespChannel)
- print("Transmit request to idChannel("..idChannel..")")
- local op={name="ID"}
- print("op.name= "..op.name)
- modem.transmit(idChannel,idRespChannel,textutils.serialize(op))
- print("transmit OK")
- local repMinerCount = 0
- local repLoaderCount = 0
- local waiting = true
- while ( waiting ) do
- print("Waiting for answers")
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- local rep=textutils.unserialize(message)
- if (rep.name == "ID" ) then
- print("ID:"..(rep.ID).."label:"..(rep.label).."type:"..(rep.wType))
- if ( rep.wType == "miner" ) then
- repMinerCount = repMinerCount + 1
- elseif ( rep.wType == "chunkLoader" ) then
- repLoaderCount = repLoaderCount +1
- end
- end
- if ( repMinerCount == nbMiners and repLoaderCount == nbLoaders ) then
- waiting = false
- modem.close(idRespChannel)
- print(repMinerCount.." miners identified.")
- print(repLoaderCount.." chunk loaders identified.")
- end
- end
- modem.close(idRespChannel)
- end
- monitor.clear()
- fillMainTable()
- button.heading("Mining System")
- while true do
- getClick()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement