Advertisement
ElliNet13

GPS Installer

May 18th, 2025
557
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.13 KB | Source Code | 0 0
  1. -- GPS Tower installer by ElliNet13
  2. -- Check if advanced
  3. local isAdvanced = term.isColor()
  4. -- Check for any wireless modem
  5. local hasWirelessModem = false
  6. for _, name in ipairs(peripheral.getNames()) do
  7.     if peripheral.getType(name) == "modem" then
  8.         local modem = peripheral.wrap(name)
  9.         if modem.isWireless and modem.isWireless() then
  10.             hasWirelessModem = true
  11.             break
  12.         end
  13.     end
  14. end
  15. -- Try GPS
  16. local x, y, z = gps.locate(2)
  17. local gpsWorking = x ~= nil
  18. -- Final check
  19. local ok = isAdvanced and hasWirelessModem
  20. -- Output
  21. print("Advanced computer:", isAdvanced)
  22. print("Wireless modem:", hasWirelessModem)
  23. print("GPS working:", gpsWorking)
  24. if gpsWorking then
  25.     print("GPS location: x="..x.." y="..y.." z="..z)
  26. end
  27. print("Computer ready (advanced + modem):", ok)
  28. -- If not ok, reject
  29. if not ok then
  30.     print("Sorry, you can not be a GPS tower.")
  31.     return
  32. end
  33. -- Ask for 3 numbers
  34. print("Enter 3 numbers (X Y Z):")
  35. local input = read()
  36. local userX, userY, userZ = input:match("^(%-?%d+)%s+(%-?%d+)%s+(%-?%d+)$")
  37. userX, userY, userZ = tonumber(userX), tonumber(userY), tonumber(userZ)
  38. if not (userX and userY and userZ) then
  39.     print("Invalid input. Please enter 3 numbers separated by spaces.")
  40.     return
  41. end
  42. -- Show user input
  43. print("You entered: x="..userX.." y="..userY.." z="..userZ)
  44. -- Full command wrapped in shell.run()
  45. local shellCommand = string.format('shell.run("bg gps host %d %d %d")', userX, userY, userZ)
  46. -- Paths to check
  47. local startupPaths = {"startup", "startup.lua"}
  48. local startupFound = false
  49. -- Append to existing startup or startup.lua
  50. for _, path in ipairs(startupPaths) do
  51.     if fs.exists(path) then
  52.         local file = fs.open(path, "a")
  53.         file.writeLine(shellCommand)
  54.         file.close()
  55.         startupFound = true
  56.     end
  57. end
  58. -- If neither existed, create startup
  59. if not startupFound then
  60.     local file = fs.open("startup", "w")
  61.     file.writeLine(shellCommand)
  62.     file.close()
  63. end
  64. -- Run it now
  65. shell.run("bg", "gps", "host", tostring(userX), tostring(userY), tostring(userZ))
  66. print("You have now been added as a GPS tower, thanks!")
Tags: Cc tweaked
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement
OSZAR »