Advertisement
Guest User

holodeck2

a guest
May 12th, 2015
1,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.33 KB | None | 0 0
  1. --Requires the Touchpoint API
  2. --Meant to be used on a 7x3 advanced monitor
  3. --Consult http://imgur.com/a/0UYWx for more information
  4. --By thecraftinggod/tunasushi
  5.  
  6. os.loadAPI("touchpoint")
  7. local buttons = touchpoint.new("monitor_0")
  8. local close = touchpoint.new("monitor_0")
  9. local loading = touchpoint.new("monitor_0")
  10. local t = touchpoint.new("monitor_0")
  11. local mon = peripheral.wrap("monitor_0")
  12. mon.setTextScale(0.5)
  13. chest = peripheral.wrap("container_chest_2")
  14. spatialio = peripheral.wrap("tilespatialioport_1")
  15. local modem = peripheral.wrap("right")
  16. active = false
  17. program = 0
  18.  
  19. function closeHolodeck()
  20.   rs.setOutput("back",false)
  21.   t = loading
  22.   t:draw()
  23.   drawUI()
  24.   spatialio.pullItem("east",program,1,1)
  25.   sleep(.2)
  26.   rs.setOutput("bottom", true)
  27.   sleep(.2)
  28.   rs.setOutput("bottom", false)
  29.   sleep(.2)
  30.   chest.pullItem("west",2,1,program)
  31.   active = false
  32. end
  33.  
  34. function loadHolodeck(n)
  35.   t = loading
  36.   t:draw()
  37.   drawUI()
  38.   program = n
  39.   spatialio.pullItem("east",n,1,1)
  40.   sleep(.2)
  41.   rs.setOutput("bottom", true)
  42.   sleep(.2)
  43.   rs.setOutput("bottom", false)
  44.   sleep(.2)
  45.   chest.pullItem("west",2,1,n)
  46.   active = true
  47.   rs.setOutput("back",true)
  48. end
  49. math.randomseed(os.time())
  50. function writeNumbers()
  51.   term.write(math.random(1000,9999).."   "..math.random(100000,999999).."  "..math.random(10,99).."  "..math.random(1000,9999).."  "..math.random(1000,9999).."  "..math.random(1000,9999).."  "..math.random(1000,9999).."  "..math.random(10,99))
  52. end
  53.  
  54. function drawUI()
  55.   paintutils.drawFilledBox(1,1,8,4,6)
  56.   paintutils.drawFilledBox(1,6,8,9,8)
  57.   paintutils.drawFilledBox(2,10,8,10,8)
  58.   paintutils.drawFilledBox(4,11,143,11,8)
  59.   paintutils.drawFilledBox(1,15,8,25,16384)
  60.   paintutils.drawFilledBox(1,27,8,39,2)
  61.   paintutils.drawFilledBox(2,14,8,14,16384)
  62.   paintutils.drawFilledBox(4,13,143,13,16384)
  63.   local icon = paintutils.loadImage("holodeckicon")
  64.   local buttons = paintutils.loadImage("buttons")
  65.   paintutils.drawImage(icon,98,1)
  66.   paintutils.drawImage(buttons,60,1)
  67.   term.setTextColor(2)
  68.   term.setBackgroundColor(32768)
  69.   term.setCursorPos(12,6)
  70.   writeNumbers()
  71.   term.setCursorPos(12,7)
  72.   writeNumbers()
  73.   term.setCursorPos(12,8)
  74.   writeNumbers()
  75.   term.setCursorPos(12,9)
  76.   writeNumbers()
  77.   term.setBackgroundColor(2)
  78.   term.setTextColor(32768)
  79.   term.setCursorPos(67,9)
  80.   term.write(math.random(1000,9999).."-"..math.random(100,999))
  81.   term.setCursorPos(86,4)
  82.   term.write(math.random(1000,9999).."-"..math.random(100,999))
  83.   term.setBackgroundColor(8)
  84.   term.setCursorPos(67,4)
  85.   term.write(math.random(1000,9999).."-"..math.random(100,999))
  86.   term.setCursorPos(86,9)
  87.   term.write(math.random(1000,9999).."-"..math.random(100,999))
  88. end
  89.  
  90. close:add("Close",nil,10,15,143,37,colors.red,colors.red)
  91. loading:add("Loading...",nil,10,15,143,37,colors.gray,colors.gray)
  92. r1 = "Leo's Room"
  93. r2 = "Brandon's Room"
  94. r3 = "Forest on Gamma-6"
  95. r4 = "Room 4"
  96. r5 = "Room 5"
  97. r6 = "Room 6"
  98. buttons:add(r1,nil,10,15,53,25,2,2)
  99. buttons:add(r2,nil,55,15,98,25,2,2)
  100. buttons:add(r3,nil,100,15,143,25,2,2)
  101. buttons:add(r4,nil,10,27,53,37,8,8)
  102. buttons:add(r5,nil,55,27,98,37,8,8)
  103. buttons:add(r6,nil,100,27,143,37,8,8)
  104.  
  105. rs.setOutput("back",false)
  106. modem.open(404)
  107.  
  108. while true do
  109.   if active then
  110.     t = close
  111.   else
  112.     t = buttons
  113.   end
  114.   t:draw()
  115.   term.redirect(mon)
  116.   drawUI()
  117.  
  118.   local event,p1,p2,p3,p4 = t:handleEvents(os.pullEvent())
  119.   if event == "modem_message" then
  120.     if p4 == "close" and active then
  121.       closeHolodeck()
  122.     elseif p4 == "p1" and not active then
  123.       loadHolodeck(1)
  124.     elseif p4 == "p2" and not active then
  125.       loadHolodeck(2)
  126.     elseif p4 == "p3" and not active then
  127.       loadHolodeck(3)
  128.     elseif p4 == "p4" and not active then
  129.       loadHolodeck(4)
  130.     elseif p4 == "p5" and not active then
  131.       loadHolodeck(5)
  132.     elseif p4 == "p6" and not active then
  133.       loadHolodeck(6)
  134.     end
  135.   elseif event == "button_click" then
  136.     if active then
  137.       if p1 == "Close" then
  138.         closeHolodeck()
  139.       end
  140.     else
  141.       if p1 == r1 then
  142.         loadHolodeck(1)
  143.       elseif p1 == r2 then
  144.         loadHolodeck(2)
  145.       elseif p1 == r3 then
  146.         loadHolodeck(3)
  147.       elseif p1 == r4 then
  148.         loadHolodeck(4)
  149.       elseif p1 == r5 then
  150.         loadHolodeck(5)
  151.       elseif p1 == r6 then
  152.         loadHolodeck(6)
  153.       end
  154.     end
  155.   end
  156. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement