Advertisement
MacaroMan

Lotto ATM V2

Feb 10th, 2025 (edited)
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.02 KB | None | 0 0
  1. drivePerf = peripheral.find("drive")
  2. speaker = peripheral.find("speaker")
  3.  
  4. function LoadDrive()
  5.     local waiting = true
  6.     WaitingForDriveDisplay()
  7.     while waiting do
  8.         if drivePerf.isDiskPresent() then
  9.             if fs.exists("disk/bal.txt") then
  10.                 speaker.playNote("bit", 1, 24)
  11.                 DisplayBal()
  12.                 return
  13.             end
  14.             speaker.playNote("bit", 1, 0)
  15.             drivePerf.setDiskLabel("Lotto Card")
  16.             local file = fs.open("disk/bal.txt", "w")
  17.             file.write(0)
  18.             file.close()
  19.             DisplayBal()
  20.         end
  21.         sleep(0)
  22.     end
  23. end
  24.  
  25. function WaitingForDriveDisplay()
  26.     term.clear()
  27.     term.setCursorPos(1,1)
  28.     paintutils.drawFilledBox(1, 1, 51, 19, colors.lightGray)
  29.     paintutils.drawFilledBox(11, 5, 41, 15, colors.gray)
  30.     paintutils.drawFilledBox(20, 9, 32, 11, colors.white)
  31.     term.setCursorPos(21,10)
  32.     term.setTextColor(colors.black)
  33.     term.write("Insert Disk")
  34.     while not(drivePerf.isDiskPresent()) do
  35.         sleep(0)
  36.     end
  37.     term.clear()
  38.     term.setCursorPos(1,1)
  39. end
  40.  
  41.  
  42.  
  43. function DisplayBal()
  44.     local file = fs.open("disk/bal.txt", "r")
  45.     local bal = file.readLine()
  46.     term.clear()
  47.     term.setCursorPos(1,1)
  48.     paintutils.drawFilledBox(1, 1, 51, 19, colors.lightGray)
  49.     paintutils.drawFilledBox(11, 5, 41, 15, colors.gray)
  50.     paintutils.drawFilledBox(15, 7, 38, 9, colors.white)
  51.    
  52.     term.setCursorPos(17,8)
  53.     term.setTextColor(colors.black)
  54.     term.write("Bal: ")
  55.     term.write(bal)
  56.  
  57.     paintutils.drawFilledBox(15, 11, 25, 13, colors.green)
  58.  
  59.     term.setCursorPos(17,12)
  60.     term.setTextColor(colors.black)
  61.     term.write("Deposit")
  62.  
  63.     paintutils.drawFilledBox(27, 11, 38, 13, colors.red)
  64.  
  65.     term.setCursorPos(29,12)
  66.     term.setTextColor(colors.black)
  67.     term.write("Withdraw")
  68.  
  69.     while drivePerf.isDiskPresent() do
  70.  
  71.         local event, button, x, y = os.pullEvent()
  72.         if event == "mouse_click" then
  73.             --deposit
  74.             if x >= 15 and x <= 25 and y >= 11 and y <= 13 then
  75.                 speaker.playNote("bit", 1, 20)
  76.                 Deposit()
  77.                 return
  78.             end
  79.  
  80.             --withdraw
  81.             if x >= 27 and x <= 38 and y >= 11 and y <= 13 then
  82.                 speaker.playNote("bit", 1, 5)
  83.                 Withdraw()
  84.                 return
  85.             end
  86.         end
  87.         if event == "timer" then
  88.             sleep(0)
  89.         end
  90.         sleep(0)
  91.     end
  92.     speaker.playNote("bit", 1, 0)
  93.     term.clear()
  94.     term.setCursorPos(1,1)
  95. end
  96.  
  97. function GetDiamonds()
  98.     local totalDiamonds = 0
  99.     for i = 1, 27 do
  100.         local item = results[i]
  101.         if item ~= nil then
  102.             if item.name == "minecraft:diamond" then
  103.                 totalDiamonds = totalDiamonds + item.count
  104.             end
  105.         end
  106.     end
  107.  
  108.     return totalDiamonds
  109. end
  110.  
  111. function Deposit()
  112.    
  113. end
  114.  
  115. function Withdraw()
  116.    
  117. end
  118.  
  119. while true do
  120.     LoadDrive()
  121.     sleep(0)
  122. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement