MtnMCG

sos port main

Jun 6th, 2025 (edited)
8
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. -- Portable Computer: tracker.lua
  2. -- By Gemini
  3.  
  4. -- CONFIGURATION --
  5. -- Set the ID of the stationary computer you want to send coordinates to.
  6. local serverId = 1 -- IMPORTANT: Change this to the ID of your stationary computer!
  7.  
  8. -- Set how often (in seconds) to send the coordinates.
  9. local sendInterval = 5 -- 5 seconds
  10.  
  11. -- -- -- -- -- -- --
  12.  
  13. -- First, make sure the ender modem is open on the correct side.
  14. -- Replace "top" with the side your ender modem is attached to.
  15. rednet.open("back")
  16.  
  17. if not gps then
  18. error("GPS API not available. Is this an advanced portable computer?")
  19. end
  20.  
  21. print("Tracker started. Sending coordinates to server ID: " .. serverId)
  22. print("Press CTRL+T to terminate.")
  23.  
  24. while true do
  25. -- Get the GPS coordinates. This requires the computer to have a clear view of the sky.
  26. local x, y, z = gps.locate()
  27.  
  28. if x then
  29. -- Package the coordinates into a Lua table.
  30. local coordinates = {x = x, y = y, z = z}
  31.  
  32. -- Serialize the table into a string to send it over rednet.
  33. local message = textutils.serialize(coordinates)
  34.  
  35. -- Send the message to the server.
  36. rednet.send(serverId, message, "gps_coords")
  37. print(string.format("Sent coordinates: %d, %d, %d", x, y, z))
  38. else
  39. print("Could not get a GPS lock. Make sure you are outdoors.")
  40. end
  41.  
  42. -- Wait for the specified interval before looping again.
  43. os.sleep(sendInterval)
  44. end
Advertisement
Add Comment
Please, Sign In to add comment