Advertisement
Ubidibity

playersdetected.lua

Jun 5th, 2025 (edited)
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.05 KB | Gaming | 0 0
  1. local pd = peripheral.wrap("right")
  2. local mon = peripheral.wrap("top")
  3.  
  4. mon.setTextScale(0.5)
  5.  
  6. -- Define a range for checking if players are in range (in blocks)
  7. local detectionRange = 50
  8.  
  9. while true do
  10.     mon.clear()
  11.     -- Set a header for the display
  12.     mon.setCursorPos(1, 1)
  13.     mon.write("=== Player Tracker ===")
  14.  
  15.     -- Get online players
  16.     local players = pd.getOnlinePlayers()
  17.     local row = 3 -- Start displaying players from row 3 to leave space for the header
  18.  
  19.     for k, v in pairs(players) do
  20.         -- Get player position and other details
  21.         local playerPos = pd.getPlayerPos(v)
  22.         -- Check if the player is within the specified range
  23.         local inRange = pd.isPlayerInRange(v, detectionRange)
  24.         -- Get additional player info (like health, if available)
  25.         local playerData = pd.getPlayer(v) -- This method provides more player info
  26.  
  27.         -- Write player name
  28.         mon.setCursorPos(1, row)
  29.         mon.write("Player: " .. v)
  30.  
  31.         -- Write position
  32.         mon.setCursorPos(1, row + 1)
  33.         mon.write("Pos: x=" .. math.floor(playerPos.x) .. " y=" .. math.floor(playerPos.y) .. " z=" .. math.floor(playerPos.z))
  34.  
  35.         -- Write health (if available in getPlayer data)
  36.         mon.setCursorPos(1, row + 2)
  37.         if playerData and playerData.health then
  38.             mon.write("Health: " .. playerData.health .. "/" .. (playerData.maxHealth or "20"))
  39.         else
  40.             mon.write("Health: N/A")
  41.         end
  42.  
  43.         -- Write if the player is in range
  44.         mon.setCursorPos(1, row + 3)
  45.         mon.write("In Range (" .. detectionRange .. " blocks): " .. (inRange and "Yes" or "No"))
  46.  
  47.         -- Add a separator
  48.         mon.setCursorPos(1, row + 4)
  49.         mon.write("-------------------")
  50.  
  51.         row = row + 6 -- Move to the next block of text (leaving a gap)
  52.     end
  53.  
  54.     -- If no players are online, display a message
  55.     if #players == 0 then
  56.         mon.setCursorPos(1, 3)
  57.         mon.write("No players online.")
  58.     end
  59.  
  60.     sleep(20) -- Refresh every 20 seconds
  61. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement