Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local m = peripheral.find "modem"
- local ioside = "bottom"
- local io = peripheral.wrap(ioside)
- local channel = 15216
- local energy = 1.97e6
- m.open(channel)
- local function attempt_swap()
- if not io.getItemMeta(1) then return false, "no cell" end
- if io.getNetworkEnergyStored() < energy then return false, "insufficient energy" end
- rs.setOutput(ioside, true)
- sleep(0.2)
- rs.setOutput(ioside, false)
- return true
- end
- while true do
- local _, _, c, rc, msg = os.pullEvent "modem_message"
- if type(msg) == "table" and msg[1] == "swap" then
- local ok, err = attempt_swap()
- print("SWAP", ok, err)
- m.transmit(channel, channel, {"swapped", ok, err})
- elseif type(msg) == "table" and msg[1] == "ping" then
- m.transmit(channel, channel, {"pong"})
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement