SHOW:
|
|
- or go back to the newest paste.
| 1 | local sensor = peripheral.wrap("top")
| |
| 2 | local bsensor = peripheral.wrap("openperipheral_sensor_1")
| |
| 3 | local monitor = peripheral.wrap("monitor_3")
| |
| 4 | ||
| 5 | monitor.clear() | |
| 6 | monitor.setCursorPos(1,1) | |
| 7 | ||
| 8 | - | local pIn = {}
|
| 8 | + | local pIn = |
| 9 | {
| |
| 10 | - | function welcome() |
| 10 | + | ["jonassvensson4"] = false |
| 11 | - | monitor.write("Welcome!")
|
| 11 | + | } |
| 12 | - | monitor.setCursorPos(1,2) |
| 12 | + | |
| 13 | - | monitor.write(username) |
| 13 | + | -- Get users outside the shop |
| 14 | - | sleep(2) |
| 14 | + | |
| 15 | - | monitor.clear() |
| 15 | + | |
| 16 | if playersb[1] == nil then | |
| 17 | -- No one is outside | |
| 18 | else | |
| 19 | usernameOut = playersb[1].name | |
| 20 | for name, status in pairs(pIn) do | |
| 21 | if pIn[usernameOut] == true then | |
| 22 | monitor.setTextColor(colors.red) | |
| 23 | monitor.setCursorPos(1,1) | |
| 24 | - | monitor.setCursorPos(1,1) |
| 24 | + | monitor.write("Please come again!")
|
| 25 | - | |
| 25 | + | monitor.setTextColor(colors.white) |
| 26 | - | for x, y in pairs(pIn) do |
| 26 | + | |
| 27 | - | if x == usernameOut then |
| 27 | + | monitor.write(" " .. usernameOut)
|
| 28 | - | monitor.write("Goodbye")
|
| 28 | + | |
| 29 | monitor.clear() | |
| 30 | - | monitor.write(usernameOut) |
| 30 | + | pIn[usernameOut] = false |
| 31 | end | |
| 32 | end | |
| 33 | - | remove = "true" |
| 33 | + | |
| 34 | end | |
| 35 | ||
| 36 | - | if remove == "true" then |
| 36 | + | -- Get user who enters the shop |
| 37 | - | pIn[usernameOut] = nil |
| 37 | + | |
| 38 | - | remove = "false" |
| 38 | + | |
| 39 | -- Checks if there's a player inside the shop | |
| 40 | if players[1] == nil then | |
| 41 | username = "null" | |
| 42 | else | |
| 43 | -- Player found | |
| 44 | username = players[1].name | |
| 45 | for name, status in pairs(pIn) do | |
| 46 | if pIn[username] == true then | |
| 47 | -- Player has already been in the shop | |
| 48 | playersb = bsensor.getPlayers() | |
| 49 | - | if next(pIn) == nil then |
| 49 | + | if playersb[1] == nil then |
| 50 | - | -- table null |
| 50 | + | -- No one is outside |
| 51 | - | welcome() |
| 51 | + | else |
| 52 | - | pIn[username] = "1" |
| 52 | + | usernameOut = playersb[1].name |
| 53 | - | else |
| 53 | + | if pIn[usernameOut] == true then |
| 54 | - | for n, a in pairs(pIn) do |
| 54 | + | pIn[usernameOut] = false |
| 55 | - | if n == username then |
| 55 | + | break |
| 56 | - | local n = username |
| 56 | + | end |
| 57 | - | -- Player has already been in the shop |
| 57 | + | end |
| 58 | - | remove0 = "true" |
| 58 | + | elseif pIn[username] == false then |
| 59 | - | else |
| 59 | + | pIn[username] = true |
| 60 | - | welcome() |
| 60 | + | |
| 61 | - | pIn[username] = "1" |
| 61 | + | -- Welcome message: |
| 62 | - | end |
| 62 | + | monitor.setTextColor(colors.green) |
| 63 | monitor.setCursorPos(1,1) | |
| 64 | - | if remove0 == "true" then |
| 64 | + | monitor.write(" Welcome!")
|
| 65 | - | getUserOut() |
| 65 | + | monitor.setCursorPos(1,2) |
| 66 | - | remove0 = "false" |
| 66 | + | monitor.setTextColor(colors.white) |
| 67 | monitor.write(" " .. username)
| |
| 68 | sleep(2) | |
| 69 | monitor.clear() | |
| 70 | end | |
| 71 | end | |
| 72 | end | |
| 73 | end | |
| 74 | ||
| 75 | - | getUserOut() |
| 75 | + | |
| 76 | monitor.setCursorPos(1,1) | |
| 77 | getUser() | |
| 78 | sleep(0.75) | |
| 79 | end |