Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local crewId = 0
- local mineTaskDist = 0
- local startMine = false
- local mineTaskRemain = 0
- local raisedUp = false
- math.randomseed(os.time())
- print("Attempting bootup of cakesoft CREW miner, hold CTRL+T to terminate - DO NOT DISTRIBUTE")
- local modem = peripheral.wrap("left")
- modem.open(8972) -- general broadcast
- modem.open(8973) -- only for dm to captain
- function BootupRight()
- local comp = peripheral.wrap("right")
- comp.turnOn()
- end
- if pcall(BootupRight) then
- print("Booted up right computer succsesfuly")
- else
- modem.transmit(8972, 8972, "FINBOOT")
- end
- local wait = true
- while wait do
- print("Waiting")
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- if event then
- wait = false
- print("Got begining message: "..message)
- crewId = math.floor(math.random()*1000)
- end
- end
- function CORE()
- while true do
- os.sleep(0)
- if (mineTaskRemain > 0) then
- turtle.forward()
- turtle.dig()
- turtle.digUp()
- turtle.digDown()
- mineTaskRemain = mineTaskRemain - 1
- print(mineTaskRemain)
- end
- end
- end
- function FUELANDLABEL()
- while true do
- print("FUELANDLABEL S")
- local fuel = turtle.getFuelLevel()
- os.setComputerLabel("Crew ID"..crewId.." | Fuel level: "..fuel)
- coroutine.yield()
- if turtle.getFuelLevel() < 100 then
- print("Fuel level below 100, attempting refuel")
- local refuelled = false
- for n = 1, 16 do -- edited from refuel.lua rom/programs
- -- Stop if we've reached the limit, or are fully refuelled.
- if turtle.getFuelLevel() >= turtle.getFuelLimit() then
- break
- end
- turtle.select(n)
- if turtle.refuel() then
- refuelled = true
- end
- end
- if not refuelled then
- modem.transmit(8973, 8973, "FUEL CRITICALY LOW - INPUT COAL (Computer Id = "..crewId..")")
- print("Uh oh - could not refuel")
- end
- end
- end
- end
- function MODEMCORE()
- while true do
- local event, side, channel, replyChannel, message, distance = os.pullEvent("modem_message")
- if event then
- local args = {}
- print("Got message '"..message.."'")
- for i in string.gmatch(message, "%S+") do
- table.insert(args, i)
- end
- print("Got order: "..args[1])
- if (args[1] == "MF") then --MF means to go however much the 2nd arg is
- mineTaskDist = tonumber(args[2])
- print(tonumber(args[2]))
- mineTaskRemain = mineTaskDist
- if not raisedUp then
- turtle.up()
- raisedUp = true
- end
- end
- end
- end
- end
- print("Running cakesoft miner (Crew)")
- parallel.waitForAny(CORE, FUELANDLABEL, MODEMCORE)
Add Comment
Please, Sign In to add comment