Advertisement
yeeeeeeeeeeeee

peter

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