Advertisement
Theshadow989

Inventory Manager (Receiver)

Jul 10th, 2022 (edited)
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.62 KB | None | 0 0
  1. --[[
  2. Inventory Manager (Receiver)
  3. Written by TheShadow989
  4. ]]--
  5.  
  6. --[[
  7. Modem Channels (Inverse of Sender)
  8.  
  9. senderChannel = Unique channel number used for modem communication.
  10. replyChannel = Unique channel for this computer to reply back.
  11.  
  12. ]]--
  13.  
  14. local senderChannel = 1
  15. local replyChannel = 2
  16.  
  17. -- Working Variables (DO NOT CHANGE)
  18. local sides = {"top", "bottom", "left", "right", "front", "back"}
  19. local modem = "" -- Modem
  20.  
  21. --Find Modem Side
  22. for i=1, #sides do
  23.     if peripheral.isPresent(sides[i]) then
  24.         if peripheral.getType(sides[i]) == "modem" then
  25.             modem = sides[i]
  26.         end
  27.     end
  28. end
  29.  
  30. -- Sender Channel
  31. modem.open(senderChannel)
  32.  
  33. --------------------------------------------------------------------------
  34. --  PROGRAM LOOP
  35. --------------------------------------------------------------------------
  36. while true do
  37.     local e = {os.pullEvent()}
  38.  
  39.     if e[1] == "modem_message" and e[3] == senderChannel then
  40.         local message
  41.         local index = 1
  42.        
  43.         for str in string.gmatch(e[5], "[^;]+") do
  44.             message[index] = str
  45.             index = index + 1
  46.         end
  47.  
  48.         if message[1] == "Mob" then
  49.             if message[2] == "ON" then
  50.                 redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.red))
  51.             else
  52.                 redstone.setBundledOutput("back", colors.subtract(redstone.getBundledOutput("back"), colors.red))
  53.             end
  54.         elseif message[1] == "Mining" then
  55.             if message[2] == "ON" then
  56.                 redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.blue))
  57.             else
  58.                 redstone.setBundledOutput("back", colors.subtract(redstone.getBundledOutput("back"), colors.blue))
  59.             end
  60.         elseif message[1] == "Option3" then
  61.             if message[2] == "ON" then
  62.                 redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.yellow))
  63.             else
  64.                 redstone.setBundledOutput("back", colors.subtract(redstone.getBundledOutput("back"), colors.yellow))
  65.             end
  66.         elseif message[1] == "Option4" then
  67.             if message[2] == "ON" then
  68.                 redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.orange))
  69.             else
  70.                 redstone.setBundledOutput("back", colors.subtract(redstone.getBundledOutput("back"), colors.orange))
  71.             end
  72.         elseif message[1] == "Option5" then
  73.             if message[2] == "ON" then
  74.                 redstone.setBundledOutput("back", colors.combine(redstone.getBundledOutput("back"), colors.green))
  75.             else
  76.                 redstone.setBundledOutput("back", colors.subtract(redstone.getBundledOutput("back"), colors.green))
  77.             end
  78.         end
  79.            
  80.         modem.transmit(replyChannel, senderChannel, message[1] + ";" + message[2])
  81.     end
  82. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement