Advertisement
Ubidibity

playersdetected-debug.lua

Jul 8th, 2025 (edited)
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.33 KB | Gaming | 0 0
  1. local pd = peripheral.wrap("bottom")
  2. local mon = peripheral.wrap("top")
  3. -- local speaker = peripheral.wrap("left")
  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. -- Klaxon Warning Sound Script for CC: Tweaked Speaker
  10. -- Place a speaker peripheral next to the computer and apply a redstone signal to start/stop
  11.  
  12. local speaker = peripheral.find("speaker") -- Find the speaker peripheral
  13. if not speaker then
  14.     error("No speaker peripheral found. Please attach a speaker.")
  15. end
  16.  
  17. local function playKlaxon()
  18. --    while true do
  19.         -- Check if redstone signal is active (e.g., from the "back" side)
  20.   --      if redstone.getInput("back") then
  21.             -- Play high pitch (note block "harp" sound, pitch 24)
  22.             speaker.playNote("harp", 3, 24)
  23.             sleep(0.3) -- Short delay for first tone
  24.             -- Play low pitch (note block "harp" sound, pitch 12)
  25.             speaker.playNote("harp", 3, 12)
  26.             sleep(0.3) -- Short delay for second tone
  27.     --    else
  28.             -- Stop if no redstone signal
  29.  --           break
  30.      --   end
  31.    -- end
  32. end
  33.  
  34. -- Main loop to monitor redstone signal
  35. while true do
  36.     -- Wait for a redstone event
  37.     os.pullEvent("redstone")
  38.     -- Start klaxon if redstone is active
  39.     if redstone.getInput("back") then
  40.         playKlaxon()
  41.     end
  42. end
  43. while true do
  44.     mon.clear()
  45.     -- Set a header for the display
  46.     mon.setCursorPos(1, 1)
  47.     mon.write("=== Player Tracker ===")
  48.  
  49.     -- Get online players
  50.     local players = pd.getOnlinePlayers()
  51.     local row = 3 -- Start displaying players from row 3 to leave space for the header
  52.  
  53.     for k, v in pairs(players) do
  54.         -- Get player position and other details
  55.         local playerPos = pd.getPlayerPos(v)
  56.         -- Check if the player is within the specified range
  57.         local inRange = pd.isPlayerInRange(detectionRange, v) -- Fixed parameter order
  58.         -- Get additional player info (like health, if available)
  59.         local playerData = pd.getPlayer(v) -- This method provides more player info
  60.  
  61.         -- Write player name
  62.         mon.setCursorPos(1, row)
  63.         mon.write("Player: " .. v)
  64.  
  65.         -- Write position
  66.         mon.setCursorPos(1, row + 1)
  67.         mon.write("Pos: x=" .. math.floor(playerPos.x) .. " y=" .. math.floor(playerPos.y) .. " z=" .. math.floor(playerPos.z))
  68.  
  69.         -- Write health (if available in getPlayer data)
  70.         mon.setCursorPos(1, row + 2)
  71.         if playerData and playerData.health then
  72.             mon.write("Health: " .. playerData.health .. "/" .. (playerData.maxHealth or "20"))
  73.         else
  74.             mon.write("Health: N/A")
  75.         end
  76.  
  77.         -- Write if the player is in range
  78.         mon.setCursorPos(1, row + 3)
  79.         mon.write("In Range (" .. detectionRange .. " blocks): " .. (inRange and "Yes" or "No"))
  80.         if inRange then
  81.           playKlaxon
  82.         end
  83.         -- Add a separator
  84.         mon.setCursorPos(1, row + 4)
  85.         mon.write("-------------------")
  86.  
  87.         row = row + 6 -- Move to the next block of text (leaving a gap)
  88.     end
  89.  
  90.     -- If no players are online, display a message
  91.     if #players == 0 then
  92.         mon.setCursorPos(1, 3)
  93.         mon.write("No players online.")
  94.     end
  95.  
  96.     sleep(20) -- Refresh every 20 seconds
  97. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement