Guest User

cc code

a guest
Jun 24th, 2026
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. -- Player Detector Chat Command Script
  2. -- Requires: Advanced Peripherals (Player Detector peripheral)
  3. -- Place Player Detector adjacent to the computer, then run this script.
  4.  
  5. local detector = peripheral.find("playerDetector")
  6. if not detector then
  7. error("No Player Detector found! Attach one to this computer.", 0)
  8. end
  9.  
  10. -- Helper: get readable dimension name
  11. local function formatDimension(dim)
  12. if not dim then return "Unknown" end
  13. local names = {
  14. ["minecraft:overworld"] = "Overworld",
  15. ["minecraft:the_nether"] = "The Nether",
  16. ["minecraft:the_end"] = "The End",
  17. }
  18. return names[dim] or dim
  19. end
  20.  
  21. -- Helper: parse "where is <name>" from chat message
  22. local function parseQuery(message)
  23. local name = message:match("^%s*where is%s+(%S+)%s*$")
  24. if not name then
  25. name = message:match("^%s*pos%s+(%S+)%s*$")
  26. end
  27. return name
  28. end
  29.  
  30. print("Player Detector active.")
  31. print('Say "where is <player>" or "pos <player>" in chat.')
  32. print("Press Ctrl+T to stop.")
  33.  
  34. -- Listen for chat events
  35. while true do
  36. local event, username, message = os.pullEvent("chat")
  37.  
  38. local target = parseQuery(message:lower())
  39. -- preserve original casing by re-parsing with original message
  40. if not target then
  41. target = parseQuery(message)
  42. else
  43. -- re-extract with original casing
  44. target = message:match("[Ww]here%s+[Ii]s%s+(%S+)") or
  45. message:match("[Pp]os%s+(%S+)")
  46. end
  47.  
  48. if target then
  49. -- Get online players and do case-insensitive match
  50. local players = detector.getOnlinePlayers()
  51. local matched = nil
  52. for _, p in ipairs(players) do
  53. if p:lower() == target:lower() then
  54. matched = p
  55. break
  56. end
  57. end
  58.  
  59. if not matched then
  60. print("[" .. username .. "] Player '" .. target .. "' is not online.")
  61. else
  62. local pos = detector.getPlayerPos(matched)
  63. if pos then
  64. local dim = formatDimension(pos.dimension)
  65. local x = math.floor(pos.x * 10 + 0.5) / 10
  66. local y = math.floor(pos.y * 10 + 0.5) / 10
  67. local z = math.floor(pos.z * 10 + 0.5) / 10
  68.  
  69. local reply = string.format(
  70. "[Detector] %s is at X: %.1f Y: %.1f Z: %.1f | Dimension: %s",
  71. matched, x, y, z, dim
  72. )
  73.  
  74. -- Print to terminal
  75. print(reply)
  76.  
  77. -- If a chat peripheral (e.g. Chat Box from AP) is available, respond in chat
  78. local chatBox = peripheral.find("chatBox")
  79. if chatBox then
  80. chatBox.sendMessage(reply, "Detector")
  81. end
  82. else
  83. print("[" .. username .. "] Could not get position for " .. matched .. ".")
  84. end
  85. end
  86. end
  87. end
  88.  
Add Comment
Please, Sign In to add comment