Advertisement
iMajesticButter

potionDispenserNodeStartup

Feb 15th, 2022
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.37 KB | None | 0 0
  1. local modem = peripheral.find("modem", rednet.open);
  2.  
  3. local itemFilename = "item"
  4.  
  5. local protocol = "Potion_Brewer_Ingredient_Dispenser_Node_v001"
  6. local logging = "Potion_Brewer_LOGGER"
  7.  
  8. local item = ""
  9.  
  10. function log(string)
  11.     print(string)
  12.     rednet.broadcast("[DISPENSER_NODE_"..item.."] "..string, logging)
  13. end
  14.  
  15. function init()
  16.     --turn out rs output
  17.     rs.setOutput("back", false)
  18.  
  19.     -- get this nodes item id
  20.     local itemFile = fs.open(itemFilename, "r")
  21.     if itemFile then
  22.         item = itemFile.readAll()
  23.         itemFile.close(itemFile)
  24.     else
  25.         log("failed to open item file: "..itemFilename)
  26.     end
  27.  
  28.     log("Items file loaded, this node is: "..item)
  29.  
  30.     rednet.host(protocol, item)
  31.  
  32.     --wait for an event to dispense the item
  33.     while true do
  34.         --receive messages
  35.         local senderID, message = rednet.receive(protocol)
  36.         print(message)
  37.  
  38.         if message == "EVENT_DISPENSE_" .. item then
  39.             --send the redstone pulse
  40.             log("attempting to dispense item: " .. item)
  41.  
  42.             rs.setOutput("back", true)
  43.             os.sleep(0.5)
  44.             rs.setOutput("back", false)
  45.  
  46.             --respond with a dispense started event
  47.             rednet.broadcast("EVENT_DISPENSE_STARTED_" .. item, protocol)
  48.             log("dispensed item: " .. item)
  49.         end
  50.     end
  51. end
  52.  
  53. init()
  54.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement