Advertisement
yeeeeeeeeeeeee

eeee

Mar 27th, 2025
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. -- Wrap peripherals
  2. local monitor = peripheral.wrap("top")
  3. local playerDetector = peripheral.wrap("right")
  4.  
  5. -- Setup the monitor
  6. monitor.clear()
  7. monitor.setTextScale(1)
  8. monitor.setTextColor(colors.white)
  9. monitor.setBackgroundColor(colors.black)
  10.  
  11. -- Monitor dimensions
  12. local width, height = monitor.getSize()
  13.  
  14. -- Table to store player names and their displayed positions
  15. local playerDisplay = {}
  16. local selectedPlayer = nil -- Store the selected player's name
  17.  
  18. -- Check if the player detector supports coordinate retrieval
  19. local hasGetPlayerCoords = playerDetector and playerDetector.getPlayerPos ~= nil
  20.  
  21. -- Helper function to update the monitor
  22. local function updateMonitor(players)
  23. monitor.clear()
  24. playerDisplay = {} -- Reset playerDisplay table
  25.  
  26. if #players > 0 then
  27. monitor.setCursorPos(1, 1)
  28. monitor.setTextColor(colors.cyan)
  29. monitor.write("Players Nearby:")
  30.  
  31. for i, player in ipairs(players) do
  32. local x = 2
  33. local y = i + 2
  34. playerDisplay[i] = { name = player, posX = x, posY = y }
  35. monitor.setCursorPos(x, y)
  36. if player == selectedPlayer then
  37. monitor.setTextColor(colors.green) -- Highlight selected player
  38. else
  39. monitor.setTextColor(colors.white)
  40. end
  41. monitor.write(player)
  42. end
  43. else
  44. monitor.setCursorPos(1, math.floor(height / 2))
  45. monitor.setTextColor(colors.red)
  46. monitor.write("No Players Detected")
  47. end
  48. end
  49.  
  50. -- Helper function to display player coordinates
  51. local function displayPlayerCoords(playerName)
  52. local coords = hasGetPlayerCoords and playerDetector.getPlayerPos(playerName) or nil
  53.  
  54. -- Clear only the coordinate section
  55. monitor.setBackgroundColor(colors.black)
  56. for i = height - 5, height - 2 do
  57. monitor.setCursorPos(1, i)
  58. monitor.write(string.rep(" ", width))
  59. end
  60.  
  61. monitor.setCursorPos(1, height - 5)
  62. monitor.setTextColor(colors.yellow)
  63. monitor.write("Player: " .. playerName)
  64. if coords then
  65. monitor.setCursorPos(1, height - 4)
  66. monitor.write("X: " .. coords.x)
  67. monitor.setCursorPos(1, height - 3)
  68. monitor.write("Y: " .. coords.y)
  69. monitor.setCursorPos(1, height - 2)
  70. monitor.write("Z: " .. coords.z)
  71. else
  72. monitor.setCursorPos(1, height - 4)
  73. monitor.setTextColor(colors.red)
  74. monitor.write("Coordinates unavailable.")
  75. end
  76. end
  77.  
  78. -- Main loop
  79. while true do
  80. -- Check player detector
  81. local players = playerDetector.getPlayersInRange(1000000000000) -- "Infinite" range
  82. updateMonitor(players)
  83.  
  84. -- Wait for a monitor touch event
  85. local event, side, x, y = os.pullEvent("monitor_touch")
  86.  
  87. -- Check if a player name was clicked
  88. for _, player in pairs(playerDisplay) do
  89. if x >= player.posX and x <= player.posX + #player.name and y == player.posY then
  90. selectedPlayer = player.name -- Update selected player
  91. displayPlayerCoords(selectedPlayer)
  92. break
  93. end
  94. end
  95. end
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement