Advertisement
mc1030

sense

Nov 21st, 2020 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.75 KB | None | 0 0
  1. STD_MONITOR_SIDE = "top"
  2.  
  3. PLAYER_WHITELIST = {
  4.     mc1030 = true,
  5.     ime990 = true,
  6.     Ajfree = true,
  7.     shirograhm = true,
  8.     RadicalRagu = true
  9. }
  10.  
  11. local moni = peripheral.wrap(STD_MONITOR_SIDE)
  12.  
  13.  
  14. local sensor = peripheral.wrap("right")
  15. local entities = {}
  16. local entity_size = 0
  17. local new_entities = {}
  18. local new_entity_size = 0
  19.  
  20.  
  21. function welcome(name)
  22.     moni.setTextColor(colors.white)
  23.     print("Welcome "..name)
  24.     monitor_write("Welcome "..name)
  25. end
  26.  
  27. function farewell(name)
  28.     moni.setTextColor(colors.lightBlue)
  29.     print("\tGodspeed "..name)
  30.     monitor_write("\tGodspeed "..name)
  31. end
  32.  
  33. function monitor_reset()
  34.     moni.clear()
  35.     moni.setCursorPos(1, 1)
  36.     moni.setTextColor(colors.white)
  37.     moni.setTextScale(0.5)
  38. end
  39.  
  40. function monitor_write(message)
  41.     moni.write(message)
  42.     local x,y = moni.getCursorPos()
  43.     if y > 8 then
  44.         y = 0
  45.     end
  46.     moni.setCursorPos(1, y + 1)
  47. end
  48.  
  49. monitor_reset()
  50.  
  51. while true do
  52.     new_entities = {}
  53.     for _, entity in pairs(sensor.sense()) do
  54.         if PLAYER_WHITELIST[entity.name] ~= nil then
  55.  
  56.             if entity_size == 0 then
  57.                 welcome(entity.name)
  58.             elseif entities ~= nil and entities[entity.name] == nil then
  59.                 new_entities[entity.name] = true
  60.                 welcome(entity.name)
  61.             end
  62.             new_entities[entity.name] = true
  63.             new_entity_size = new_entity_size + 1
  64.         end
  65.     end
  66.  
  67.     for name, bool in pairs(entities) do
  68.         if PLAYER_WHITELIST[name] ~= nil then
  69.             if new_entities[name] == nil then
  70.                 farewell(name)
  71.             end    
  72.         end  
  73.     end
  74.     entities = new_entities
  75.     entity_size = new_entity_size
  76.     os.sleep(1.5)
  77. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement