Advertisement
LokeYourLord

Player Sensor Alarm

Feb 22nd, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. sensor = peripheral.wrap("top")
  2. monitor = peripheral.wrap("right")
  3.  
  4. local w,h = monitor.getSize()
  5. --rs.setBundledOutput("left",colors.white)
  6. --rs.setOutput("left",false)
  7.  
  8. function usersCheck(name)
  9.  
  10. --users
  11. local users = {["USERNAME"] = true,
  12. --If you want more usernames to allow, copy the line below and paste it right under it
  13. ["USERNAME"] = true,
  14. ["USERNAME"] = true}
  15.  
  16. length = table.getn(users)
  17.  
  18. for i=1,length do
  19.  
  20. if name ~= users[i] then
  21. return 1
  22. end
  23.  
  24. if name == users[i] then
  25. return 2
  26. end
  27.  
  28. end
  29. end
  30.  
  31. while true do
  32. monitor.clear()
  33. i = 2
  34. ww = w/2 - 7
  35. monitor.setCursorPos(ww,1)
  36. monitor.write("Near your base:")
  37. rs.setOutput("left",false)
  38. targets = sensor.getPlayerNames()
  39.  
  40. for k, v in pairs(targets) do
  41. name = targets[k]
  42. tarLeng = table.getn(targets)
  43.  
  44. sL = string.len(name)
  45. ww = w/2 - sL/2 + 1
  46. monitor.setCursorPos(ww,i)
  47. monitor.clearLine(i)
  48. if usersCheck(name) == 2 then
  49. monitor.setTextColor(8192)
  50. elseif usersCheck(name) == 1 then
  51. monitor.setTextColor(colors.red)
  52. end
  53. monitor.write(name)
  54. monitor.setTextColor(1)
  55. i = i + 1
  56.  
  57. if usersCheck(name) == 1 then
  58. --rs.setBundledOutput("left",colors.white)
  59. print("Warning: Unathorized player in range!")
  60. rs.setOutput("left",true)
  61. end
  62.  
  63. end
  64. sleep(2)
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement