MarsP4ste

readyScreen--ATM

Jun 12th, 2021 (edited)
740
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local event = require("event")
  2. local com = require("component")
  3. local term = require("term")
  4. local shell = require("shell")
  5. local sizeX, sizeY, sizeXO, sizeYO, sizeXR, sizeYR = term.getViewport()
  6. local gpu = term.gpu()
  7. local rs = nil
  8. local ready = true
  9. term.setCursorBlink(false)
  10.  
  11. for e in com.list("interface") do
  12.   rs = com.proxy(e)
  13.   break
  14. end
  15.  
  16. function clearScreen()
  17.   gpu.setBackground(0x365991, false)
  18.   term.clear()
  19.   term.setCursor(1,1)
  20. end
  21.  
  22. function writeText(n)
  23.   local text = "This ATM is ready for usage"
  24.   local text2 = "Hit the screen to begin"
  25.   if n ~= 3 then
  26.     if n == 1 then
  27.       text2 = "Welcome"
  28.     end
  29.  
  30.     len1 = string.len(text)/2
  31.     len2 = string.len(text2)/2
  32.  
  33.     term.setCursor(sizeX/2-len1,sizeY/2-1)
  34.     print(text)
  35.  
  36.     term.setCursor(sizeX/2-len2,sizeY/2+1)
  37.     print(text2)
  38.   else
  39.     text = "There is a problem with this ATM"
  40.     text2 = "Please inform the bank staff"
  41.     len1 = sizeX/2-string.len(text)/2
  42.     len2 = sizeX/2-string.len(text2)/2
  43.    
  44.     setCursor(len1,sizeY/2-1)
  45.     print(text)
  46.     setCursor(len2,sizeY/2+1)
  47.     print(text2)
  48.   end
  49. end
  50.  
  51.  
  52. ---Execute programm
  53. shell.execute("/home/allOff.lua")
  54. clearScreen()
  55. if rs.getItems().n ~= 0 then
  56.   ready = false
  57.   writeText(3)
  58. else
  59.   writeText(0)
  60. end
  61. while (true) do --wait for an Input from a user to start the ATM program
  62.   local _,_,x,y,_,n = event.pull("touch")
  63.   if x == 1 and y == 1 then
  64.     shell.execute("reboot")
  65.   elseif ready then
  66.     break
  67.   end
  68. end
  69. clearScreen()
  70. writeText(1)
  71. os.sleep(1)
  72. shell.execute("/home/atm.lua")
RAW Paste Data