Advertisement
iMajesticButter

Untitled

Feb 14th, 2022
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. local modem = peripheral.find("modem", rednet.open);
  2.  
  3. local idFilename = "id"
  4.  
  5. local protocol = "Potion_Brewer_BELT_SELECTOR"
  6. local logging = "Potion_Brewer_LOGGER"
  7.  
  8. local id = ""
  9.  
  10. function log(string)
  11. print(string)
  12. rednet.broadcast("[BELT_SELECTOR_"..id.."] "..string, logging)
  13. end
  14.  
  15. function init()
  16.  
  17. -- get this selectors id
  18. local idFile = fs.open(idFilename, "r")
  19. if idFile then
  20. id = idFile.readAll()
  21. idFile.close()
  22. else
  23. log("failed to open item file: "..idFilename)
  24. end
  25.  
  26. log("ID file loaded, this selector is: "..id)
  27.  
  28. rednet.host(protocol, id)
  29.  
  30. --wait for an event to dispense the item
  31. while true do
  32. --receive messages
  33. local senderID, message = rednet.receive(protocol)
  34. print(message)
  35.  
  36. local eventName = "EVENT_BELT_SELECT_"..id
  37.  
  38. if string.find(message, eventName) then
  39. --get the setting value
  40. log("attemting to set belt selection")
  41.  
  42. local setting = string.sub(message, #eventName + 1, #message)
  43. setting = tonumber(setting)
  44.  
  45. -- select the belt
  46. rs.setAnalogOutput("back", setting)
  47.  
  48. --respond with a dispense started event
  49. rednet.broadcast("EVENT_BELT_SELECT_FINNISHED_" .. id .. " " .. setting, protocol)
  50. log("selected belt: " .. setting)
  51. end
  52. end
  53. end
  54.  
  55. init()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement