Advertisement
osmarks

TrilateratorNode

Jul 27th, 2018
1,678
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. shell.run "rm t"
  2. shell.run "pastebin get TPT3gpNF t"
  3. os.loadAPI "t"
  4.  
  5. local pos = {gps.locate()}
  6.  
  7. local function configure_modem(channels)
  8.     t.on_all_modems(t.wireless, "closeAll")
  9.     for _, c in pairs(channels) do t.on_all_modems(t.wireless, "open", c) end
  10. end
  11.  
  12. print(textutils.serialise(pos))
  13.  
  14. configure_modem({})
  15. t.on_all_modems(t.wired, "open", t.command_channel)
  16.  
  17. local function process_command(c)
  18.     if c.type == "set_channels" and c.channels and #c.channels <= 128 then
  19.         configure_modem(c.channels)
  20.     end
  21. end
  22.  
  23. while true do
  24.     local _, _, chan, reply_chan, message, distance = os.pullEvent "modem_message"
  25.     if chan == t.command_channel or chan == t.message_channel then process_command(message)
  26.     else
  27.         t.on_all_modems(t.wired, "transmit", t.message_channel, t.command_channel, {
  28.             channel = chan,
  29.             reply_channel = reply_chan,
  30.             message = message,
  31.             distance = distance,
  32.             time = os.day() + (os.time() / 24),
  33.             position = pos,
  34.             ID = os.getComputerID()
  35.         })
  36.     end
  37. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement