petomka

Untitled

Aug 12th, 2014
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.19 KB | None | 0 0
  1. local redside = "back" -- Redstone Output Seite
  2. local monside = "top" -- Seite des Monitors
  3.  
  4. local option1 = 60   -- Zeit fuer Option1 in s
  5. local option2 = 120  -- Zeit fuer Option2 in s
  6. local option3 = 180  -- Zeit fuer Option3 in s
  7. local option4 = 300  -- Zeit fuer Option4 in s
  8. local option5 = 600  -- zeit fuer Option5 in s
  9.  
  10. local input = 0 -- Diesen Wert nicht veraendern
  11. local time = 0 -- Diesen Wert nicth veraendern
  12.  
  13. m = peripheral.wrap(monside)
  14. m.clear()
  15.  
  16. redstone.setOutput(redside,false)
  17.  
  18. function Layout()
  19.  m.setBackgroundColor(colors.cyan)
  20.  m.clear()
  21.  m.setCursorPos(1,1)
  22.  m.write(option1)
  23.  m.write("          ")
  24.  
  25.  m.setBackgroundColor(colors.green)
  26.  m.setCursorPos(1,2)
  27.  m.write(option2)
  28.  m.write("          ")
  29.  
  30.  m.setBackgroundColor(colors.yellow)
  31.  m.setCursorPos(1,3)
  32.  m.write(option3)
  33.  m.write("          ")
  34.  
  35.  m.setBackgroundColor(colors.orange)
  36.  m.setCursorPos(1,4)
  37.  m.write(option4)
  38.  m.write("          ")
  39.  
  40.  m.setBackgroundColor(colors.red)
  41.  m.setCursorPos(1,5)
  42.  m.write(option5)
  43.  m.write("          ")
  44. end
  45.  
  46. Layout()
  47.  
  48. function SetTime()
  49.  if input == 1 then
  50.   time = option1
  51.  elseif input == 2 then
  52.   time = option2
  53.  elseif input == 3 then
  54.   time = option3
  55.  elseif input == 4 then
  56.   time = option4
  57.  elseif input == 5 then
  58.   time = option5
  59.  end
  60. end
  61.  
  62. function CancelButton()
  63.  m.setBackgroundColor(colors.green)
  64.  m.setTextColor(colors.red)
  65.  m.setCursorPos(1,5)
  66.  m.write("Cancel")
  67.  m.setBackgroundColor(colors.red)
  68.  m.setTextColor(colors.white)
  69. end
  70.  
  71. function Timer()
  72.  while time >= 0.2 do
  73.   CancelButton()
  74.   m.clear()
  75.   m.setCursorPos(1,3)
  76.   m.write(time)
  77.   time = time - 0.1
  78.   sleep(0.1)
  79.   event,side,x,y = os.pullEvent()
  80.   if event == "monitor_touch" then
  81.    if x >= 1 and y == 5 then
  82.     time = 0
  83.     break
  84.    end
  85.   end
  86.  end
  87. end
  88.  
  89. local function isIn( tbl, value ) --#table search function.
  90. for k, v in pairs( tbl ) do
  91.   if v == value then
  92.    return true
  93.   end
  94. end
  95. return false
  96. end
  97.  
  98. function doRedstone( side, time )
  99.  rs.setOutput( side, true ) --#turn on redstone
  100.  local ids = {}
  101.  for i = 0.1, time, 0.1 do --#make a bunch of timers.
  102.   ids[ #ids + 1 ] = os.startTimer( i )
  103.  end
  104.  local num = 0
  105.  while true do --#loop
  106.   local event = {os.pullEvent()} --#pull an event
  107.   if event[ 1 ] == "timer" and event[ 2 ] == ids[ #ids ] then --#last timer is up
  108.    break --#exit the loop
  109.   elseif event[ 1 ] == "monitor_touch" and event[ 3 ] >= 1 and event[ 4 ] == 5 then --#button was pushed
  110.    break --#exit the loop
  111.   elseif event[ 1 ] == "timer" and isIn( ids, event[ 2 ] ) then --#the event was a timer we made, but not the last one
  112.    num = num + 0.1
  113.    term.setCursorPos( 1, 1 )
  114.    term.write( num )
  115.   end
  116.  end
  117.  rs.setOutput( side, false ) --#turn off redstone
  118. end
  119.  
  120. function Toggle()
  121.  Layout()
  122.  SetTime()
  123.  doRedstone()
  124.  Layout()
  125. end
  126.  
  127. while true do
  128.  event,side,x,y = os.pullEvent()
  129.  if event == "monitor_touch" then
  130.   if x >= 1 and y == 1 then
  131.    input = 1
  132.    Toggle()
  133.   elseif x >= 1 and y == 2 then
  134.    input = 2
  135.    Toggle()
  136.   elseif x >= 1 and y == 3 then
  137.    input = 3
  138.    Toggle()
  139.   elseif x >= 1 and y == 4 then
  140.    input = 4
  141.    Toggle()
  142.   elseif x >= 1 and y == 5 then
  143.    input = 5
  144.    Toggle()
  145.   end
  146.  end
  147. end
Advertisement
Add Comment
Please, Sign In to add comment