yeeeeeeeeeeeee

sus

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