Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.find("modem", rednet.open);
- local itemFilename = "item"
- local protocol = "Potion_Brewer_Ingredient_Dispenser_Node_v001"
- local logging = "Potion_Brewer_LOGGER"
- local item = ""
- function log(string)
- print(string)
- rednet.broadcast("[DISPENSER_NODE_"..item.."] "..string, logging)
- end
- function init()
- --turn out rs output
- rs.setOutput("back", false)
- -- get this nodes item id
- local itemFile = fs.open(itemFilename, "r")
- if itemFile then
- item = itemFile.readAll()
- itemFile.close(itemFile)
- else
- log("failed to open item file: "..itemFilename)
- end
- log("Items file loaded, this node is: "..item)
- rednet.host(protocol, item)
- --wait for an event to dispense the item
- while true do
- --receive messages
- local senderID, message = rednet.receive(protocol)
- print(message)
- if message == "EVENT_DISPENSE_" .. item then
- --send the redstone pulse
- log("attempting to dispense item: " .. item)
- rs.setOutput("back", true)
- os.sleep(0.5)
- rs.setOutput("back", false)
- --respond with a dispense started event
- rednet.broadcast("EVENT_DISPENSE_STARTED_" .. item, protocol)
- log("dispensed item: " .. item)
- end
- end
- end
- init()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement