Advertisement
thatparadox

SpatialTeleport V2.1

Jul 28th, 2015
350
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.32 KB | None | 0 0
  1. mon = peripheral.find("monitor")
  2. for k,v in pairs(rs.getSides()) do
  3.   if peripheral.getType(v) == "modem" then
  4.    rednet.open(v)
  5.   end
  6. end
  7.  
  8. freqRange = 60 --If you want a second network or other people are using ender chests used by this program you can change this number. Must be the same on all computers on this network.
  9.  
  10. ECInput = peripheral.wrap("top")
  11. ECOutput = peripheral.wrap("bottom")
  12. ioPort = peripheral.wrap("right")
  13.  
  14. function drawBackground()
  15.   mon.setBackgroundColor(colors.black)
  16.   mon.clear()
  17.   x,y = mon.getSize()
  18.   for yc = 1,y do
  19.     if yc%2 == 1 then
  20.       mon.setBackgroundColor(colors.purple)
  21.     else
  22.       mon.setBackgroundColor(colors.magenta)
  23.     end
  24.     for xc = 1,x do
  25.       mon.setCursorPos(xc, yc)
  26.       mon.write(" ")
  27.     end
  28.   end
  29. end
  30.  
  31. function inputPage(level)
  32.   mon.clear()
  33.   mon.setBackgroundColor(colors.pink)
  34.   mon.setCursorPos(1, 1)
  35.   mon.write("go to")
  36.   mon.setCursorPos(1, 2)
  37.   mon.write("computer")
  38.   term.clear()
  39.   x,y = term.getSize()
  40.   term.setCursorPos(x/2-8, y/2-2)
  41.   print("Enter Name")
  42.   term.setCursorPos(2, y/2)
  43.   print("        ")
  44.   term.setCursorPos(2, y/2)
  45.   label = read()
  46.   term.setBackgroundColor(colors.black)
  47.   term.clear()
  48.   file = fs.open(tostring(param3), "w")
  49.   file.write(label)
  50.   file.close()
  51. end
  52.  
  53. function drawButtons()
  54.   x,y = mon.getSize()
  55.   for i=1,y do
  56.     if fs.exists(tostring(i)) then
  57.       file = fs.open(tostring(i), "r")
  58.       label = file.readAll()
  59.       file.close()
  60.       mon.setCursorPos(x/2 - string.len(label)/2, i)
  61.       if i%2 == 1 then
  62.         mon.setBackgroundColor(colors.purple)
  63.       else
  64.         mon.setBackgroundColor(colors.magenta)
  65.       end
  66.       mon.setTextColor(colors.white)
  67.       mon.write(label)
  68.       mon.setCursorPos(x, i)
  69.       mon.setBackgroundColor(colors.black)
  70.       mon.setTextColor(colors.white)
  71.       mon.write("X")
  72.     end
  73.   end
  74. end
  75.  
  76. if fs.exists("freq") then --
  77.   file = fs.open("freq", "r")
  78.   freq = file.readAll()
  79.   file.close()
  80. else
  81.   mon.clear()
  82.   mon.setCursorPos(1,1)
  83.   mon.write("GO TO")
  84.   mon.setCursorPos(1,1)
  85.   mon.write("COMPUTER")
  86.   term.clear()
  87.   term.setCursorPos(1,1)
  88.   print("Enter a unique number for where you want this pad to appear on the touchscreen. 1 is the top of the screen:")
  89.   write("> ")
  90.   freq = read()
  91.   file = fs.open("freq", "w")
  92.   file.write(freq)
  93.   file.close()
  94. end
  95. if fs.exists("incCheck") == false then
  96.   print("Installing IncCheck")
  97.   shell.run("pastebin get zLBpFvAn incCheck")
  98. end
  99.  
  100. ECInput.setFrequency(freq + freqRange)
  101. ECOutput.setFrequency(freqRange)
  102. mon.clear()
  103. drawBackground()
  104. drawButtons()
  105.  
  106. shell.openTab("incCheck")
  107. while true do
  108.   x,y=mon.getSize()
  109.   event, param1, param2, param3, param4 = os.pullEvent() --destination selected or new destination being set
  110.   if event == "monitor_touch" and param2 < x then
  111.     if fs.exists(tostring(param3)) then -- existing destination selected
  112.       rednet.broadcast("up",freq)
  113.       ECInput.setFrequency(freqRange)
  114.       ECOutput.setFrequency(param3 + freqRange)
  115.       ECOutput.pullItem("west",1,1,1)
  116.       os.sleep(.2)
  117.       ECOutput.pushItem("west",1)
  118.       if ECInput.pushItem("East",1) == 1 then
  119.         var = ioPort.getStackInSlot(2)
  120.         while var == nil do
  121.           rs.setAnalogOutput("right", 1)
  122.           sleep(0.5)
  123.           rs.setOutput("right", false)
  124.           var = ioPort.getStackInSlot(2)
  125.           print("Attempting to deploy image")
  126.           sleep(0.5)
  127.         end
  128.         rednet.broadcast("down",freq)
  129.         ioPort.pushItem("down", 2)
  130.         ECInput.setFrequency(freqRange + freq)
  131.         var = ECOutput.getStackInSlot(1)
  132.         while var ~= nil do
  133.           sleep(0.1)
  134.           var = ioPort.getStackInSlot(1)
  135.         end
  136.         ECOutput.setFrequency(freqRange)
  137.       else
  138.         mon.clear()
  139.         mon.setCursorPos(1,1)
  140.         mon.write("No Drive")
  141.         sleep(1)
  142.       end
  143.     else -- user selected blank part of the screen and wants to add new destination
  144.       inputPage(param3)
  145.     end
  146.     mon.clear()
  147.     drawBackground()
  148.     drawButtons()
  149.   elseif event == "modem_message" and param4.message == "freq" then -- frequency requested from PylonCom
  150.     sleep(.1)
  151.     rednet.send(param3, freq)
  152.   elseif event == "monitor_touch" then
  153.     fs.delete(tostring(param3))
  154.     mon.clear()
  155.     drawBackground()
  156.     drawButtons()
  157.   end
  158. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement