GNOOR1S

Computertronics Radar Closest Finder

Jun 23rd, 2022 (edited)
378
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- Created by Gunnar Jessee 6/23/22
  2. -- Used for computertronics for computercraft
  3.  
  4. local radar = peripheral.find("radar")
  5. local debug = false
  6.  
  7. function findClosest()
  8.     local players = {radar.getPlayers()}
  9.     if debug then
  10.         print(tostring(players))
  11.     end
  12.     local shortest = 1000000
  13.     local name = ""
  14.     for i = 1, #players[1] do
  15.         dist = players[1][i].distance
  16.         if dist < shortest then
  17.             shortest = dist
  18.         end
  19.     end
  20.    
  21.     for i = 1, #players[1] do
  22.         if players[1][i].distance == dist then
  23.             name = players[1][i].name
  24.         end
  25.     end
  26.    
  27.     return name
  28. end
RAW Paste Data Copied