Advertisement
DOGGYWOOF

GPS satalite

Aug 23rd, 2024 (edited)
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. -- GPS Satellite Program with Fixed IDs
  2.  
  3. -- Define the satellite's Computer ID and coordinates
  4. local satelliteID = os.getComputerID() -- Automatically get this computer's ID
  5. local xPos, yPos, zPos = 100, 64, 100 -- Replace with the satellite's coordinates
  6.  
  7. -- Open the rednet modem
  8. local function startGPS()
  9. rednet.open("right") -- Ensure the modem is on the correct side
  10. print("Satellite ID " .. satelliteID .. " is broadcasting...")
  11.  
  12. while true do
  13. -- Wait for a request and respond with the satellite's data
  14. local senderID, message = rednet.receive("GPS")
  15. if message == "request" then
  16. local data = {
  17. id = satelliteID,
  18. x = xPos,
  19. y = yPos,
  20. z = zPos
  21. }
  22. rednet.send(senderID, textutils.serializeJSON(data), "GPS")
  23. print("Sent data to " .. senderID)
  24. end
  25. end
  26. end
  27.  
  28. startGPS()
  29.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement