Advertisement
LeslieCraft

Minecraft WiFi universal test

Nov 3rd, 2013
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.45 KB | None | 0 0
  1. local thisID = os.getComputerID()
  2. local otherID = "999999"
  3.  
  4. local function openRednet()
  5.     local listOfSides = rs.getSides()
  6.     local listofPossibles = {}
  7.     local counter1 = 0
  8.     while true do
  9.       counter1 = counter1 +1
  10.  
  11.       if peripheral.isPresent(tostring(listOfSides[counter1])) and peripheral.getType(listOfSides[counter1]) == "modem" then
  12.        table.insert(listofPossibles,tostring(listOfSides[counter1]))
  13.       end
  14.  
  15.       if counter1 == 6 and table.maxn(listofPossibles) == 0 then
  16.        print("no wifi present")
  17.        return nil
  18.       end
  19.  
  20.       if counter1 == 6 and table.maxn(listofPossibles) ~= 0 then
  21.        rednet.open(listofPossibles[1])
  22.        return listofPossibles[1]
  23.       end
  24.     end
  25. end
  26.  
  27. local function openMonitor()
  28.     local listOfSides = rs.getSides()
  29.     local listofPossibles = {}
  30.     local counter1 = 0
  31.     while true do
  32.       counter1 = counter1 +1
  33.  
  34.       if peripheral.isPresent(tostring(listOfSides[counter1])) and peripheral.getType(listOfSides[counter1]) == "monitor" then
  35.        table.insert(listofPossibles,tostring(listOfSides[counter1]))
  36.       end
  37.  
  38.       if counter1 == 6 and table.maxn(listofPossibles) == 0 then
  39.        print("no monitor present")
  40.        return nil
  41.       end
  42.  
  43.       if counter1 == 6 and table.maxn(listofPossibles) ~= 0 then
  44.        monitor = peripheral.wrap(listofPossibles[1])
  45.        return listofPossibles[1]
  46.       end
  47.     end
  48. end
  49.  
  50. modemOn = openRednet()
  51. monitorOn = openMonitor()
  52.  
  53. function newLine()
  54.   _,cY = monitor.getCursorPos()
  55.   monitor.setCursorPos(1,cY+1)
  56. end
  57.  
  58. function printAll(message)
  59.     print(message)
  60.     newLine()
  61.     monitor.write(message)
  62. end
  63. function printAll2(message)
  64.     monitor.setCursorPos(1,cY)
  65.     term.clearLine()
  66.     monitor.clearLine()
  67.     print(message)
  68.     monitor.write(message)
  69. end
  70.  
  71. if modemOn == nil then
  72.     printAll("No WIFI Modem")
  73.     printAll("Will shutdown in 3 seconds")
  74.     sleep(3)
  75.     os.shutdown()
  76. else
  77.     printAll("Opened wifi on "..modemOn.." side")
  78.     printAll("thisId: " .. thisID)
  79.     while not redstone.getInput("bottom") do
  80.         while otherID == "999999" do
  81.             rednet.broadcast(thisID)
  82.             senderId, message, distance = rednet.receive(1)
  83.             if senderId ~= thisID and message ~= nil then
  84.                 otherID = message
  85.             end
  86.         end
  87.         sleep(.1)
  88.     end
  89.     sleep(.5)
  90.     rednet.broadcast(thisID)
  91.     printAll("otherId: " .. tostring(otherID))
  92.     newLine()
  93.     newLine()
  94.     while redstone.getInput("bottom") do
  95.         sleep(.1)
  96.         printAll2("Redstone active")
  97.     end
  98.     printAll2("Redstone deactive")
  99.     sleep(2)
  100.     printAll("Will shutdown in 3 seconds")
  101.     sleep(3)
  102.     os.reboot()
  103. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement