Advertisement
MaGuSware2012

Accident Counter for MC

May 12th, 2013
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.74 KB | None | 0 0
  1. local monitor = peripheral.wrap("back")
  2. local seconds = 0
  3. local minutes = 0
  4. local hours = 0
  5. local days = 0
  6.  
  7. local filename = "counter_save.mag"
  8.  
  9. function ticker ()
  10.     while true do
  11.         seconds = seconds + 1
  12.        
  13.         if seconds == 60 then
  14.             seconds = 0
  15.             minutes = minutes + 1
  16.          
  17.             os.remove(filename)
  18.             file = io.open(filename, "w")
  19.             if file != nil then
  20.                 file:write(minutes)
  21.                 file:write(hours)
  22.                 file:write(days)
  23.                
  24.                 file:close()
  25.             end
  26.         end
  27.        
  28.         if minutes == 60 then
  29.             minutes = 0
  30.             hours = hours + 1
  31.         end
  32.        
  33.         if hours == 24 then
  34.             hours = 0
  35.             days = days + 1
  36.         end
  37.        
  38.         myString = tonumber(days) .. ":" .. tonumber(hours) .. ":" .. tonumber(minutes) .. ":" .. tonumber(seconds)
  39.      
  40.         monitor.clear()
  41.        
  42.         monitor.setCursorPos(1,1)
  43.         monitor.write("Accident free for")
  44.      
  45.         local x,y = monitor.getSize()
  46.      
  47.         monitor.setCursorPos(1 + math.ceil((x/2)-(myString:len()/2)), math.ceil(y/2))
  48.         monitor.write(myString)
  49.        
  50.         sleep(1)
  51.     end
  52. end
  53.  
  54. function resetter ()
  55.     while true do
  56.         term.setTextColor(colors.white)
  57.        
  58.         term.clear()
  59.         term.setCursorPos(1,1)
  60.        
  61.         term.write("Enter reset password:")
  62.        
  63.         local pwd = read("*")
  64.        
  65.         if pwd == "whoopsie" then
  66.             break
  67.         else
  68.             term.setTextColor(colors.red)
  69.             term.clear()
  70.             term.setCursorPos(1,1)
  71.              
  72.             term.write("bad password")
  73.             sleep(3)
  74.         end
  75.     end
  76. end
  77.  
  78. --startup--
  79. file = io.open(filename, "r")
  80. if file != nil then
  81.     minutes = file:read("n")
  82.     hours = file:read("n")
  83.     days = file:read("n")
  84.    
  85.     file:close()
  86. end
  87.  
  88. --main--
  89. while true do
  90.   parallel.waitForAny(ticker, resetter)
  91.  
  92.   term.setTextColor(colors.lime)
  93.   term.clear()
  94.   term.setCursorPos(1,1)
  95.   term.write("password accepted, counter reset")
  96.  
  97.   sleep(3)
  98. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement