Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- This program sets up the environment needed to run
- -- the TrackerGlass program zEtx48ni written by
- -- MorgosMaci
- function validateSide(side)
- if side == "top" then
- return true
- end
- if side == "bottom" then
- return true
- end
- if side == "left" then
- return true
- end
- if side == "right" then
- return true
- end
- if side == "front" then
- return true
- end
- if side == "back" then
- return true
- end
- return false
- end
- function tableLength(t)
- local count = 0
- for _ in pairs(t) do count = count + 1 end
- return count
- end
- function clampX(x)
- if not x then
- x = 0
- end
- if x < -4530 then
- x = -4530
- end
- if x > 6235 then
- x = 6235
- end
- return x
- end
- function clampY(y)
- if not y then
- y = 0
- end
- if y < 5 then
- y = 5
- end
- if y > 255 then
- y = 255
- end
- return y
- end
- function clampZ(z)
- if not z then
- z = 0
- end
- if z < -4330 then
- z = -4330
- end
- if z > 6275 then
- z = 6275
- end
- return z
- end
- function writeColor(mon, text, fgColor, bgColor)
- if (mon.isColor()) then
- if fgColor then
- mon.setTextColor(fgColor)
- end
- if bgColor then
- mon.setBackgroundColor(bgColor)
- end
- end
- mon.write(text)
- if (mon.isColor()) then
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- end
- end
- function getDevice(search)
- local plist = peripheral.getNames()
- local i, name
- for i, name in pairs(plist) do
- if string.find(peripheral.getType(name), search) then
- return peripheral.wrap(name)
- end
- end
- if search == monitor then
- return term
- else
- return nil
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Setting up TrackerGlass by MorgosMaci")
- term.setCursorPos(1, 3)
- term.write("Checking hardware configuration...")
- fatal = false
- term.setCursorPos(1, 4)
- term.write("Checking for monitor: ")
- mon = getDevice("monitor")
- term.setCursorPos(23, 4)
- if mon then
- mon.setTextScale(0.5)
- mw, mh = mon.getSize()
- if mh < 30 or mw < 65 then
- writeColor(term, "Monitor must be atleast 4x3.", colors.red)
- fatal = true
- elseif not mon.isColor() then
- writeColor(term, "Color preferred.", colors.yellow)
- else
- writeColor(term, "Good.", colors.green)
- end
- else
- writeColor(term, "Monitor not found.", colors.red)
- fatal = true
- end
- term.setCursorPos(1, 5)
- term.write("Checking for bridge: ")
- d = getDevice("glassesbridge")
- term.setCursorPos(22, 5)
- if d then
- writeColor(term, "Good.", colors.green)
- else
- writeColor(term, "Glasses bridge not found.", colors.red)
- fatal = true
- end
- term.setCursorPos(1, 6)
- term.write("Checking for ME Interface: ")
- d = getDevice("me_interface")
- term.setCursorPos(28, 6)
- if d then
- writeColor(term, "Good.", colors.green)
- else
- writeColor(term, "Not found.", colors.yellow)
- end
- term.setCursorPos(1, 7)
- term.write("Checking for drive: ")
- term.setCursorPos(21, 7)
- basedir = "/"
- if fs.isDir("/disk") then
- if fs.getFreeSpace("/disk") < 100000 then
- writeColor(term, "Too small.", colors.yellow)
- else
- writeColor(term, "Good.", colors.green)
- basedir = "/disk/"
- end
- else
- writeColor(term, "Not found.", colors.yellow)
- end
- term.setCursorPos(1, 9)
- if fatal then
- writeColor(term, "Invalid hardware setup.", colors.red)
- print("\nTerminating.\n")
- return
- end
- print("Hardware is sufficient.\n")
- print("Review any warnings and press enter to start.")
- read()
- term.clear()
- term.setCursorPos(1, 1)
- print("Setting up "..basedir.."settings/default.settings\n")
- defaultSettings = {}
- -- Setup the default spawn and world filter.
- defaultSettings.worldFilter = "world"
- defaultSettings.hereSpawn = vector.new(910, 65, 1035)
- -- Setup the default location of the tracking window.
- defaultSettings.trackLoc = {x=1, y=1}
- -- Setup the default location of the output window.
- defaultSettings.outputLoc = {x=400, y=40, l=40}
- defaultSettings.privUsers = {}
- while tableLength(defaultSettings.privUsers) < 1 do
- print("Enter admin users seperated by a space.")
- users = read()
- for user in string.gmatch(users, "[^%s]+") do
- defaultSettings.privUsers[user] = true
- end
- end
- print("Enter X coordinate of your base.")
- local x = clampX(tonumber(read()))
- print("Enter Y coordinate of your base.")
- local y = clampY(tonumber(read()))
- print("Enter Z coordinate of your base.")
- local z = clampZ(tonumber(read()))
- defaultSettings.hereDefault = vector.new(x, y, z)
- d = getDevice("me_interface")
- if d then
- defaultSettings.MESide = ""
- while not validateSide(defaultSettings.MESide) do
- print("Enter the side of the ME interface for the\ndelivery chest. (Default top)")
- defaultSettings.MESide = read()
- if defaultSettings.MESide == "" then
- defaultSettings.MESide = "top"
- end
- end
- else
- defaultSettings.MESide = "top"
- end
- term.clear()
- term.setCursorPos(1, 1)
- print("Creating "..basedir.."settings")
- fs.makeDir(basedir.."settings")
- print("Writing "..basedir.."settings/default.settings\n")
- local fh = fs.open(basedir.."settings/default.settings", "w")
- if fh then
- fh.write(textutils.serialize(defaultSettings))
- fh.close()
- else
- print("Error creating the default settings file.")
- return
- end
- fs.delete(basedir.."tg")
- print("Writing startup file...")
- fh = fs.open(basedir.."startup", "w")
- if fh then
- fh.write("main = \""..basedir.."tg\"\n")
- fh.write("if fs.exists(main) then\n")
- fh.write(" os.run({}, main)\n")
- fh.write("end\n")
- fh.close()
- else
- Print("Error creating the startup file.")
- return
- end
- print("Downloading the main program to "..basedir.."tg...")
- success = shell.run("pastebin", "get", "zEtx48ni", basedir.."tg")
- if not success then
- print("Error downloading from pastebin zEtx48ni.")
- return
- end
- print("Press enter to reboot.")
- read()
- os.reboot()
Add Comment
Please, Sign In to add comment