yeeeeeeeeeeeee

test 100

Mar 27th, 2025
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.76 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.     if not playerDetector.getPlayerCoords then
  42.         monitor.clear()
  43.         monitor.setCursorPos(1, 1)
  44.         monitor.write("Player: " .. playerName)
  45.         monitor.setCursorPos(1, 2)
  46.         monitor.write("Coordinates unavailable (unsupported).")
  47.         sleep(3) -- Display the message for 3 seconds
  48.         return
  49.     end
  50.  
  51.     local coords = playerDetector.getPlayerCoords(playerName)
  52.     monitor.clear()
  53.     if coords then
  54.         monitor.setCursorPos(1, 1)
  55.         monitor.write("Player: " .. playerName)
  56.         monitor.setCursorPos(1, 2)
  57.         monitor.write("Coordinates:")
  58.         monitor.setCursorPos(1, 3)
  59.         monitor.write("X: " .. coords.x)
  60.         monitor.setCursorPos(1, 4)
  61.         monitor.write("Y: " .. coords.y)
  62.         monitor.setCursorPos(1, 5)
  63.         monitor.write("Z: " .. coords.z)
  64.     else
  65.         monitor.setCursorPos(1, 1)
  66.         monitor.write("Coordinates unavailable.")
  67.     end
  68.     sleep(3) -- Display coordinates for 3 seconds
  69. end
  70.  
  71. -- Main loop
  72. while true do
  73.     -- Check player detector
  74.     local players = playerDetector.getPlayersInRange(1000000) -- "Infinite" range
  75.     updateMonitor(players)
  76.  
  77.     -- Wait for a monitor touch event
  78.     local event, side, x, y = os.pullEvent("monitor_touch")
  79.  
  80.     -- Check if a player name was clicked
  81.     for _, player in pairs(playerDisplay) do
  82.         if x >= player.posX and x <= player.posX + #player.name and y == player.posY then
  83.             displayPlayerCoords(player.name)
  84.             break
  85.         end
  86.     end
  87.  
  88.     -- Sleep to avoid overwhelming the server
  89.     sleep(1)
  90. end
  91.  
Advertisement
Add Comment
Please, Sign In to add comment