LazerAio

startup

Jul 10th, 2022 (edited)
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.31 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. print("Booting!")
  3. shell.run("set shell.allow_disk_startup false")
  4. modem = peripheral.wrap("right")
  5. hopper = peripheral.wrap("left")
  6. Disp = peripheral.wrap("botttom")
  7. CashItem = "Emerald" --The inventory name
  8. CashName = "minecraft:emerald"
  9. ServerAdress = 3 --IMPORTANT: MUST BE CORRECT!
  10.  
  11. --if Disp.getItemDetail(9) == nil then
  12. -- print("ATM OUT OF SERVICE! [EMPTY]")
  13. -- sleep(10)
  14. -- os.reboot()
  15. --elseif Disp.getItemDetail(9).count < 10 then
  16. -- print("ATM OUT OF SERVICE! [LOW]")
  17. -- sleep(10)
  18. -- os.reboot()
  19. --end
  20. function ALERT(T)
  21. term.setBackgroundColor(colors.black)
  22. term.setTextColor(colors.red)
  23. term.setCursorPos(1,1)
  24. print(T)
  25. sleep(5)
  26. os.reboot()
  27. end
  28. function COMS(adress,command,clientID)
  29. term.clear()
  30. term.setCursorPos(1,1)
  31. if command == "Deposit" then
  32. -- if Disp.getItemDetail(9).count == Disp.getItemLimit(9) then
  33. -- print("Failed to allocate inventory")
  34. -- else
  35. print("Please insert 10"..CashItem)
  36. while true do
  37. if hopper.getItemDetail(1) == nil then
  38. sleep(2)
  39. elseif hopper.getItemDetail(1).name == CashName and hopper.getItemDetail(1).count == 10 then
  40. hopper.pushItems("bottom",1)
  41. sleep(0.5)
  42. print("Wait...")
  43. break
  44. end
  45. -- end
  46. end
  47. end
  48. --Commands: Withdraw, Deposit, Balance
  49. print("Contacting server!")
  50. rednet.open("right")
  51. rednet.send(adress,"proof?")
  52. while true do
  53. RIX,MSG = rednet.receive(10)
  54. if RIX == adress or MSG == nil or MSG == "FAIL" then
  55. break
  56. end
  57. end
  58. print("Verified Server")
  59. if MSG == nil or MSG == "FAIL" then
  60. ALERT("Failed to communicate with server!")
  61. elseif string.upper(MSG) == string.upper(adress) then
  62. rednet.send(RIX,command)
  63. RXID,MSG = rednet.receive(10)
  64. if RXID == RIX and MSG == "Client?" then
  65. print("Protocall OK")
  66. sleep(0.2)
  67. rednet.send(adress,clientID)
  68. while true do
  69. RXID, MSG = rednet.receive(10)
  70. if RXID == adress then
  71. print("DONE!")
  72. sleep(0.2)
  73. if command == "Withdraw" then
  74. if MSG == "ok" then
  75. print("Dispensing...")
  76. rs.setOutput("bottom",false)
  77. for i=1,10 do
  78. print(i.."/10")
  79. rs.setOutput("bottom",true)
  80. sleep(0.1)
  81. rs.setOutput("bottom",false)
  82. sleep(0.1)
  83. end
  84. sleep(5)
  85. ALERT("TRANSACTION COMPLETED!")
  86. else
  87. ALERT("ERROR",MSG)
  88. end
  89. elseif command == "Deposit" then
  90. if MSG == "ok" then
  91. ALERT("TRANSACTION COMPLETED!")
  92. else
  93. ALERT("ERROR",MSG)
  94. end
  95. elseif command == "Bal" then
  96. ALERT(MSG)
  97. end
  98. elseif MSG == nil then
  99. ALERT("Failed to hold communication with server")
  100. end
  101. end
  102. elseif MSG == nil then
  103. ALERT("Lost communication with server!")
  104. else
  105. ALERT("Faild to verify server! [stage 2]")
  106. end
  107. else
  108. ALERT("Failed to verify server!")
  109. end
  110. end
  111. nOp = 1
  112. while true do
  113. term.clear()
  114. term.setCursorPos(1,1)
  115. print("Aio Terminal for Money (ATM)")
  116. print("")
  117. print("Version 1.0")
  118. print("")
  119. print("ATTENTION!")
  120. print("Withdrawals and/or deposits ocurr at own risk!")
  121. print("")
  122. print(os.date())
  123. print("")
  124. if nOp == 1 then
  125. print("Withdraw <<")
  126. print("Deposit ")
  127. print("See balance ")
  128. elseif nOp == 2 then
  129. print("Withdraw ")
  130. print("Deposit <<")
  131. print("See balance ")
  132. elseif nOp == 3 then
  133. print("Withdraw ")
  134. print("Deposit ")
  135. print("See balance <<")
  136. end
  137. E,K = os.pullEvent("key")
  138. if K == keys.up then
  139. if nOp == 1 then
  140. nOp = 2
  141. else
  142. nOp = nOp - 1
  143. end
  144. elseif K == keys.down then
  145. if nOp == 3 then
  146. nOp = 1
  147. else
  148. nOp = nOp + 1
  149. end
  150. elseif K == keys.enter then
  151. print("Please enter your username")
  152. USRN = read()
  153. print("Please enter your PIN")
  154. UPIN = read("*")
  155. term.setBackgroundColor(colors.lightGray)
  156. term.clear()
  157. term.setCursorPos(1,1)
  158. print("WELCOME",USRN)
  159. print("Please wait..")
  160. sleep(0.5)
  161. print("Starting communications with server!")
  162. if nOp == 1 then
  163. COMS(ServerAdress,"Withdraw",USRN..UPIN)
  164. elseif nOp == 2 then
  165. COMS(ServerAdress,"Deposit",USRN..UPIN)
  166. else
  167. COMS(ServerAdress,"Bal",USRN..UPIN)
  168. end
  169. break
  170. end
  171. end
  172. term.clear()
  173. term.setBackgroundColor(colors.black)
  174. term.setCursorPos(1,1)
  175. textutils.slowPrint("Thank you for using ATM!")
  176. sleep(0.1)
  177. os.reboot()
Add Comment
Please, Sign In to add comment