GNOOR1S

Computertronics Radar Closest Finder

Jun 23rd, 2022 (edited)
494
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.64 KB | None | 0 0
  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
Add Comment
Please, Sign In to add comment