Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Portable Computer: tracker.lua
- -- By Gemini
- -- CONFIGURATION --
- -- Set the ID of the stationary computer you want to send coordinates to.
- local serverId = 1 -- IMPORTANT: Change this to the ID of your stationary computer!
- -- Set how often (in seconds) to send the coordinates.
- local sendInterval = 5 -- 5 seconds
- -- -- -- -- -- -- --
- -- First, make sure the ender modem is open on the correct side.
- -- Replace "top" with the side your ender modem is attached to.
- rednet.open("back")
- if not gps then
- error("GPS API not available. Is this an advanced portable computer?")
- end
- print("Tracker started. Sending coordinates to server ID: " .. serverId)
- print("Press CTRL+T to terminate.")
- while true do
- -- Get the GPS coordinates. This requires the computer to have a clear view of the sky.
- local x, y, z = gps.locate()
- if x then
- -- Package the coordinates into a Lua table.
- local coordinates = {x = x, y = y, z = z}
- -- Serialize the table into a string to send it over rednet.
- local message = textutils.serialize(coordinates)
- -- Send the message to the server.
- rednet.send(serverId, message, "gps_coords")
- print(string.format("Sent coordinates: %d, %d, %d", x, y, z))
- else
- print("Could not get a GPS lock. Make sure you are outdoors.")
- end
- -- Wait for the specified interval before looping again.
- os.sleep(sendInterval)
- end
Advertisement
Add Comment
Please, Sign In to add comment