Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GPS Host Program with Coordinate Storage
- -- File to store coordinates
- local COORD_FILE = "gps_coords.txt"
- -- Function to read coordinates from file
- local function readCoordsFromFile()
- if fs.exists(COORD_FILE) then
- local file = fs.open(COORD_FILE, "r")
- local x = tonumber(file.readLine())
- local y = tonumber(file.readLine())
- local z = tonumber(file.readLine())
- file.close()
- if x and y and z then
- return x, y, z
- end
- end
- return nil
- end
- -- Function to write coordinates to file
- local function writeCoordsToFile(x, y, z)
- local file = fs.open(COORD_FILE, "w")
- file.writeLine(x)
- file.writeLine(y)
- file.writeLine(z)
- file.close()
- end
- -- Function to get coordinates from user input
- local function getCoords()
- print("Enter this computer's exact Minecraft block coordinates:")
- io.write("X: ")
- local x = tonumber(io.read())
- io.write("Y: ")
- local y = tonumber(io.read())
- io.write("Z: ")
- local z = tonumber(io.read())
- return x, y, z
- end
- -- Main program
- local x, y, z = readCoordsFromFile()
- if not x or not y or not z then
- x, y, z = getCoords()
- if not x or not y or not z then
- print("Invalid coordinates. Exiting.")
- return
- end
- writeCoordsToFile(x, y, z)
- print("Coordinates saved to file.")
- else
- print("Using stored coordinates:", x, y, z)
- end
- print("Starting GPS Host at Minecraft coordinates:", x, y, z)
- -- Ensure the modem is on
- local sides = {"top", "bottom", "left", "right", "front", "back"}
- local modemOpened = false
- for _, side in ipairs(sides) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- rednet.open(side)
- modemOpened = true
- print("Modem opened on side: " .. side)
- break
- end
- end
- if not modemOpened then
- print("No modem found. Please attach a modem to the computer.")
- return
- end
- -- Start the GPS host
- print("Starting GPS host...")
- shell.run("gps", "host", x, y, z)
- -- This point is reached only if shell.run returns, which it shouldn't under normal operation
- print("GPS Host has stopped. Please check for errors.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement