Nyaar

[CC] Defense System

Jun 6th, 2012
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.23 KB | None | 0 0
  1. local side = "back" -- Change this to the side the transmitter is on
  2.  
  3. -- DEFENSE SYSTEM
  4. -- Version: 1.4
  5. -- Code by: Nyaar
  6.  
  7. local status = rs.getOutput(side)
  8. local loop = true
  9. local bRead = true
  10. local w,h = term.getSize()
  11.  
  12. function printC(str, y)
  13.  term.setCursorPos(1,y)
  14.  term.clearLine()
  15.  term.setCursorPos(w/2 - #str/2, y)
  16.  term.write(str)
  17. end
  18.  
  19. function printLB(str, y)
  20.  term.setCursorPos(1, y)
  21.  print(string.rep(str, w-1))
  22. end
  23.  
  24. function logo(status)
  25. term.clear()
  26. term.setCursorPos(1,1)
  27. local sStatus = ""
  28. if (status == true) then
  29.  printLB("=",1)
  30.  print("|  Defense System             Status: Unarmed  |")
  31.  printLB("=",3)
  32.  sStatus = "arm"
  33. else
  34.  printLB("=",1)
  35.  print("|  Defense System               Status: Armed  |")
  36.  printLB("=",3)
  37.  sStatus = "disarm"
  38. end
  39.  
  40. printC("Press ENTER to "..sStatus.." system.", 5)
  41. printC("Press BACKSPACE to quit.",6)
  42. end
  43.  
  44. while (loop) do
  45. logo(status)
  46. bRead = true
  47. while (bRead) do
  48.  local sEvent, param = os.pullEventRaw("key")
  49.  if (sEvent == "key") then
  50.   if (param == 28) then
  51.    status =  not status
  52.    rs.setOutput(side,status)
  53.    bRead = false
  54.   elseif (param == 14) then
  55.    bRead = false
  56.    loop = false
  57.   end
  58.  end
  59. end
  60. end
  61.  
  62. term.clear()
  63. term.setCursorPos(1,1)
Advertisement
Add Comment
Please, Sign In to add comment