thatparadox

dislocatorTeleGate

May 2nd, 2017
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. rednet.open("left")
  2. mon = periheral.wrap("bottom")
  3. incMessage = "false"
  4.  
  5. function drawBackground()
  6.   mon.setBackgroundColor(colors.black)
  7.   mon.clear()
  8.   x,y = mon.getSize()
  9.   for yc = 1,y do
  10.     if yc%2 == 1 then
  11.       mon.setBackgroundColor(colors.red)
  12.     else
  13.       mon.setBackgroundColor(colors.orange)
  14.     end
  15.     for xc = 1,x do
  16.       mon.setCursorPos(xc, yc)
  17.       mon.write(" ")
  18.     end
  19.   --mon.setCursorPos(x/2,yc)
  20.   --mon.write(yc)
  21.   end
  22. end
  23.  
  24.  
  25. function drawButtons()
  26.   x,y = mon.getSize()
  27.   for i=1,y do
  28.     if fs.exists(tostring(i)) then
  29.       file = fs.open(tostring(i), "r")
  30.       label = file.readAll()
  31.       file.close()
  32.       if i%2 == 1 then
  33.         mon.setBackgroundColor(colors.red)
  34.       else
  35.         mon.setBackgroundColor(colors.orange)
  36.       end
  37.       mon.setTextColor(colors.black)
  38.       mon.setCursorPos(x/2 - string.len(label)/2, i)
  39.       mon.write(label)
  40.     end
  41.   end
  42. end
  43.  
  44. while true do
  45.   drawBackground()
  46.   drawButtons()
  47.   term.clear()
  48.   term.setCursorPos(1,1)
  49.   print("Press any key to delete destinations")
  50.   event, p1, p2, p3 =os.pullEvent()
  51.   if event == "Monitor_touch" then
  52.     if fs.exists(p2) then
  53.       file = fs.open(p2, "r")
  54.       newMessage = file.read()
  55.       file.close()
  56.       rednet.broadcast(newMessage, "tele")
  57.       incID, incMessage = rednet.receive("tele", 1)
  58.       if incMessage == "true" then
  59.         turtle.select(1)
  60.         turtle.drop()
  61.         sleep(5)
  62.         turtle.suck()
  63.       else
  64.         mon.clear()
  65.         mon.setCursorPos(1,1)
  66.         mon.write("No active")
  67.         mon.setCursorPos(1,3)
  68.         mon.write("portal")
  69.         sleep(1)
  70.       end
  71.       incMessage = "false"
  72.     else
  73.       mon.clear()
  74.       mon.setCursorPos(1,1)
  75.       mon.write("Not Set")
  76.       sleep(1)
  77.     end
  78.   elseif event == "turtle_inventory" then
  79.     itemData = turtle.getItemDetail(16)
  80.     if itemData <> nil then
  81.       newDestination = itemData.name
  82.     end
  83.     findBlank = 1
  84.     while fs.exists(findBlank) = true do
  85.       findBlank = findBlank + 1
  86.     end
  87.     fs.open(tostring(findBlank), "w")
  88.     file.write(newDestination)
  89.     file.close()
  90.   elseif event == "key" then
  91.     print("counting down from the top, enter the number of the line to delete.")
  92.     term.write(">")
  93.     toDelete = read()
  94.     fs.delete(toDelete)  
  95.   end
  96. end
Add Comment
Please, Sign In to add comment