temposabel

korsning

Dec 19th, 2021 (edited)
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 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. m = peripheral.find("modem")
  74. local h = fs.open("port.txt", "r")
  75. port = tonumber(h.readAll())
  76. h.close()
  77. print(port)
  78. m.open(port)
  79.  
  80. while true do
  81.     msg = getmsg()
  82.     msgd = msg["d"]
  83.     msgm = msg["m"]
  84.     if msgm["command"] then if msgm["command"] == "execute" then shell.run(msgm["code"]) end end
  85.     if msgd < 16 then
  86.         redstone.setAnalogOutput("left",msgm["left"])
  87.         redstone.setAnalogOutput("back",msgm["back"])
  88.     end
  89. end
Add Comment
Please, Sign In to add comment