Skiret

radar

Nov 29th, 2020
495
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local distance = 50
  2. local period=5
  3. local whitelistFilename = "radar_whitelist"
  4. local addr = ""--cURL сюда
  5.  
  6. local component = require("component")
  7. local internet = require("internet")
  8. local event = require("event")
  9.  
  10. local function readWhitelist(filename)
  11.   local file = io.open(filename, "r")
  12.   local arr = {}
  13.   for line in file:lines() do
  14.     arr[line]=true
  15.   end
  16.   return arr
  17. end
  18.  
  19. local function checkWhitelist(entities, whitelist)
  20.   local notInWhitelist = {}
  21.   for k in pairs(entities) do
  22.     if not whitelist[entities[k].name] then
  23.       table.insert(notInWhitelist, entities[k])
  24.     end
  25.   end
  26.   return notInWhitelist
  27. end
  28.  
  29. local function convert(entities)
  30.   local list = {}
  31.   for k in pairs(entities) do
  32.     local entity = entities[k]
  33.     list[#list+1] = string.format("%s %.0f", entity.name, entity.distance)
  34.   end
  35.   return table.concat(list, "\n")
  36. end
  37.  
  38. local function printWhitelist(whitelist)
  39.   local list = {}
  40.   for k in pairs(whitelist) do
  41.     list[#list+1] = k
  42.     print(k)
  43.   end
  44.   print("Whitelist:", table.concat(list, ", "))
  45. end
  46.  
  47. local whitelist = readWhitelist(whitelistFilename)
  48. printWhitelist(whitelist)
  49. component.redstone.setWakeThreshold(15)
  50.  
  51. repeat
  52.   local players = component.radar.getPlayers(distance)
  53.   --local players = component.radar.getEntities(distance)
  54.   local notInWL = checkWhitelist(players, whitelist)
  55.  
  56.   print(#notInWL)
  57.  
  58.   if #notInWL > 0 then
  59.     local playersString = convert(notInWL)
  60.     local req = internet.request(addr, {data=playersString})
  61.   end
  62.   os.sleep(period)
  63. until event.pull(1) == "interrupted"
RAW Paste Data