SHOW:
|
|
- or go back to the newest paste.
| 1 | - | os.pullEvent = os.pullEventRaw |
| 1 | + | rednet.open("back")
|
| 2 | - | checkoutcomputer = 32 |
| 2 | + | |
| 3 | - | alogin = "adminpassword" |
| 3 | + | |
| 4 | server = 3 | |
| 5 | - | function connect() |
| 5 | + | |
| 6 | - | rednet.open("bottom")
|
| 6 | + | |
| 7 | monitor.clear() | |
| 8 | monitor.setCursorPos(1, 2) | |
| 9 | - | success = pcall(connect) |
| 9 | + | |
| 10 | - | if not success then |
| 10 | + | |
| 11 | - | os.reboot() |
| 11 | + | |
| 12 | end | |
| 13 | ||
| 14 | function checkOut(balance) | |
| 15 | - | if not monitor then |
| 15 | + | confirmation = false |
| 16 | - | os.reboot() |
| 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 | - | success = false |
| 28 | + | print("Request Sent")
|
| 29 | - | while success ~= "true" do |
| 29 | + | rednet.send(server, "serverbuyrequest " .. balance .. " " .. phoneid) |
| 30 | - | rednet.send(checkoutcomputer, balance) |
| 30 | + | id, success = rednet.receive(nil, 60) |
| 31 | - | id, success = rednet.receive() |
| 31 | + | if success ~= "true" then |
| 32 | print("Server did not return successful payment")
| |
| 33 | - | print("SUCCESS!")
|
| 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 input == alogin then |
| 61 | + | |
| 62 | - | os.exit(1) |
| 62 | + | |
| 63 | else | |
| 64 | return nil, "Error evaluating formula: " .. result | |
| 65 | - | checkOut(balance) |
| 65 | + | |
| 66 | - | break |
| 66 | + | |
| 67 | ||
| 68 | - | if input ~= 0 then |
| 68 | + | |
| 69 | - | change = evaluateFormula(input) |
| 69 | + | |
| 70 | - | if change then |
| 70 | + | |
| 71 | - | balance = balance + change |
| 71 | + | |
| 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 |