Advertisement
yeeeeeeeeeeeee

player locator

Mar 27th, 2025
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. -- Wrap peripherals
  2. local monitor = peripheral.wrap("top")
  3. local silo = peripheral.wrap("left")
  4. local playerDetector = peripheral.wrap("right")
  5.  
  6. -- Setup the monitor
  7. monitor.clear()
  8. monitor.setTextScale(1)
  9. monitor.setTextColor(colors.white)
  10. monitor.setBackgroundColor(colors.black)
  11.  
  12. -- Monitor dimensions
  13. local width, height = monitor.getSize()
  14.  
  15. -- Table to store player names and their displayed positions
  16. local playerDisplay = {}
  17.  
  18. -- Helper function to update the monitor
  19. local function updateMonitor(players)
  20.     monitor.clear()
  21.     playerDisplay = {} -- Reset playerDisplay table
  22.     if #players > 0 then
  23.         monitor.setCursorPos(1, 1)
  24.         monitor.write("Players Nearby:")
  25.  
  26.         for i, player in ipairs(players) do
  27.             local x = 2
  28.             local y = i + 2
  29.             playerDisplay[i] = { name = player, posX = x, posY = y }
  30.             monitor.setCursorPos(x, y)
  31.             monitor.write(player)
  32.         end
  33.     else
  34.         monitor.setCursorPos(1, math.floor(height / 2))
  35.         monitor.write("No Players Detected")
  36.     end
  37. end
  38.  
  39. -- Helper function to display player coordinates on the monitor
  40. local function displayPlayerCoords(playerName)
  41.     local coords = playerDetector.getPlayerCoords(playerName)
  42.     monitor.clear()
  43.     if coords then
  44.         monitor.setCursorPos(1, 1)
  45.         monitor.write("Player: " .. playerName)
  46.         monitor.setCursorPos(1, 2)
  47.         monitor.write("Coordinates:")
  48.         monitor.setCursorPos(1, 3)
  49.         monitor.write("X: " .. coords.x)
  50.         monitor.setCursorPos(1, 4)
  51.         monitor.write("Y: " .. coords.y)
  52.         monitor.setCursorPos(1, 5)
  53.         monitor.write("Z: " .. coords.z)
  54.     else
  55.         monitor.setCursorPos(1, 1)
  56.         monitor.write("Coordinates unavailable.")
  57.     end
  58.     sleep(3) -- Display coordinates for 3 seconds
  59. end
  60.  
  61. -- Main loop
  62. while true do
  63.     -- Check player detector
  64.     local players = playerDetector.getPlayersInRange(1000000) -- "Infinite" range
  65.     updateMonitor(players)
  66.  
  67.     -- Wait for a monitor touch event
  68.     local event, side, x, y = os.pullEvent("monitor_touch")
  69.  
  70.     -- Check if a player name was clicked
  71.     for _, player in pairs(playerDisplay) do
  72.         if x >= player.posX and x <= player.posX + #player.name and y == player.posY then
  73.             displayPlayerCoords(player.name)
  74.             break
  75.         end
  76.     end
  77.  
  78.     -- Sleep to avoid overwhelming the server
  79.     sleep(1)
  80. end
  81.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement