Advertisement
xX-AAAAAAAAAA-Xx

ComputerCraft + Computronics Radar

Sep 2nd, 2024 (edited)
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. -- Wrap the radar peripheral and open port 420
  2. local radar = peripheral.wrap("left")
  3. rednet.open("right") -- Assuming the modem is on the right side, adjust as needed
  4. local port = 420
  5.  
  6. -- Function to get player distances
  7. local function getPlayerDistances()
  8. local players = radar.getPlayers()
  9. local playerData = {}
  10.  
  11. for i = 1, #players do
  12. local playerName = players[i].name or "Unknown"
  13. local distance = players[i].distance or 0
  14. table.insert(playerData, {name = playerName, distance = distance})
  15. end
  16.  
  17. return playerData
  18. end
  19.  
  20. -- Main loop
  21. while true do
  22. local senderID, message, protocol = rednet.receive(port)
  23. if message == "request_distance" then
  24. local playerData = getPlayerDistances()
  25. rednet.send(senderID, playerData, port)
  26. print("Sent player distances to " .. senderID)
  27. end
  28. end
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement