CelticCoder

cashRegisterPhone

Jun 25th, 2024 (edited)
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. rednet.open("back")
  2. monitor = peripheral.wrap("top")
  3.  
  4. server = 3
  5.  
  6. function displayBalance(balance)
  7.     monitor.clear()
  8.     monitor.setCursorPos(1, 2)
  9.     monitor.write("Welcome!")
  10.     monitor.setCursorPos(1, 4)
  11.     monitor.write("$" .. balance)
  12. end
  13.  
  14. function checkOut(balance)
  15.     confirmation = false
  16.     rednet.broadcast("buyrequest " .. balance)
  17.     temp, message2 = rednet.receive(nil, 3)
  18.     if message2 == "ping" then
  19.         phoneid = temp
  20.         confirmation = true
  21.     end
  22.     temp, message2 = rednet.receive(nil, 3)
  23.     if message2 == "ping" then
  24.         phoneid = temp
  25.         confirmation = true
  26.     end
  27.     if confirmation then
  28.         print("Request Sent")
  29.         rednet.send(server, "serverbuyrequest " .. balance .. " " .. phoneid)
  30.         id, success = rednet.receive(nil, 60)
  31.         if success ~= "true" then
  32.             print("Server did not return successful payment")
  33.             rednet.send(server, "removebuyrequest " .. balance .. " " .. phoneid)
  34.             newid, success = rednet.receive(nil, 2)
  35.             if success ~= nil then
  36.                 print("Order " .. success .. "ly received")
  37.             else
  38.                 print("Server did not Respond")
  39.             end
  40.         else
  41.             print("SUCCESS!")
  42.             return true
  43.         end
  44.     else
  45.         print("Phone Response Failed")
  46.     end
  47.     return false
  48. end
  49.  
  50. function evaluateFormula(formula)
  51.     -- Load the formula as a Lua function
  52.     local func, err = load("return " .. formula)
  53.    
  54.     -- Check if there was an error compiling the formula
  55.     if not func then
  56.         return nil, "Invalid formula: " .. err
  57.     end
  58.    
  59.     -- Execute the function and return the result
  60.     local success, result = pcall(func)
  61.     if success then
  62.         return result
  63.     else
  64.         return nil, "Error evaluating formula: " .. result
  65.     end
  66. end
  67.  
  68. balance = 0
  69. displayBalance(balance)
  70.  
  71. while true do
  72.     print("type end to confirm order \n")
  73.     print("Current Order: $" .. balance)
  74.     input = io.read()
  75.     if input == "end" then
  76.         success = checkOut(balance)
  77.         if success then
  78.             break
  79.         end
  80.     end
  81.     if input ~= 0 and input ~= "end" then
  82.         balance = balance + evaluateFormula(input)
  83.         displayBalance(balance)
  84.     end
  85. end
  86. monitor.clear()
  87. monitor.setCursorPos(1, 2)
  88. monitor.write("Thank")
  89. monitor.setCursorPos(1, 4)
  90. monitor.write("You!")
  91. os.sleep(5)
  92. displayBalance(0)
  93.  
  94.    
Advertisement
Add Comment
Please, Sign In to add comment