jonassvensson4

Sensor2

Sep 23rd, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 =
  9. {
  10.     ["Wazyr"] = false,
  11.     ["jonassvensson4"] = false,
  12.     ["Fragwad"] = false,
  13.     ["Pure_Salt"] = false,
  14.     ["Powerfarmer"] = false,
  15.     ["Naxix"] = false,
  16.     ["AndersWithTheCat"] = false,
  17.     ["CannaJR"] = false,
  18.     ["Blazing_sword27"] = false,
  19.     ["Kenny608uk"] = false,
  20.     ["Sorms"] = false,
  21.     ["jjceel"] = false,
  22.     ["Understalker"] = false,
  23.     ["Pangolin"] = false,
  24.     ["Sunconure11"] = false,
  25.     ["Isoceth"] = false,
  26.     ["CatManTad"] = false,
  27.     ["it_is_me"] = false,
  28.     ["BossSnake"] = false,
  29.     ["DarkKnight53642"] = false,
  30.     ["pyro1212"] = false,
  31.     ["UsamiUsagi"] = false,
  32.     ["Rihawk"] = false,
  33.     ["bonkeywonkey"] = false,
  34.     ["shaquiqui"] = false,
  35.     ["antnuts"] = false,
  36.     ["Coffe_x"] = false,
  37.     ["thygamerr"] = false,
  38.     ["TheRealElonMusk"] = false
  39. }
  40.  
  41. -- Get users outside the shop
  42. function getUserOut()
  43.   playersb = bsensor.getPlayers()
  44.   if playersb[1] == nil then
  45.        -- No one is outside
  46.   else
  47.     usernameOut = playersb[1].name
  48.     for name, status in pairs(pIn) do
  49.       if pIn[usernameOut] == true then
  50.         monitor.setTextColor(colors.red)
  51.         monitor.setCursorPos(1,1)
  52.         monitor.write("Please come again!")
  53.         monitor.setTextColor(colors.white)
  54.         monitor.setCursorPos(1,2)
  55.         monitor.write("  " .. usernameOut)
  56.         sleep(1)
  57.         monitor.clear()
  58.         pIn[usernameOut] = false
  59.       end
  60.     end
  61.   end
  62. end
  63.  
  64. -- Get user who enters the shop
  65. function getUser()
  66.   players = sensor.getPlayers()
  67.   -- Checks if there's a player inside the shop
  68.   if players[1] == nil then
  69.     username = "null"
  70.   else
  71.   -- Player found
  72.     username = players[1].name
  73.     for name, status in pairs(pIn) do
  74.       if pIn[username] == true then
  75.         -- Player has already been in the shop
  76.         playersb = bsensor.getPlayers()
  77.         if playersb[1] == nil then
  78.             -- No one is outside
  79.         else
  80.             usernameOut = playersb[1].name
  81.             if pIn[usernameOut] == true then
  82.                 pIn[usernameOut] = false
  83.                 break
  84.             end
  85.         end
  86.       elseif pIn[username] == false then
  87.         pIn[username] = true
  88.  
  89.         -- Welcome message:
  90.         monitor.setTextColor(colors.green)
  91.         monitor.setCursorPos(1,1)
  92.         monitor.write("     Welcome!")
  93.         monitor.setCursorPos(1,2)
  94.         monitor.setTextColor(colors.white)
  95.         monitor.write("  " .. username)
  96.         sleep(2)
  97.         monitor.clear()
  98.       end
  99.     end
  100.   end
  101. end
  102.  
  103. while true do
  104.   monitor.setCursorPos(1,1)
  105.   getUser()
  106.   sleep(0.75)
  107. end
Add Comment
Please, Sign In to add comment