PaymentOption

PaymentDoorMenu

Apr 8th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.09 KB | None | 0 0
  1. rednet.open("left")
  2. local selection = 1
  3.  
  4. local function cPrint(height, string)
  5.     local w,h = term.getSize()
  6.    
  7.     xPos = w/2 - string.len(string)/2
  8.     term.setCursorPos(xPos, height)
  9.     term.write(string)
  10. end
  11.  
  12. local function printDoorMenu()
  13.     if selection == 1 then cPrint(6, ">> Open")
  14.     else                   cPrint(6, "   Open") end
  15.    
  16.     if selection == 2 then cPrint(7, ">> Close")
  17.     else                   cPritn(7, "   Close") end
  18.    
  19.     if selection == 3 then cPrint(8, ">> Exit")
  20.     else                   cPrint(8, "   Exit") end
  21. end
  22.  
  23. while true do
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26.     pritnDoorMenu()
  27.    
  28.     event, key = os.pullEvent("key")
  29.    
  30.     if key == 200 and selection > 1 then selection = selection-1
  31.     else if key == 208 and selection < 3 then selection = selection+1
  32.     end
  33.    
  34.     if selection == 1 and key == 28 then
  35.         rednet.send(174, "open")
  36.         rednet.send(173, "open")
  37.         cPrint(10, "Door Opened.")
  38.         sleep(2)
  39.     elseif selection == 2 and key == 28 then
  40.         rednet.send(174, "close")
  41.         rednet.send(173, "close")
  42.         cPrint(10, "Door Closed.")
  43.         sleep(2)
  44.     elseif selection == 3 and key == 28 then
  45.         os.reboot()
  46.     end
  47. end
Advertisement
Add Comment
Please, Sign In to add comment