SHOW:
|
|
- or go back to the newest paste.
| 1 | - | local sensor = peripheral.wrap("top")
|
| 1 | + | local sensor = peripheral.wrap("openperipheral_sensor_0")
|
| 2 | - | local bsensor = peripheral.wrap("openperipheral_sensor_1")
|
| 2 | + | local bsensor = peripheral.wrap("openperipheral_sensor_0")
|
| 3 | - | local monitor = peripheral.wrap("monitor_3")
|
| 3 | + | local monitor = peripheral.wrap("monitor_4")
|
| 4 | ||
| 5 | monitor.clear() | |
| 6 | monitor.setCursorPos(1,1) | |
| 7 | ||
| 8 | local pIn = | |
| 9 | {
| |
| 10 | ["jonassvensson4"] = false | |
| 11 | } | |
| 12 | ||
| 13 | -- Get users outside the shop | |
| 14 | function getUserOut() | |
| 15 | playersb = bsensor.getPlayers() | |
| 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.write("Please come again!")
| |
| 25 | monitor.setTextColor(colors.white) | |
| 26 | monitor.setCursorPos(1,2) | |
| 27 | monitor.write(" " .. usernameOut)
| |
| 28 | sleep(1) | |
| 29 | monitor.clear() | |
| 30 | pIn[usernameOut] = false | |
| 31 | end | |
| 32 | end | |
| 33 | end | |
| 34 | end | |
| 35 | ||
| 36 | -- Get user who enters the shop | |
| 37 | function getUser() | |
| 38 | players = sensor.getPlayers() | |
| 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 playersb[1] == nil then | |
| 50 | -- No one is outside | |
| 51 | else | |
| 52 | usernameOut = playersb[1].name | |
| 53 | if pIn[usernameOut] == true then | |
| 54 | pIn[usernameOut] = false | |
| 55 | break | |
| 56 | end | |
| 57 | end | |
| 58 | elseif pIn[username] == false then | |
| 59 | pIn[username] = true | |
| 60 | ||
| 61 | -- Welcome message: | |
| 62 | monitor.setTextColor(colors.green) | |
| 63 | monitor.setCursorPos(1,1) | |
| 64 | monitor.write(" Welcome!")
| |
| 65 | monitor.setCursorPos(1,2) | |
| 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 | while true do | |
| 76 | monitor.setCursorPos(1,1) | |
| 77 | getUser() | |
| 78 | sleep(0.75) | |
| 79 | end |