Advertisement
DaikiKaminari

PlayerSensor

Mar 24th, 2020
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.34 KB | None | 0 0
  1. local arg = ...
  2.  
  3. local function getPeripheral()
  4.     print("Searching sensor...")
  5.     local sides = {"top", "bottom", "right", "left", "back", "front"}
  6.     local sensor = peripheral.wrap("top")
  7.     local i = 1
  8.     while sensor == nil do
  9.         sensor = peripheral.wrap(tostring(sides[i]))
  10.         i = i + 1
  11.         if i % 7 == 0 then
  12.             i = 1
  13.         end
  14.         sleep(0)
  15.     end
  16.     print("Sensor found !")
  17.     return sensor
  18. end
  19.  
  20. local function displayAllAttributes(tab)
  21.     for k,v in ipairs(tab) do
  22.         print(k)
  23.         print(type(v))
  24.         if type(v) == "table" then
  25.             displayAllAttributes(v)
  26.         else
  27.             print(v)
  28.         end
  29.     end
  30. end
  31.  
  32. local function getNames(sensor)
  33.     players = {}
  34.     i = 1
  35.     for _,v in ipairs(sensor.getPlayers()) do
  36.         players[i] = v.name
  37.         i = i + 1
  38.     end
  39.     return players
  40. end
  41.  
  42. local function displayPlayersInRange(sensor, times)
  43.     local i = 0
  44.     while i ~= times do
  45.         term.clear()
  46.         for _,players in ipairs(getNames(sensor)) do
  47.             print(players)
  48.         end
  49.         i = i + 1
  50.         sleep(1)
  51.     end
  52. end
  53.  
  54. local function main()
  55.     local sensor = getPeripheral()
  56.     if arg == nil then
  57.         displayPlayersInRange(sensor, -1)
  58.     else
  59.         displayPlayersInRange(sensor, arg)
  60.     end
  61. end
  62.  
  63. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement