Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --name FrameMaster
- --version 1.0a
- local version = "1.0a"
- rednet.open("right")
- local side = {}
- side.batbox = 0
- side.chest = 4
- local batteryId = {}
- batteryId.full = 38041
- batteryId.empty = 5272
- local inventory = {}
- inventory.batbox = "Empty"
- inventory.chest = false
- inventory.chestFull = 0
- inventory.chestEmpty = 0
- local function output(str)
- term.clear()
- term.setCursorPos(1,1)
- print(string.format("FrameMaster (v%s)",version))
- print("By BigTwisty")
- print("-----------------")
- print(str)
- end
- local function move()
- redstone.setOutput("left", true)
- while turtle.detectUp() do
- os.sleep(0.1)
- end
- redstone.setOutput("left", false)
- redstone.setOutput("back", true)
- while not turtle.detectUp() do
- os.sleep(0.1)
- end
- redstone.setOutput("back", false)
- end
- local function rednetBroadcastAndWait(outMessage, inMessage)
- while true do
- rednet.broadcast(outMessage)
- id,msg,dist = rednet.receive(0.5)
- if msg == inMessage then
- return id
- end
- end
- end
- local sorter = peripheral.wrap("front")
- output("Waiting for MasterPC")
- rednetBroadcastAndWait("FrameMaster Init", "FrameMaster Ok")
- while true do
- inventory.batbox = "Not Found..."
- x = sorter.list(side.batbox)
- if x ~= nil then
- inventory.batbox = "Empty"
- for id,qty in pairs(x) do
- if id == batteryId.full then
- inventory.batbox = "Full"
- else
- inventory.batbox = "Discharging"
- end
- end
- end
- inventory.chestFull = 0
- inventory.chestEmpty = 0
- x = sorter.list(side.chest)
- if x == nil then
- inventory.chest = false
- else
- inventory.chest = true
- for id,qty in pairs(x) do
- if id == batteryId.full then
- inventory.chestFull = inventory.chestFull + qty
- elseif id == batteryId.empty then
- inventory.chestEmpty = inventory.chestEmpty + qty
- end
- end
- end
- output(string.format("\n-- Status:\nBatbox: %s",
- inventory.batbox))
- write(string.format("-- Inventory:\nCharged: %d\nEmpty: %d\n",
- inventory.chestFull,
- inventory.chestEmpty))
- if inventory.batbox == "Discharging" then
- sorter.extract(side.batbox, batteryId.empty, side.chest, 1)
- elseif inventory.batbox == "Empty" then
- sorter.extract(side.chest, batteryId.full, side.batbox, 1)
- end
- id,msg,dist = rednet.receive(0.3)
- if msg == "FrameMaster Move" then
- move()
- rednet.send(masterPC, "FrameMaster Finished")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment