Advertisement
yeeeeeeeeeeeee

eeeeeee

Mar 27th, 2025
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 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. if not hasGetPlayerCoords then
  21. print("Error: Player detector does not support coordinate retrieval!")
  22. end
  23.  
  24. -- Helper function to update the monitor
  25. local function updateMonitor(players)
  26. monitor.clear()
  27. playerDisplay = {} -- Reset playerDisplay table
  28.  
  29. if #players > 0 then
  30. monitor.setCursorPos(1, 1)
  31. monitor.setTextColor(colors.cyan)
  32. monitor.write("Players Nearby:")
  33.  
  34. for i, player in ipairs(players) do
  35. local x = 2
  36. local y = i + 2
  37. playerDisplay[i] = { name = player, posX = x, posY = y }
  38. monitor.setCursorPos(x, y)
  39. if player == selectedPlayer then
  40. monitor.setTextColor(colors.green) -- Highlight selected player
  41. else
  42. monitor.setTextColor(colors.white)
  43. end
  44. monitor.write(player)
  45. end
  46. else
  47. monitor.setCursorPos(1, math.floor(height / 2))
  48. monitor.setTextColor(colors.red)
  49. monitor.write("No Players Detected")
  50. end
  51. end
  52.  
  53. -- Helper function to display player coordinates
  54. local function displayPlayerCoords(playerName)
  55. if not hasGetPlayerCoords then
  56. monitor.setCursorPos(1, height - 4)
  57. monitor.setTextColor(colors.red)
  58. monitor.write("Coordinates unavailable.")
  59. return
  60. end
  61.  
  62. local coords = playerDetector.getPlayerPos(playerName)
  63. if not coords then
  64. monitor.setCursorPos(1, height - 4)
  65. monitor.setTextColor(colors.red)
  66. monitor.write("Coordinates unavailable.")
  67. return
  68. end
  69.  
  70. -- Clear only the coordinate section
  71. monitor.setBackgroundColor(colors.black)
  72. for i = height - 5, height - 2 do
  73. monitor.setCursorPos(1, i)
  74. monitor.write(string.rep(" ", width))
  75. end
  76.  
  77. monitor.setCursorPos(1, height - 5)
  78. monitor.setTextColor(colors.yellow)
  79. monitor.write("Player: " .. playerName)
  80. monitor.setCursorPos(1, height - 4)
  81. monitor.write("X: " .. coords.x)
  82. monitor.setCursorPos(1, height - 3)
  83. monitor.write("Y: " .. coords.y)
  84. monitor.setCursorPos(1, height - 2)
  85. monitor.write("Z: " .. coords.z)
  86. end
  87.  
  88. -- Main loop
  89. while true do
  90. -- Check player detector
  91. local players = playerDetector.getPlayersInRange(1000000000000) -- "Infinite" range
  92. updateMonitor(players)
  93.  
  94. -- Wait for a monitor touch event
  95. local event, side, x, y = os.pullEvent("monitor_touch")
  96.  
  97. -- Check if a player name was clicked
  98. for _, player in pairs(playerDisplay) do
  99. if x >= player.posX and x <= player.posX + #player.name and y == player.posY then
  100. selectedPlayer = player.name -- Update selected player
  101. displayPlayerCoords(selectedPlayer)
  102. break
  103. end
  104. end
  105. end
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement