Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- GPS Tower installer by ElliNet13
- -- Check if advanced
- local isAdvanced = term.isColor()
- -- Check for any wireless modem
- local hasWirelessModem = false
- for _, name in ipairs(peripheral.getNames()) do
- if peripheral.getType(name) == "modem" then
- local modem = peripheral.wrap(name)
- if modem.isWireless and modem.isWireless() then
- hasWirelessModem = true
- break
- end
- end
- end
- -- Try GPS
- local x, y, z = gps.locate(2)
- local gpsWorking = x ~= nil
- -- Final check
- local ok = isAdvanced and hasWirelessModem
- -- Output
- print("Advanced computer:", isAdvanced)
- print("Wireless modem:", hasWirelessModem)
- print("GPS working:", gpsWorking)
- if gpsWorking then
- print("GPS location: x="..x.." y="..y.." z="..z)
- end
- print("Computer ready (advanced + modem):", ok)
- -- If not ok, reject
- if not ok then
- print("Sorry, you can not be a GPS tower.")
- return
- end
- -- Ask for 3 numbers
- print("Enter 3 numbers (X Y Z):")
- local input = read()
- local userX, userY, userZ = input:match("^(%-?%d+)%s+(%-?%d+)%s+(%-?%d+)$")
- userX, userY, userZ = tonumber(userX), tonumber(userY), tonumber(userZ)
- if not (userX and userY and userZ) then
- print("Invalid input. Please enter 3 numbers separated by spaces.")
- return
- end
- -- Show user input
- print("You entered: x="..userX.." y="..userY.." z="..userZ)
- -- Full command wrapped in shell.run()
- local shellCommand = string.format('shell.run("bg gps host %d %d %d")', userX, userY, userZ)
- -- Paths to check
- local startupPaths = {"startup", "startup.lua"}
- local startupFound = false
- -- Append to existing startup or startup.lua
- for _, path in ipairs(startupPaths) do
- if fs.exists(path) then
- local file = fs.open(path, "a")
- file.writeLine(shellCommand)
- file.close()
- startupFound = true
- end
- end
- -- If neither existed, create startup
- if not startupFound then
- local file = fs.open("startup", "w")
- file.writeLine(shellCommand)
- file.close()
- end
- -- Run it now
- shell.run("bg", "gps", "host", tostring(userX), tostring(userY), tostring(userZ))
- print("You have now been added as a GPS tower, thanks!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement