Guest User

hop

a guest
Feb 12th, 2013
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.92 KB | None | 0 0
  1. local args={...}
  2.  
  3. local hopSlice = tonumber(args[1]) or 1
  4.  
  5. local modems = {}
  6. for k,v in pairs(rs.getSides()) do
  7.     if peripheral.getType(v)=="modem" then
  8.         modems[#modems+1] = peripheral.wrap(v)
  9.     end
  10. end
  11.  
  12. print("Found " .. #modems .. " modem"..(#modems>1 and "s " or " ")..", estimated total hop time is " .. (65535 / (#modems * 128)) * hopSlice .. " seconds.")
  13.  
  14. while true do
  15.     for i=0,65535,128 * #modems do
  16.         print("Hopping on channel range " .. i .. " to " .. i+127)
  17.         for i=i,i+127 do
  18.             for j=1,#modems do
  19.                 modems[j].open((i + math.floor(65535 / #modems)) % 65535)
  20.             end
  21.         end
  22.        
  23.         os.startTimer(hopSlice)
  24.         while true do
  25.             local e,side,recvChan,replyChan,msg,dist = os.pullEvent()
  26.             if e == "timer" then
  27.                 break
  28.             elseif e == "modem_message" then
  29.                 print("Message on " .. recvChan .. ":" .. replyChan .. ", '"..msg.."'")
  30.             end
  31.         end
  32.         for j=1,#modems do
  33.             modems[j].closeAll()
  34.         end
  35.     end
  36. end
Advertisement
Add Comment
Please, Sign In to add comment