Advertisement
Fooman

Liquicrafter Pulser

Apr 22nd, 2013
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.37 KB | None | 0 0
  1. --[[
  2. Redstone Pulser for Liquicrafter
  3. by Fooman
  4. v1.0
  5. April 20, 2013
  6. ]]--
  7. local iter
  8. local w,h = term.getSize()
  9.  
  10.  
  11. --Delay Between Pulses
  12. local mindelay = 0.2
  13. --Side to output signal
  14. local outputside = "bottom"
  15. --Timer of success screen before program reboots
  16. local reboottimer = 60
  17.  
  18.  
  19. function pulse()
  20.     rs.setOutput(tostring(outputside), true)
  21.     sleep(0.1)
  22.     rs.setOutput(tostring(outputside), false)
  23.     sleep(mindelay)
  24. end
  25. --Pretty Functions
  26. local function printCentered(str,ypos)
  27.     term.setCursorPos(w/2 - #str/2, ypos)
  28.     term.write(str)
  29. end
  30. local function printRight(str,ypos)
  31.     term.setCursorPos(w - #str, ypos)
  32.     term.write(str)
  33. end
  34. local function printLeft(str,ypos)
  35.     term.setCursorPos(1 , ypos)
  36.     term.write(str)
  37. end
  38. function drawTerminalBG()
  39.     term.clear()
  40.     printCentered(string.rep("-",w),1)
  41.     printCentered("LiquiCrafter Control System", 2)
  42.     printCentered(string.rep("-",w),3)
  43.     printLeft("|",2)
  44.     printRight("|",2)
  45.         local th = 4
  46.     for th=4,h-1 do
  47.         printLeft("|",th)
  48.         printRight("|",th)
  49.     end
  50.     printCentered("How many items would you like to craft?", 7)
  51.     printCentered(string.rep("-",w),h)
  52.     term.setCursorPos(w/2-1,9)
  53. end
  54.  
  55. function drawTerminalProgress(prog)
  56.     printCentered("Currently Crafting:", 11)
  57.     term.setCursorPos(1,12)
  58.     term.clearLine()
  59.     printLeft("|",12)
  60.     printRight("|",12)
  61.     printCentered(tostring(prog),12)
  62. end
  63.  
  64. function drawTerminalSuccess()
  65.     term.setCursorPos(1,7)
  66.     term.clearLine()
  67.     printLeft("|",7)
  68.     printRight("|",7)
  69.     term.setCursorPos(1,9)
  70.     term.clearLine()
  71.     printLeft("|",9)
  72.     printRight("|",9)
  73.     term.setCursorPos(1,11)
  74.     term.clearLine()
  75.     printLeft("|",11)
  76.     printRight("|",11)
  77.     term.setCursorPos(1,12)
  78.     term.clearLine()
  79.     printLeft("|",12)
  80.     printRight("|",12)
  81.     printCentered("Success! "..tostring(iter).." items crafted.", 10)
  82.     printCentered("Press any key to continue.",12)
  83. end
  84.  
  85. --Program Start
  86. term.clear()
  87. drawTerminalBG()
  88. iter = tonumber(read())
  89. --could use stuff to ensure good input
  90.  
  91. for i=1,iter do
  92.     pulse()
  93.     drawTerminalProgress(i)
  94. end
  95.    
  96. --Finished
  97. drawTerminalSuccess()
  98. local autotimer = os.startTimer(tonumber(reboottimer))
  99. local event = os.pullEvent()
  100. if event == "key" then
  101.     os.reboot()
  102. elseif event == "timer" then
  103.     os.reboot()
  104. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement