Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local component = require("component")
- local event = require("event")
- local modem = component.modem
- local redstone = component.redstone
- local sides = require("sides")
- channel_number = 1
- modem.open(channel_number)
- function check_cart()
- if redstone.getInput(sides.left) > 0 then
- return true
- else
- return false
- end
- end
- function send_cart()
- if check_cart() then
- print("Sending cart...")
- redstone.setOutput(sides.right, 16)
- os.execute("sleep ".. tonumber(2))
- redstone.setOutput(sides.right, 0)
- print("Cart sent.")
- return true
- else
- return false
- end
- end
- while true do
- _, localAddress, remoteAddress, port, distance, message = event.pull("modem_message")
- print("Request recieved")
- print("Request from: ", remoteAddress)
- print("Message is: ", message)
- if tostring(message) == "send_cart" then
- result = send_cart()
- print("Cart available: ", result)
- modem.send(remoteAddress, 10, result)
- print("Response sent")
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement