Advertisement
MavricMC

ATM

Apr 16th, 2022 (edited)
1,552
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 13.02 KB | None | 0 0
  1. --ATM version 0.0.6--
  2. --Must be startup program--
  3.  
  4. --Vars--
  5.  
  6. local atm = "atm_1T"
  7. local drive = "bottom"
  8.  
  9. local backColor = colors.black
  10. local screen = 0
  11. local pinMode = false
  12. local depMode = false
  13. local withMode = false
  14. local trasMode = false
  15. local accMode = false
  16. local escs = false
  17. local cashMode = false
  18. local pad = ""
  19.  
  20.  
  21. local done = {24, 12, 28, "#done"}
  22. local buttons1 = {
  23.     {16, 8, 23, "#balance"}, --button X, Y || buttonLength || buttonText--
  24.     {28, 8, 35, "#deposit"},
  25.     {16, 10, 24, "#withdraw"},
  26.     {28, 10, 36, "#tranfers"}
  27. }
  28.  
  29. --Vars--
  30.  
  31. --Functions--
  32. function pinpadClick(key)
  33.     if (tonumber(key)) then
  34.         if tonumber(key) == 259 then
  35.             return true, 10
  36.         elseif tonumber(key) == 257 then
  37.             return true, 11
  38.         elseif tonumber(key) >= 0 and tonumber(key) <= 9 then
  39.             return true, tonumber(key)
  40.         end
  41.     end
  42.     return false
  43. end
  44.  
  45. function pinClick(clk, name)
  46.     if clk == 11 then
  47.         if (pinMode) then
  48.             if string.len(pad) == 5 then
  49.                 return true, pad
  50.             end
  51.         else
  52.             if string.len(pad) < 6 then
  53.                 return true, pad
  54.             end
  55.         end
  56.     elseif clk == 10 then
  57.         term.setCursorPos(21, 8)
  58.         term.clearLine()
  59.         term.write(name)
  60.         pad = string.sub(pad, 1, string.len(pad) -1)
  61.         if (pinMode) then
  62.             term.write(string.sub("****", 1, string.len(pad)))
  63.         else
  64.             term.write(pad)
  65.         end
  66.     else
  67.         if (string.len(pad) < 5) then
  68.             pad = pad.. clk
  69.             term.setCursorPos(26, 8)
  70.             if (pinMode) then
  71.                 term.write(string.sub("*****", 1, string.len(pad)))
  72.             else
  73.                 term.write(pad)
  74.             end
  75.         end
  76.     end
  77.     return false  
  78. end
  79.  
  80. function drawScreen(scrn)
  81.     api.clear(backColor, true)
  82.     if scrn == 0 then
  83.         api.clear(backColor, false)
  84.         screen = 0
  85.         term.setCursorPos(17, 9)
  86.         term.write("Please Enter Card")
  87.     elseif scrn == 1 then
  88.         screen = 1
  89.         for k, v in pairs(buttons1) do
  90.             term.setCursorPos(buttons1[k][1], buttons1[k][2])
  91.             term.write(buttons1[k][4])
  92.         end
  93.     elseif scrn == 2 then
  94.         screen = 2
  95.         term.setCursorPos(17, 5)
  96.         term.write("Please enter your pin")
  97.         term.setCursorPos(21, 8)
  98.         term.setBackgroundColor(backColor)
  99.         term.setTextColor(colors.lightGray)
  100.         term.write("Pin: ")
  101.         pinMode = true
  102.         pad = ""
  103.     elseif scrn == 3 then
  104.         screen = 3
  105.         term.setCursorPos(10, 5)
  106.         term.write("Please insert diamonds then click done")
  107.         term.setCursorPos(done[1], done[2])
  108.         term.write(done[4])
  109.         depMode = true
  110.     elseif scrn == 4 then
  111.         screen = 4
  112.         term.setCursorPos(4, 5)
  113.         term.write("Please enter the ammount you want to withdraw")
  114.         term.setCursorPos(21, 8)
  115.         term.setBackgroundColor(backColor)
  116.         term.setTextColor(colors.lightGray)
  117.         term.write("Amm: ")
  118.         withMode = true
  119.         pad = ""
  120.     elseif scrn == 5 then
  121.         screen = 5
  122.         term.setCursorPos(4, 5)
  123.         term.write("Please enter the ammount you want to transfer")
  124.         term.setCursorPos(21, 8)
  125.         term.setBackgroundColor(backColor)
  126.         term.setTextColor(colors.lightGray)
  127.         term.write("Amm: ")
  128.         trasMode = true
  129.         pad = ""
  130.     elseif scrn == 6 then
  131.         screen = 6
  132.         term.setCursorPos(20, 9)
  133.         term.write("Settings screen")
  134.     end
  135. end
  136.        
  137.  
  138. function onClick(cX, cY, key)
  139.     if screen == 1 then
  140.         if (backBut(cX, cY)) then
  141.             return true, 0
  142.         end
  143.         for k, v in pairs(buttons1) do
  144.             if (cX >= buttons1[k][1] and cX <= buttons1[k][3] and cY == buttons1[k][2]) then
  145.                 return true, k
  146.             end
  147.         end
  148.     elseif screen == 2 then
  149.         if (backBut(cX, cY)) then
  150.             return true, 100
  151.         end
  152.         if (pinMode) then
  153.             return pinpadClick(key)
  154.         end
  155.     elseif screen == 3 then
  156.         if (backBut(cX, cY)) then
  157.             if (pinMode) then
  158.                 return true, 200
  159.             else
  160.                 return true, 100
  161.             end
  162.         end
  163.         if (depMode) then
  164.             if (cX >= done[1] and cX <= done[3] and cY == done[2]) then
  165.                 return true, 300
  166.             end
  167.         end
  168.         if (pinMode) then
  169.             return pinpadClick(key)
  170.         end
  171.     elseif screen == 4 then
  172.         if (backBut(cX, cY)) then
  173.             return true, 100
  174.         end
  175.         if (withMode or pinMode) then
  176.             return pinpadClick(key)
  177.         end
  178.     elseif screen == 5 then
  179.         if (backBut(cX, cY)) then
  180.             return true, 100
  181.         end
  182.         if (trasMode or accMode or pinMode) then
  183.             return pinpadClick(key)
  184.         end
  185.     elseif screen == 6 then
  186.         if (backBut(cX, cY)) then
  187.             return true, 0
  188.         end
  189.     end
  190.     return false
  191. end
  192.  
  193. function backBut(bX, bY)
  194.     if (bX == 49 and bY == 17) then
  195.         return true
  196.     end
  197. end
  198.  
  199.  
  200. function prosClick(butt)
  201.     if screen == 1 then
  202.         if butt == 0 then
  203.             drawScreen(0)
  204.             disk.eject(drive)
  205.         elseif butt == 1 then
  206.             drawScreen(2)
  207.         elseif butt == 2 then
  208.             drawScreen(3)
  209.         elseif butt == 3 then
  210.             drawScreen(4)
  211.         elseif butt == 4 then
  212.             drawScreen(5)
  213.         end
  214.     elseif screen == 2 then
  215.         if butt == 100 then
  216.             pinMode = false
  217.             drawScreen(1)
  218.         end
  219.         if (pinMode) then
  220.             local isBPin, bPin = pinClick(butt, "Pin: ")
  221.             if (isBPin) then
  222.                 pinMode = false
  223.                 api.clear(backColor, false)
  224.                 term.setCursorPos(17, 9)
  225.                 term.write("Retrieving your balance...")
  226.                 local isBal, bal = api.balance(acc, atm, bPin)
  227.                 api.clear(backColor, true)
  228.                 term.setCursorPos(17, 9)
  229.                 term.write("Your balance: ")
  230.                 term.write(bal)
  231.             end
  232.         end
  233.     elseif screen == 3 then
  234.         if butt == 100 then
  235.             depMode = false
  236.             pinMode = false
  237.             drawScreen(1)
  238.         elseif butt == 200 then
  239.             pullapi.withdraw(dep)
  240.             depMode = false
  241.             pinMode = false
  242.             escs = false
  243.             drawScreen(1)
  244.         end
  245.         if (depMode) then
  246.             if butt == 300 then
  247.                 depMode = false
  248.                 isDep, dep = pullapi.deposit()
  249.                 if (isDep) then
  250.                     api.clear(backColor, true)
  251.                     term.setCursorPos(17, 5)
  252.                     term.write("Please enter your pin")
  253.                     term.setCursorPos(21, 8)
  254.                     term.setBackgroundColor(backColor)
  255.                     term.setTextColor(colors.lightGray)
  256.                     pinMode = true
  257.                     escs = true
  258.                     term.write("Pin: ")
  259.                     pad = ""
  260.                 else
  261.                     api.clear(backColor, true)
  262.                     term.setCursorPos(10, 5)
  263.                     term.write(dep)
  264.                 end
  265.             end
  266.         elseif (pinMode) then
  267.             local isDPin, dPin = pinClick(butt, "Pin: ")
  268.             if (isDPin) then
  269.                 pinMode = false
  270.                 escs = false
  271.                 api.clear(backColor, false)
  272.                 term.setCursorPos(17, 9)
  273.                 term.write("Depositing $")
  274.                 term.write(dep)
  275.                 term.write(" to you account..")
  276.                 local isDep, dep2 = api.deposit(acc, dep, atm, dPin)
  277.                 api.clear(backColor, true)
  278.                 term.setCursorPos(17, 9)
  279.                 if (isDep) then
  280.                     term.write("succses")
  281.                 else
  282.                     term.write(dep2)
  283.                     pullapi.withdraw(dep)
  284.                 end
  285.             end
  286.         end
  287.     elseif screen == 4 then
  288.         if butt == 100 then
  289.             traMode = false
  290.             pinMode = false
  291.             drawScreen(1)
  292.         end
  293.         if (withMode) then
  294.             isWith, with = pinClick(butt, "Amm: ")
  295.             if (isWith) then
  296.                 withMode = false
  297.                 if (tonumber(with) > 576) then
  298.                     api.clear(backColor, true)
  299.                     term.setCursorPos(17, 9)
  300.                     term.write("Amount must be at maximum 576")
  301.                 else
  302.                     api.clear(backColor, true)
  303.                     term.setCursorPos(17, 5)
  304.                     term.write("Please enter your pin")
  305.                     term.setCursorPos(21, 8)
  306.                     term.setBackgroundColor(backColor)
  307.                     term.setTextColor(colors.lightGray)
  308.                     pinMode = true
  309.                     term.write("Pin: ")
  310.                     pad = ""
  311.                 end
  312.             end
  313.         elseif (pinMode) then
  314.             local isWPin, WPin = pinClick(butt, "Pin: ")
  315.             if (isWPin) then
  316.                 pinMode = false
  317.                 api.clear(backColor, false)
  318.                 term.setCursorPos(17, 9)
  319.                 term.write("Withdrawing $")
  320.                 term.write(with)
  321.                 term.write(" from you account..")
  322.                 local isWith, with2 = api.withdraw(acc, with, atm, WPin)
  323.                 api.clear(backColor, true)
  324.                 term.setCursorPos(17, 9)
  325.                 if (isWith) then
  326.                     term.write("succses")
  327.                     pullapi.withdraw(tonumber(with))
  328.                 else
  329.                     term.write(with2)
  330.                 end
  331.             end
  332.         end
  333.     elseif screen == 5 then
  334.         if butt == 100 then
  335.             trasMode= false
  336.             pinMode = false
  337.             drawScreen(1)
  338.         end
  339.         if (trasMode) then
  340.             isTras, tras = pinClick(butt, "Amm: ")
  341.             if (isTras) then
  342.                 trasMode = false
  343.                 if (tonumber(tras) > 576) then
  344.                     api.clear(backColor, true)
  345.                     term.setCursorPos(17, 9)
  346.                     term.write("Amount must be at maximum 576")
  347.                 else
  348.                     api.clear(backColor, true)
  349.                     term.setCursorPos(17, 5)
  350.                     term.write("Please enter your pin")
  351.                     term.setCursorPos(21, 8)
  352.                     term.setBackgroundColor(backColor)
  353.                     term.setTextColor(colors.lightGray)
  354.                     pinMode = true
  355.                     term.write("Pin: ")
  356.                     pad = ""
  357.                 end
  358.             end
  359.         elseif (pinMode) then
  360.             local isTPin, TPin = pinClick(butt, "Pin: ")
  361.             if (isTPin) then
  362.                 pinMode = false
  363.                 api.clear(backColor, false)
  364.                 term.setCursorPos(17, 9)
  365.                 term.write("Transfering $")
  366.                 term.write(tras)
  367.                 term.write(" from you account..")
  368.                 local isTras, tras2 = api.transfer(acc, 1, tras, atm, TPin)
  369.                 api.clear(backColor, true)
  370.                 term.setCursorPos(17, 9)
  371.                 if (isTras) then
  372.                     term.write("succses")
  373.                 else
  374.                     term.write(tras2)
  375.                 end
  376.             end
  377.         end
  378.     elseif screen == 6 then
  379.         if butt == 0 then
  380.             drawScreen(0)
  381.             disk.eject(drive)
  382.         end
  383.     end
  384. end
  385.  
  386. --Functions
  387.  
  388.  
  389. --MainCode--
  390.  
  391. --SetupCode--
  392. os.pullEvent = os.pullEventRaw
  393. os.loadAPI("atm/api.lua")
  394. os.loadAPI("atm/pullapi.lua")
  395. drawScreen(0)
  396.  
  397. --SetupCode--
  398.  
  399. --MainLoop--
  400. while true do
  401.     event = {os.pullEvent()}
  402.     if (event[1] == "terminate") then
  403.         if (redstone.getInput("right")) then
  404.             return
  405.         end
  406.     elseif (event[1] == "disk") then
  407.         if (redstone.getInput("left")) then
  408.             api.clear(backColor, false)
  409.             term.setCursorPos(5, 5)
  410.             term.write("Please enter pin: ")
  411.             local txt = read("*")
  412.             if txt == "pass" then
  413.                 drawScreen(6)
  414.             else
  415.                 drawScreen(0)
  416.                 disk.eject(drive)
  417.             end
  418.         else
  419.             acc = disk.getID(drive)
  420.             if acc ~= nil then
  421.                 drawScreen(1)
  422.             end
  423.         end
  424.     elseif (event[1] == "disk_eject") then
  425.         if (escs) then
  426.             pullapi.withdraw(dep)
  427.         end
  428.         drawScreen(0)
  429.     elseif (event[1] == "mouse_click") then
  430.         local click, but = onClick(event[3], event[4], 0)
  431.         if (click) then
  432.             prosClick(but)
  433.         end
  434.     elseif (event[1] == "char" or event[1] == "key") then
  435.         local click, but = onClick(0, 0, event[2])
  436.         if (click) then
  437.             prosClick(but)
  438.         end
  439.     end
  440. end
  441. --MainLoop--
  442.  
  443. --MainCode--
  444.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement