Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Wrap peripherals
- local monitor = peripheral.wrap("top")
- local silo = peripheral.wrap("left")
- local playerDetector = peripheral.wrap("right")
- -- Setup the monitor
- monitor.clear()
- monitor.setTextScale(1)
- monitor.setTextColor(colors.white)
- monitor.setBackgroundColor(colors.black)
- -- Monitor dimensions
- local width, height = monitor.getSize()
- -- Table to store player names and their displayed positions
- local playerDisplay = {}
- local selectedPlayer = nil -- Store the selected player's name
- -- Helper function to update the monitor
- local function updateMonitor(players)
- monitor.clear()
- playerDisplay = {} -- Reset playerDisplay table
- if #players > 0 then
- monitor.setCursorPos(1, 1)
- monitor.setTextColor(colors.cyan)
- monitor.write("Players Nearby:")
- for i, player in ipairs(players) do
- local x = 2
- local y = i + 2
- playerDisplay[i] = { name = player, posX = x, posY = y }
- monitor.setCursorPos(x, y)
- if player == selectedPlayer then
- monitor.setTextColor(colors.green) -- Highlight selected player
- else
- monitor.setTextColor(colors.white)
- end
- monitor.write(player)
- end
- else
- monitor.setCursorPos(1, math.floor(height / 2))
- monitor.setTextColor(colors.red)
- monitor.write("No Players Detected")
- end
- end
- -- Helper function to display player coordinates
- local function displayPlayerCoords()
- while selectedPlayer do
- local coords = playerDetector.getPlayerCoords(selectedPlayer)
- -- Clear only the coordinate section
- monitor.setBackgroundColor(colors.black)
- for i = height - 5, height - 2 do
- monitor.setCursorPos(1, i)
- monitor.write(string.rep(" ", width))
- end
- monitor.setCursorPos(1, height - 5)
- monitor.setTextColor(colors.yellow)
- monitor.write("Player: " .. selectedPlayer)
- if coords then
- monitor.setCursorPos(1, height - 4)
- monitor.write("X: " .. coords.x)
- monitor.setCursorPos(1, height - 3)
- monitor.write("Y: " .. coords.y)
- monitor.setCursorPos(1, height - 2)
- monitor.write("Z: " .. coords.z)
- else
- monitor.setCursorPos(1, height - 4)
- monitor.setTextColor(colors.red)
- monitor.write("Coordinates unavailable.")
- end
- sleep(1) -- Update every second
- end
- end
- -- Main loop
- while true do
- -- Check player detector
- local players = playerDetector.getPlayersInRange(1000000) -- "Infinite" range
- updateMonitor(players)
- -- Wait for a monitor touch event
- local event, side, x, y = os.pullEvent("monitor_touch")
- -- Check if a player name was clicked
- for _, player in pairs(playerDisplay) do
- if x >= player.posX and x <= player.posX + #player.name and y == player.posY then
- selectedPlayer = player.name
- parallel.waitForAny(displayPlayerCoords)
- break
- end
- end
- -- Sleep to avoid overwhelming the server
- sleep(1)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement