Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pd = peripheral.wrap("right")
- local mon = peripheral.wrap("top")
- mon.setTextScale(0.5)
- -- Define a range for checking if players are in range (in blocks)
- local detectionRange = 50
- while true do
- mon.clear()
- -- Set a header for the display
- mon.setCursorPos(1, 1)
- mon.write("=== Player Tracker ===")
- -- Get online players
- local players = pd.getOnlinePlayers()
- local row = 3 -- Start displaying players from row 3 to leave space for the header
- for k, v in pairs(players) do
- -- Get player position and other details
- local playerPos = pd.getPlayerPos(v)
- -- Check if the player is within the specified range
- local inRange = pd.isPlayerInRange(v, detectionRange)
- -- Get additional player info (like health, if available)
- local playerData = pd.getPlayer(v) -- This method provides more player info
- -- Write player name
- mon.setCursorPos(1, row)
- mon.write("Player: " .. v)
- -- Write position
- mon.setCursorPos(1, row + 1)
- mon.write("Pos: x=" .. math.floor(playerPos.x) .. " y=" .. math.floor(playerPos.y) .. " z=" .. math.floor(playerPos.z))
- -- Write health (if available in getPlayer data)
- mon.setCursorPos(1, row + 2)
- if playerData and playerData.health then
- mon.write("Health: " .. playerData.health .. "/" .. (playerData.maxHealth or "20"))
- else
- mon.write("Health: N/A")
- end
- -- Write if the player is in range
- mon.setCursorPos(1, row + 3)
- mon.write("In Range (" .. detectionRange .. " blocks): " .. (inRange and "Yes" or "No"))
- -- Add a separator
- mon.setCursorPos(1, row + 4)
- mon.write("-------------------")
- row = row + 6 -- Move to the next block of text (leaving a gap)
- end
- -- If no players are online, display a message
- if #players == 0 then
- mon.setCursorPos(1, 3)
- mon.write("No players online.")
- end
- sleep(20) -- Refresh every 20 seconds
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement