Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- 'Map' (GPS Minimap) by EldidiStroyrr (LDDestroier)
- Get with
- pastebin get x9ajKSc0 map
- or
- std pb x9ajKSc0 map
- std ld map map
- This is a stable release. You fool!
- --]]
- local mapRelease = "main"
- local pastebinIDList = {
- main = "x9ajKSc0",
- beta = "KJ4t2DM9",
- }
- mapVersion = "1.3.9" --Version of Map. Must be string.
- os.pullEvent = os.pullEventRaw
- local scr_x, scr_y = term.getSize()
- local parentDir = fs.combine("",fs.getDir(shell.getRunningProgram()))
- local configDir = fs.combine(parentDir,".map")
- if fs.isReadOnly(configDir) then
- configDir = ".map"
- end
- if not fs.isDir(configDir) then
- if fs.exists(configDir) then fs.delete(configDir) end
- fs.makeDir(configDir)
- end
- if fs.isReadOnly(shell.resolve(shell.getRunningProgram())) then --In case Map is located in a write-protected directory.
- waypointDir = fs.combine(fs.getName(configDir),"waypoints")
- mapConfigFile = fs.combine(fs.getName(configDir),"config")
- pathDir = fs.combine(fs.getName(configDir),"paths")
- else
- waypointDir = "/" .. fs.combine(configDir, "waypoints")
- mapConfigFile = "/" .. fs.combine(configDir, "config")
- pathDir = fs.combine(configDir,"paths")
- end
- if not fs.exists(waypointDir) then fs.makeDir(waypointDir) end
- if not fs.exists(pathDir) then fs.makeDir(pathDir) end
- defaultWaypointFile = "waypoints" --The name of the waypoint file that is written to.
- mapNetworkWaypointsFile = fs.combine(waypointDir,"networkPoints")
- local mapName
- local function updateMapProgram(url)
- if not fs.isReadOnly(shell.resolve(shell.getRunningProgram())) then
- mapName = fs.combine("",shell.getRunningProgram())
- else
- mapName = shell.getRunningProgram()
- end
- local updateFile
- if url then
- updateFile = http.get(url)
- else
- updateFile = http.get("http://pastebin.com/raw.php?i=" .. pastebinIDList[mapRelease])
- end
- if updateFile then
- updateFile = updateFile.readAll()
- else
- error("Could not connect.")
- end
- local file = fs.open(mapName, "w")
- file.write(updateFile)
- file.close()
- return fs.getSize(mapName)
- end
- local function setColormode()
- if term.isColor() and colorLimit >= 2 then
- colormode = true
- grayAllowed = true
- else
- colormode = false
- if _VERSION and colorLimit >= 1 then
- grayAllowed = true
- else
- grayAllowed = false
- end
- end
- end
- local nothing = false
- local tArg = {...}
- if tArg[1] ~= nil then
- if tArg[1] == "cc" then
- if fs.exists(mapConfigFile) then
- fs.delete(mapConfigFile)
- print("Config cleared.")
- else
- print("No config to clear.")
- end
- fakeX = nil
- fakeY = nil
- fakeZ = nil
- fakeDir = nil
- return
- elseif tArg[1] == "cw" then
- if fs.exists(waypointDir) then
- fs.delete(waypointDir)
- print("Waypoints cleared.")
- else
- print("No waypoints to clear.")
- end
- return
- elseif tArg[1] == "oc" then
- shell.run("edit "..mapConfigFile)
- print("Config updated.")
- return
- elseif tArg[1] == "nothing" then
- nothing = true
- elseif tArg[1] == "update" then
- local file = tArg[2]
- local updateURL
- if not tArg[2] then
- updateURL = pastebinIDList[mapRelease]
- else
- if pastebinIDList[file] then
- updateURL = pastebinIDList[file]
- else
- print("Invalid update source.")
- return false
- end
- end
- write("Updating " .. shell.getRunningProgram() .. "...")
- local mapName = shell.getRunningProgram()
- local fileSize = updateMapProgram("http://pastebin.com/raw.php?i=" .. updateURL)
- print("done (got " .. fs.getSize(mapName) .. " bytes)")
- write("Updated from "..mapVersion)
- shell.run(fs.getName(shell.getRunningProgram()),"nothing")
- if mapVersion then
- print(" to "..mapVersion)
- else
- print("...whatever.")
- end
- return true
- elseif tArg[1] == "help" then
- local helpText = [[
- 'map update' Updates program.
- 'map fast' Runs term.redirect(term.native()).
- 'map cw' Deletes waypoints.
- 'map cc' Deletes config.
- 'map oc' Opens config.
- 'map nothing' gets config, but doesn't run
- Config path: ']]..mapConfigFile..[['
- Waypoint directory: ']]..waypointDir..[[']]
- print(helpText)
- return true
- elseif tArg[1] == "fast" then
- term.redirect(term.native())
- end
- end
- local function runMapProgramAlready() --This is to allow me to run pcall on the program.
- function numberToColor(input)
- if type(input) == "number" then
- for k,v in pairs(colors) do
- if input == v then
- return "colors."..k
- end
- end
- elseif type(input) == "table" then
- local output = {}
- for a = 1, #input do
- for k,v in pairs(colors) do
- if input[a] == v then
- table.insert(output,"colors."..k)
- end
- end
- end
- return output
- end
- return false
- end
- local function yield()
- os.queueEvent("yield")
- os.pullEvent("yield")
- end
- local function seperateMethods(input)
- local output={}
- for key,value in pairs(input) do
- table.insert(output, {key,value})
- end
- return output
- end
- local function defineMapBorders()
- local mapCorners
- if not monitorMode then
- mapCorners = { --Top left corner, bottom right corner
- {
- 2,
- 2,
- },
- {
- scr_x - 1,
- scr_y - 6,
- }
- }
- else
- mapCorners = {
- {
- 1,
- 1,
- },
- {
- scr_x,
- scr_y - 3,
- }
- }
- end
- corner1 = mapCorners[1]
- corner2 = mapCorners[2]
- midPoint = {
- math.floor((corner1[1] + corner2[1]) / 2),
- math.floor((corner1[2] + corner2[2]) / 2)
- }
- mapDimensions = {
- corner2[1] - corner1[1],
- corner2[2] - corner1[2]
- }
- end
- defineMapBorders()
- --[[ In case adding this to the config messes something up, I want to easily fix it.
- mapColors = { --This controls most of the colors in the program, except for some hardcoded colors. If you are using a normal computer, grayscale or not, colors will not be pulled from this list.
- colors.gray, --Background color (default: colors.gray)
- colors.white, --Border color (default: colors.white)
- colors.yellow, --Waypoint color (default: colors.yellow)
- colors.red, --Offscreen waypoint arrow color (default: colors.red)
- colors.lightBlue, --Direction indicator color (default: colors.lightBlue)
- colors.black, --Command list text color (default: colors.black)
- colors.lightGray, --Command list background color (default: colors.lightGray)
- colors.red, --Background color if not connected to GPS server (default: colors.red)
- colors.black, --Map background color (default: colors.black)
- }
- directionSensitivity = 0.15 --This is used to prevent the arrow on the middle of the screen from going crazy.
- --]]
- displayStuffs = true
- currentlyConnected = false --We don't know, so assume false because of glitch with numpad
- isConnected = false --We still don't know, and it's just safer to assume false because of visual bugs
- arrows = {
- ">",
- "v",
- "<",
- "^"
- }
- youChar = "O" --This used to be a config item, too bad it was useless. Luckily, it was replaced with many, much more useful options for you to screw up.
- playerChar = youChar
- function displayTitleScreen()
- term.clear()
- term.setCursorPos(1,1)
- if colormode then
- paintutils.drawImage(mapTitleScreen_adv, 1, 1)
- else
- if grayAllowed then
- paintutils.drawImage(mapTitleScreen_gray, 1, 1)
- else
- paintutils.drawImage(mapTitleScreen_norm, 1, 1)
- end
- end
- if colormode then
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightBlue)
- else
- if grayAllowed then
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- else
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- end
- term.setCursorPos(5,4)
- print("Version " .. mapVersion)
- term.setCursorPos(5,3)
- print("Made by EldidiStroyrr")
- sleep(0.1)
- repeat
- event, param1 = os.pullEvent()
- until event == "key" or event == "mouse_click" or event == "monitor_touch"
- end
- function refreshOtherConfig()
- local file = fs.open(mapConfigFile, "w")
- local mapSettings = {
- {
- "spoofMode = " .. tostring(spoofMode),
- "boolean, set true if testing program in emulator. Replaces gps movement detection with arrow keys. Default: false",
- },
- {
- "broadcastData = " .. tostring(broadcastData),
- "boolean, set true if you want other people to see your location. Default: true",
- },
- {
- "networkName = '" .. tostring(networkName) .. "'",
- "string, what your name appears as for other Map clients. Default: 'mapuser'..math.random(1,9999)",
- },
- {
- "mapProtocol = " .. textutils.serialize(mapProtocol),
- "table, list of modem protocols of the data broadcasted to other clients. Default: {10666}",
- },
- {
- "scaleFactor = " .. tostring(scaleFactor),
- "number, the zoom factor for the minimap. Lower means wider range. Does not affect GPS range. Default: 0.25",
- },
- {
- "displayTitle = " .. tostring(displayTitle),
- "boolean, whether or not to display the title screen. I find it kind of garish, but I already did the work. Default: false",
- },
- {
- "labelMode = " .. tostring(labelMode),
- "boolean, true if waypoint labels are their names, false if their distances. Default: true",
- },
- {
- "waypointChar = '" .. tostring(waypointChar) .. "'",
- "string, the character that waypoints on the map are represented by. Default: '*'",
- },
- {
- "blankChar = '" .. tostring(blankChar) .. "'",
- "string, the blank character that the inside of the map is made of. Default: ' '",
- },
- {
- "refreshSleep = " .. tostring(refreshSleep),
- "number, the delay between each GPS request. Default: 0.4",
- },
- {
- "autoUpdate = " .. tostring(autoUpdate),
- "boolean, whether or not Map automatically updates to the latest version. this is reccommended FALSE because new updates could break the program into a state where it can't update again. Default: false",
- },
- {
- "turtleMode = " .. tostring(turtleMode),
- "boolean, whether Map should be tuned to turtle controlling. Especially useful if used in conjunction with Lyqyd's NSH. Default: false",
- },
- {
- "keyAgoesRight = " .. tostring(keyAgoesRight),
- "boolean, determines whether to invert the left/right turtle turning controls. Requires turtleMode=true. This option exists because the 'A' button turns the turtle left on the map, but not in minecraft world. Default: false",
- },
- {
- "spoofStep = " .. tostring(spoofStep),
- "number, amount you move in one keypress in spoof mode. Used to move faster. Default: 1",
- },
- {
- "mapColors = " .. string.gsub( textutils.serialize(numberToColor(mapColors)), "\"", "" ),
- "table, there are 9 items in this array, and this controls most of the colors in the program, except for some hardcoded colors and for normal computers. The colors are, in sequence: background color outside, border color, waypoint color, offscreen waypoint arrow color, direction indicator color, command screen text color, command screen background color, background color if not connected to GPS, background color inside. Do not input any values into this config option that isn't a color, or the program will crash. Default: {colors.gray, colors.white, colors.yellow, colors.red, colors.lightBlue, colors.black, colors.lightGray, colors.red, colors.black}",
- },
- {
- "directionSensitivity = " .. tostring(directionSensitivity),
- "number, this is used to prevent the arrow on the middle of the screen from going crazy. it will only change the middle indicator if you move that amount of meters. Default: 0.15",
- },
- {
- "monitorTextScale = " .. tostring(monitorTextScale),
- "number, this determines what scale factor the text has if Map is being ran on a monitor. Default: 0.5",
- },
- {
- "fakeX = " .. tostring(fakeX),
- "number, this is the last recorded X position of the turtle/PDA. Is used in spoofMode, and updates when using turtleMode. Default: 0",
- },
- {
- "fakeY = " .. tostring(fakeY),
- "number, same as fakeX but for Y. Default: 66",
- },
- {
- "fakeZ = " .. tostring(fakeZ),
- "number, same as fakeX but for Z. Default: 0",
- },
- {
- "fakeDir = " .. tostring(fakeDir),
- "number, equal to 'f' in Debug mode in Minecraft (F3), range=0-3. Default: nil",
- },
- {
- "doFlash = " .. tostring(doFlash),
- "boolean, whether or not to do the flash animation when starting map up or exiting a menu. Default: false",
- },
- {
- "colorLimit = " .. tostring(colorLimit),
- "number, artificially limits the color palate. (0=monochrome,1=grayscale,2=colors). Default: 2",
- },
- }
- file.writeLine("-" .. "- Do not break the format of this config.")
- file.writeLine("-" .. "- This is for EldidiStroyrr/LDDestroier's 'Map' (GPS Minimap). Do 'map cc' to fix broken config.")
- file.writeLine("-" .. "- This config has been last used on version " .. mapVersion .. ", for reference.")
- for a = 1, #mapSettings do
- file.writeLine(mapSettings[a][1] .. " -" .. "-" .. mapSettings[a][2])
- end
- file.writeLine("")
- file.close()
- end
- function getConfig(mode)
- if not fs.exists(fs.combine(waypointDir, defaultWaypointFile)) or (not fs.isDir(waypointDir)) then
- if fs.exists("/.waypoints") and (not fs.isDir("/.waypoints")) then
- fs.move("/.waypoints", "/waypoints")
- fs.makeDir(waypointDir)
- fs.move("/waypoints", fs.combine(waypointDir, defaultWaypointFile))
- else
- fs.makeDir(waypointDir)
- file = fs.open(fs.combine(waypointDir, defaultWaypointFile), "w")
- file.write({})
- file.close()
- end
- end
- local wayFiles = fs.list(waypointDir)
- waypoints = {}
- fileWaypoints = {}
- for a = 1, #wayFiles do
- if not fs.isDir(fs.combine(waypointDir, wayFiles[a])) then
- file = fs.open(fs.combine(waypointDir, wayFiles[a]), "r")
- contents = file.readAll()
- contents = textutils.unserialize(contents)
- file.close()
- for b = 1, #contents do
- table.insert(waypoints, contents[b])
- if wayFiles[a] == defaultWaypointFile then
- table.insert(fileWaypoints, contents[b])
- end
- end
- end
- end
- --This part has been modified to automatically fix missing config options, at the cost of the inability to add custom ones. Sorry, but this is more useful.
- local modem = peripheral.find("modem")
- if modem and mapProtocol then
- for a = 1, #mapProtocol do
- modem.close(mapProtocol[a])
- end
- end
- spoofMode = false
- broadcastData = true
- scaleFactor = 0.25
- networkName = "mapuser"..math.random(1,9999)
- mapProtocol = {10666}
- displayTitle = false
- labelMode = true
- waypointChar = '*'
- blankChar = ' '
- refreshSleep = 0.4
- autoUpdate = false
- if turtle then
- turtleMode = true
- else
- turtleMode = false
- end
- keyAgoesRight = false --Useless and probably cauyses problems..but whatever
- spoofStep = 1
- mapColors = { --This controls most of the colors in the program, except for some hardcoded colors. If you are using a normal computer, grayscale or not, colors will not be pulled from this list.
- colors.gray, --Background color outside map square
- colors.white, --Border color
- colors.yellow, --Default waypoint color
- colors.red, --Off-screen waypoint text color
- colors.lightBlue, --Player color
- colors.black, --Command screen text color
- colors.lightGray, --Command screen background color
- colors.red, --Background color if not connected to a GPS server
- colors.black, --Background color inside map square
- }
- directionSensitivity = 0.15 --This is used to prevent the arrow on the middle of the screen from going crazy.
- monitorTextScale = 0.5 --This determines what scale factor the text has if Map is being ran on a monitor.
- fakeX = 0
- fakeY = 66
- fakeZ = 0
- fakeDir = 0
- doFlash = fals
- colorLimit = 2
- shell.run(mapConfigFile) --Get the existing config options.
- setColormode()
- if not type(networkName) == "string" then networkName = "mapuser"..math.random(1,9999) end
- if not type(mapProtocol) == "table" then mapProtocol = {10666} end
- refreshOtherConfig() --Set the config file to what the variables are.
- if scr_x > 16 or scr_y > 10 then --Determines if Map is being ran on a single monitor block.
- monitorMode = false
- else
- monitorMode = true
- end
- if not monitorTextScale then --This whole bit is for monitors, should you be arsed to use them with this.
- monitorTextScale = 0.5
- end
- if monitorTextScale < 0.5 then
- monitorTextScale = 0.5
- elseif monitorTextScale > 5 then
- monitorTextScale = 5
- end
- if type(monitorTextScale) ~= "number" then
- monitorTextScale = 0.5
- end
- local mon = peripheral.find("monitor")
- if mon then
- if not monitorMode then
- mon.setTextScale(monitorTextScale)
- else
- mon.setTextScale(0.5)
- end
- end
- if mode == "waypoint" then
- return fileWaypoints
- else
- return contents
- end
- end
- getConfig()
- function set(list) --Used to check if a phrase is in a table. Straight from StackOverflow, by Jon Ericson.
- local set = {}
- for _, l in ipairs(list) do
- set[l] = true
- end
- return set
- end
- function stringToColor(color)
- local stringColors = {"white","orange","magneta","lightBlue","yellow","lime","pink","gray","lightGray","cyan","purple","blue","brown","green","red","black"}
- local numberColors = {colors.white,colors.orange,colors.magneta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.gray,colors.lightGray,colors.cyan,colors.purple,colors.blue,colors.brown,colors.green,colors.red,colors.black}
- if string.sub(color, 1, 7) == "colors." then
- color = string.sub(color, 8)
- end
- for a = 1, #stringColors do
- if string.lower(color) == string.lower(stringColors[a]) then
- return numberColors[a]
- end
- end
- return false
- end
- function setConfig(pointname, mode, x, y, z, derf)
- config = getConfig("waypoint")
- file = fs.open(fs.combine(waypointDir, defaultWaypointFile), "w")
- if mode == "delete" then
- for a = 1, #config do
- point = config[a]
- if point[1] == pointname then
- table.remove(config, a)
- file.writeLine(textutils.serialize(config))
- file.close()
- getConfig()
- return true
- end
- end
- file.close()
- return false
- elseif mode == "add" then
- if x == nil or y == nil or z == nil then
- file.close()
- return false
- end
- table.insert(config, {pointname, x, y, z, derf})
- file.writeLine(textutils.serialize(config))
- file.close()
- getConfig()
- return true
- elseif mode == "rename" then
- for a = 1, #config do
- point = config[a]
- if point[1] == pointname then
- table.remove(point, 1)
- table.insert(point, 1, x)
- file.writeLine(textutils.serialize(config))
- file.close()
- getConfig()
- return true
- end
- end
- file.close()
- return false
- end
- file.close()
- end
- local function round(num, idp)
- local mult=10^(idp or 0)
- return math.floor(num * mult + 0.5 ) / mult
- end
- local function setDefaultBackgroundColor()
- if isConnected then
- if colormode then
- term.setBackgroundColor(mapColors[1])
- else
- if grayAllowed then
- term.setBackgroundColor(colors.gray)
- else
- term.setBackgroundColor(colors.black)
- end
- end
- else
- if colormode then
- term.setBackgroundColor(mapColors[8])
- else
- term.setBackgroundColor(colors.white)
- end
- end
- end
- local function setDefaultTextColor()
- if colormode then
- term.setTextColor(mapColors[2])
- else
- if isConnected then
- term.setTextColor(colors.white)
- else
- term.setTextColor(colors.black)
- end
- end
- end
- local function setDefaultColors()
- setDefaultTextColor()
- setDefaultBackgroundColor()
- end
- local recordBuffer = {}
- if not oldCoord_x then
- oldCoord_x, oldCoord_y, oldCoord_z = 0,0,0
- posX, posY, posZ = 0,0,0
- end
- local function savePath(path)
- if not path then return false, "you need a table." end
- local pathpath
- setDefaultColors()
- term.clear()
- term.setCursorPos(1,2)
- print("Save path as: (blank for cancel)")
- repeat
- write(">")
- pathpath = read()
- if pathpath == "" then
- print("Cancelling.")
- sleep(0.2)
- return false
- end
- if fs.exists(fs.combine(pathDir,pathpath)) then
- pathpath = ""
- print("That already exists.")
- end
- until pathpath ~= ""
- pathpath = fs.combine(pathDir,pathpath)
- local file = fs.open(pathpath,"w")
- file.writeLine(textutils.serialize(path))
- file.close()
- print("Okay!")
- sleep(0.2)
- return true
- end
- local function getCoordinates()
- if spoofMode then
- isConnected = true
- currentlyConnected = true
- os.queueEvent("gpsRequest", true)
- return {fakeX, fakeY, fakeZ}
- else
- oldCoord_x, oldCoord_y, oldCoord_z = coord_x, coord_y, coord_z
- coord_x, coord_y, coord_z = gps.locate(5)
- if (coord_x == nil) and isConnected then
- currentlyConnected = false
- os.queueEvent("gpsRequest", false)
- if displayStuffs then
- term.setCursorPos(1,1)
- if colormode then
- term.setTextColor(colors.lightGray)
- else
- term.setTextColor(colors.white)
- end
- end
- if isConnected then
- if displayStuffs then
- term.clearLine()
- print("GPS not found...searching")
- end
- for a = 1, 5 do
- coord_x, coord_y, coord_z = gps.locate(1)
- if coord_x == nil then os.queueEvent("gpsRequest", false) end
- end
- if displayStuffs then
- if coord_x == nil then
- term.clearLine()
- end
- end
- end
- end
- if coord_x == nil then
- isConnected = false
- os.queueEvent("gpsRequest", false)
- return nil
- else
- isConnected = true
- currentlyConnected = true
- os.queueEvent("gpsRequest", true)
- fakeX, fakeY, fakeZ = coord_x, coord_y, coord_z
- if recording then
- if (math.floor(coord_x) ~= math.floor(oldCoord_x)) or (math.floor(coord_y) ~= math.floor(oldCoord_y)) or (math.floor(coord_z) ~= math.floor(oldCoord_z)) then
- table.insert(recordBuffer,{math.floor(coord_x),math.floor(coord_y),math.floor(coord_z)})
- end
- else
- if #recordBuffer > 0 then
- currentLocation = "savePath"
- displayStuffs = false
- savePath(recordBuffer)
- displayStuffs = true
- redrawMap = true
- renderCommands()
- currentLocation = "renderMap"
- end
- recordBuffer = {}
- end
- return {coord_x, coord_y, coord_z}
- end
- end
- end
- local function rollOver(input, max)
- return math.floor(input % max)
- end
- local function drawMovingLine(ypos, size, speed, spacesize)
- for a = 1, size do
- if currentLocation == "waypointSettings" then
- term.setCursorPos(1,ypos)
- if colormode then
- term.setTextColor(colors.orange)
- else
- if grayAllowed then
- term.setTextColor(colors.lightGray)
- else
- if isConnected then
- term.setTextColor(colors.white)
- else
- term.setTextColor(colors.black)
- end
- end
- end
- for x = 1, scr_x do
- if rollOver(x - a, size) < spacesize then
- write(" ")
- else
- write("-")
- end
- end
- sleep(speed)
- end
- end
- end
- function flashScreen(times)
- if (not times) or (type(times) ~= "number") then
- times = 1
- end
- if colormode or grayAllowed then
- flashes = {
- colors.black,
- colors.gray,
- colors.lightGray,
- colors.white,
- colors.lightGray,
- colors.black,
- }
- else
- flashes = {
- colors.black,
- colors.white,
- }
- end
- if doFlash then
- for a = 1, times do
- for b = 1, #flashes do
- term.setBackgroundColor(flashes[b])
- term.clear()
- sleep(0)
- end
- end
- end
- flashes = nil
- setDefaultColors()
- end
- --These functions were made by PhyscoKillerMonkey. It's subject to change...
- local function forward()
- while not mapturt.forward() do
- -- print("Can't move, checking fuel")
- if turtle.getFuelLevel() == 0 then
- turtle.select(1)
- turtle.refuel(1)
- end
- if digBlocks then
- turtle.dig()
- else
- mapturt.up()
- goneUp = goneUp + 1
- cy = cy + 1
- end
- end
- if dir == 0 then cz = cz + 1
- elseif dir == 1 then cx = cx - 1
- elseif dir == 2 then cz = cz - 1
- elseif dir == 3 then cx = cx + 1 end
- while goneUp > 0 and not turtle.detectDown() do
- mapturt.down()
- goneUp = goneUp - 1
- cy = cy - 1
- end
- end
- local function up()
- while not mapturt.up() do
- -- print("Can't move, checking fuel")
- if turtle.getFuelLevel() == 0 then
- turtle.select(1)
- turtle.refuel(1)
- end
- if digBlocks then
- turtle.digUp()
- end
- end
- cy = cy + 1
- end
- local function down()
- while not mapturt.down() do
- -- print("Can't move, checking fuel")
- if turtle.getFuelLevel() == 0 then
- turtle.select(1)
- turtle.refuel(1)
- end
- if digBlocks then
- turtle.digDown()
- end
- end
- cy = cy - 1
- end
- local function getPos()
- -- print("Getting position")
- local cx, cy, cz = gps.locate(5)
- print(cx, cy, cz)
- end
- local function getDir()
- -- print("Getting direction")
- getPos()
- local ox, oy, oz = cx, cy, cz
- forward()
- getPos()
- if oz > cz then dir = 0
- elseif oz < cz then dir = 2
- elseif ox < cx then dir = 1
- elseif ox > cx then dir = 3 end
- --print(dir)
- mapturt.back()
- getPos()
- end
- local function turn(d)
- -- getDir()
- -- print("Aligning")
- -- print(dir, d)
- while dir ~= d do
- mapturt.turnRight()
- dir = dir + 1
- if dir == 4 then dir = 0 end
- end
- end
- local function moveX()
- -- print("Moving X")
- -- getPos()
- if gox > cx then
- turn(1)
- for x = 1, gox - cx do
- forward()
- cx = cx + 1
- end
- elseif gox < cx then
- turn(3)
- for x = 1, cx - gox do
- forward()
- cx = cx - 1
- end
- end
- end
- local function moveZ()
- -- print("Moving Z")
- -- getPos()
- if goz > cz then
- turn(2)
- for z = 1, goz - cz do
- forward()
- cz = cz + 1
- end
- elseif goz < cz then
- turn(0)
- for z = 1, cz - goz do
- forward()
- cz = cz - 1
- end
- end
- end
- local function moveY()
- -- print("Moving Y")
- -- getPos()
- if goy > cy then
- for z = 1, goy - cy do
- up()
- cy = cy + 1
- end
- elseif goy < cy then
- for z = 1, cy - goy do
- down()
- cy = cy - 1
- end
- end
- end
- function clearMap()
- if displayStuffs then
- if not doGrid then
- setDefaultTextColor()
- if colormode then
- term.setBackgroundColor(mapColors[9])
- else
- term.setBackgroundColor(colors.black)
- end
- local mapLengthInner = (corner2[1]) - (corner1[1]) - 1
- local longBlankChar1 = string.rep(blankChar, mapLengthInner)
- for y = corner1[2] + 1, corner2[2] - 1 do
- term.setCursorPos(corner1[1]+1,y)
- if y == math.floor(midPoint[2]) then
- write(string.rep(blankChar, math.ceil(mapLengthInner/2)-1))
- term.setCursorPos(midPoint[1]+1,y)
- write(string.rep(blankChar, math.floor(mapLengthInner/2)))
- else
- write(longBlankChar1)
- end
- end
- setDefaultColors()
- for y = corner1[2], corner2[2] do
- term.setCursorPos(corner1[1]-1,y)
- write(" ") --I do " " because 'blankChar' is for the inside of the map.
- end
- for y = corner1[2], corner2[2] do
- term.setCursorPos(corner2[1]+1,y)
- write(" ") --Same here.
- end
- if isConnected then
- term.setCursorPos(1,corner1[2]-1)
- term.clearLine()
- end
- end
- end
- return
- end
- local commandXYPoses
- function drawBorder()
- defineMapBorders()
- if displayStuffs then
- if colormode then
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(mapColors[2])
- else
- if isConnected then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.white)
- else
- if grayAllowed then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.gray)
- else
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- end
- end
- local mapLength = corner2[1] - corner1[1]
- local mapHeight = corner2[2] - corner1[2]
- local longMapChar = string.rep(" ", mapLength)
- local longMapCharHalf = string.rep(" ", math.floor(mapLength/2))
- term.setCursorPos(corner1[1],corner1[2])
- write(longMapCharHalf)
- term.setCursorPos(midPoint[1]+1,corner1[2])
- write(longMapCharHalf)
- term.setCursorPos(corner1[1],corner2[2])
- write(longMapChar)
- for b = corner1[2], corner2[2] do
- term.setCursorPos(corner1[1],b)
- if b ~= midPoint[2] then
- write(" ")
- else
- write("X")
- end
- end
- for b = corner1[2], corner2[2] do
- term.setCursorPos(corner2[1],b)
- write(" ")
- end
- term.setCursorPos(midPoint[1],corner1[2])
- write("Z")
- -- term.setCursorPos(corner1[1],midPoint[2])
- -- write("X")
- setDefaultColors()
- end
- return
- end
- function drawScaleIndicator()
- if math.floor(scaleFactor*100000) == 0 then
- scaleFactor = 0.01
- end
- if displayStuffs then
- scaleX = corner1[1] + 1
- if not monitorMode then
- scaleY = corner2[2] + 1
- else
- scaleY = scr_y - 2
- end
- term.setCursorPos(scaleX,scaleY)
- setDefaultColors()
- term.clearLine()
- if isConnected then
- term.setTextColor(colors.white)
- else
- if colormode then
- term.setTextColor(colors.white)
- else
- if grayAllowed then
- term.setTextColor(colors.gray)
- else
- term.setTextColor(colors.black)
- end
- end
- end
- write("Scale: ")
- if colormode then
- term.setTextColor(colors.orange)
- else
- if grayAllowed then
- term.setTextColor(colors.lightGray)
- else
- if isConnected then
- term.setTextColor(colors.white)
- else
- term.setTextColor(colors.black)
- end
- end
- end
- if not monitorMode then
- write(table.concat({string.sub(scaleFactor, 1, 12),"x"}))
- else
- write(table.concat({string.sub(scaleFactor, 1, 6),"x"}))
- end
- end
- end
- local function printOutput(commie)
- local oldCurX, oldCurY = term.getCursorPos()
- if type(commie) == "table" then
- for a = 1, #commie do
- term.setCursorPos(2,scr_y-(#commie-a))
- if colormode then
- term.setTextColor(colors.gray)
- term.setBackgroundColor(colors.lightGray)
- else
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- term.clearLine()
- write(tostring(commie[a]))
- end
- else
- setDefaultColors()
- term.setCursorPos(1,scr_y-1)
- term.clearLine()
- term.setCursorPos(2,scr_y)
- if colormode then
- term.setTextColor(colors.gray)
- term.setBackgroundColor(colors.lightGray)
- else
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- term.clearLine()
- write(tostring(commie))
- if turtle then
- if type(turtle.getFuelLevel()) ~= "string" then
- if turtle.getFuelLevel() < 1 then
- write(" (out of fuel)")
- else
- write(" (fuel:" .. turtle.getFuelLevel() .. ")")
- end
- else
- write(" (fuel:" .. turtle.getFuelLevel() .. ")")
- end
- end
- end
- term.setCursorPos(oldCurX,oldCurY)
- setDefaultColors()
- return commie
- end
- local renderMap = function()
- getCoordinates()
- setDefaultColors()
- term.clear()
- drawBorder()
- clearMap()
- redrawMap = true
- renderCommands()
- changedDirection = false
- if turtleMode then printOutput("turtleMode activated!") end
- local poses
- while true do
- if displayStuffs then
- wasConnected = true
- repeat
- poses = getCoordinates()
- if not isConnected then
- if displayStuffs then
- if colormode then
- term.setBackgroundColor(mapColors[8])
- else
- term.setBackgroundColor(colors.white)
- end
- term.clear()
- drawBorder()
- renderCommands()
- end
- repeat
- poses = getCoordinates()
- sleep(0)
- until isConnected
- if displayStuffs then
- setDefaultColors()
- term.clear()
- renderCommands()
- drawBorder()
- end
- end
- until isConnected
- if displayStuffs then
- setDefaultColors()
- end
- end
- oldCoord_x = posX
- oldCoord_y = posY
- oldCoord_z = posZ
- posX = poses[1]
- posY = poses[2]
- posZ = poses[3]
- if oldCoord_x ~= nil then
- if math.abs(oldCoord_x - posX) > directionSensitivity or math.abs(oldCoord_z - posZ) > directionSensitivity and not (turtleMode and changedDirection and turtle) then
- if math.abs(oldCoord_x - posX) > math.abs(oldCoord_z - posZ) and oldCoord_x - posX > 0 then
- direction_long = "east"
- direction = "east"
- changedDirection = true
- elseif math.abs(oldCoord_x - posX) > math.abs(oldCoord_z - posZ) and oldCoord_x - posX < 0 then
- direction_long = "west"
- direction = "west"
- changedDirection = true
- elseif math.abs(oldCoord_z - posZ) > math.abs(oldCoord_x - posX) and oldCoord_z - posZ > 0 then
- direction_lat = "south"
- direction = "south"
- changedDirection = true
- elseif math.abs(oldCoord_z - posZ) > math.abs(oldCoord_x - posX) and oldCoord_z - posZ < 0 then
- direction_lat = "north"
- direction = "north"
- changedDirection = true
- end
- end
- end
- if displayStuffs then
- setDefaultColors()
- if ((oldCoord_x ~= posX or oldCoord_z ~= posZ) or hadCleared) and displayStuffs then
- drawBorder()
- clearMap()
- hadCleared = false
- end
- if oldCoord_x ~= posX or oldCoord_z ~= posZ or oldCoord_y ~= posY or redrawMap == true then
- redrawMap = false
- for a = 1, #waypoints do
- point = waypoints[a]
- wayX = point[2]
- wayY = point[3]
- wayZ = point[4]
- waypointColor = point[5]
- waypointNewchar = point[6]
- oldItemX = itemX
- oldItemZ = itemZ
- itemX = math.floor((midPoint[1] + (posX - math.floor(wayX)) * scaleFactor))
- itemZ = math.floor((midPoint[2] + (posZ - math.floor(wayZ)) * scaleFactor))
- term.setCursorPos(itemX,itemZ)
- if itemX >= corner1[1] and itemX <= corner2[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
- if not (itemX == math.floor(midPoint[1]) and itemZ == math.floor(midPoint[2])) then
- if isConnected then
- if ((itemZ == corner1[2] or itemZ == corner2[2]) or (itemX == corner1[1] or itemX == corner2[1])) and ((itemX >= corner1[1] and itemX <= corner2[1]) and (itemZ >= corner1[2] and itemZ <= corner2[2])) then
- term.setCursorPos(itemX,itemZ)
- if colormode then
- if waypointColor then
- term.setTextColor(waypointColor)
- else
- term.setTextColor(mapColors[3])
- end
- term.setBackgroundColor(mapColors[2])
- else
- if grayAllowed then
- term.setTextColor(colors.gray)
- term.setBackgroundColor(colors.white)
- else
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- end
- else
- if colormode then
- if waypointColor then
- term.setTextColor(waypointColor)
- else
- term.setTextColor(mapColors[3])
- end
- term.setBackgroundColor(mapColors[9])
- else
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- end
- if not waypointNewchar then
- write(waypointChar)
- else
- write(tostring(waypointNewchar))
- end
- else
- if colormode then
- term.setTextColor(mapColors[8])
- else
- term.setTextColor(colors.black)
- end
- end
- end
- else
- if colormode then
- if waypointColor then
- term.setTextColor(waypointColor)
- else
- term.setTextColor(mapColors[4])
- end
- term.setBackgroundColor(mapColors[2])
- else
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- if itemX <= corner1[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
- term.setCursorPos(corner1[1],itemZ)
- write("<")
- elseif itemX <= corner1[1] and itemZ <= corner1[2] then
- term.setCursorPos(corner1[1],corner1[2])
- if (itemX+corner1[1]) * -1 >= (itemZ+corner1[2]) * -1 then
- write("<")
- else
- write("^")
- end
- elseif itemX <= corner1[1] and itemZ >= corner2[2] then
- term.setCursorPos(corner1[1],corner2[2])
- if (itemX+corner1[1]) * -1 >= (itemZ-corner2[2]) then
- write("<")
- else
- write("v")
- end
- elseif itemX >= corner2[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
- term.setCursorPos(corner2[1],itemZ)
- write(">")
- elseif itemX >= corner2[1] and itemZ <= corner1[2] then
- term.setCursorPos(corner2[1],corner1[2])
- if (itemX-corner1[1]) >= (itemZ+corner1[2]) * -1 then
- write(">")
- else
- write("^")
- end
- elseif itemX >= corner2[1] and itemZ >= corner2[2] then
- term.setCursorPos(corner2[1],corner2[2])
- if (itemX-corner2[1]) >= (itemZ-corner2[2]) then
- write(">")
- else
- write("v")
- end
- elseif itemX >= corner1[1] and itemX <= corner2[1] and itemZ <= corner1[2] then
- term.setCursorPos(itemX,corner1[2])
- write("^")
- elseif itemX >= corner1[1] and itemX <= corner2[1] and itemZ >= corner2[2] then
- term.setCursorPos(itemX,corner2[2])
- write("v")
- end
- if colormode then
- term.setTextColor(mapColors[3])
- else
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- end
- setDefaultColors()
- if itemZ < corner2[2] + 2 then
- if labelMode == true then
- pointName = point[1]
- pointMidX = math.ceil(itemX - (#pointName / 2))
- pointMidZ = itemZ - 1
- term.setCursorPos(pointMidX,pointMidZ)
- elseif labelMode == false then
- pointName = tostring(round(math.sqrt((point[2]-posX)^2 + (point[3]-posY)^2 + (point[4]-posZ)^2), 2))
- pointMidX = itemX - math.floor(#pointName / 2)
- pointMidZ = itemZ - 1
- term.setCursorPos(pointMidX,pointMidZ)
- end
- if pointMidX + #pointName >= scr_x then
- subLength = (scr_x - pointMidX) + 1
- subName = string.sub(pointName, 1, subLength)
- if pointMidX <= scr_x + 1 then
- pointName = subName
- end
- end
- if pointMidX <= scr_x then
- for i = 1, #pointName do
- labelPosX, labelPosY = term.getCursorPos()
- term.setCursorPos(labelPosX,labelPosY)
- if ((labelPosY == corner1[2] or labelPosY == corner2[2]) or (labelPosX == corner1[1] or labelPosX == corner2[1])) and ((labelPosX >= corner1[1] and labelPosX <= corner2[1]) and (labelPosY >= corner1[2] and labelPosY <= corner2[2])) then
- if colormode then
- term.setTextColor(mapColors[1])
- term.setBackgroundColor(mapColors[2])
- else
- if grayAllowed then
- term.setTextColor(colors.gray)
- term.setBackgroundColor(colors.white)
- else
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- end
- end
- else
- if colormode then
- term.setBackgroundColor(mapColors[9])
- if wayY >= posY then
- term.setTextColor(mapColors[3])
- else
- term.setTextColor(colors.lightGray)
- end
- else
- if grayAllowed then
- term.setBackgroundColor(colors.black)
- if wayY >= posY then
- term.setTextColor(colors.white)
- else
- term.setTextColor(colors.lightGray)
- end
- else
- if wayY >= posY then
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- else
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- end
- end
- end
- end
- if (labelPosX == 1 or labelPosX == scr_x or labelPosY-1 % corner2[2] == 0) then
- term.setBackgroundColor(mapColors[1])
- end
- write(string.sub(pointName, i, i))
- end
- end
- end
- setDefaultColors()
- end
- end --Do not remove this end.
- term.setCursorPos(midPoint[1],midPoint[2])
- if colormode then
- if recording then
- term.setTextColor(colors.white)
- else
- term.setTextColor(mapColors[5])
- end
- term.setBackgroundColor(mapColors[9])
- else
- if grayAllowed then
- if recording then
- term.setTextColor(colors.black)
- else
- term.setTextColor(colors.lightGray)
- end
- if isConnected then
- term.setBackgroundColor(colors.black)
- else
- term.setBackgroundColor(colors.white)
- end
- else
- if recording then
- term.setTextColor(colors.black)
- else
- term.setTextColor(colors.white)
- end
- if isConnected then
- term.setBackgroundColor(colors.black)
- else
- term.setBackgroundColor(colors.white)
- end
- end
- end
- if not turtleMode then
- if direction == "east" then
- playerChar = ">"
- elseif direction == "west" then
- playerChar = "<"
- elseif direction == "south" then
- playerChar = "v"
- elseif direction == "north" then
- playerChar = "^"
- else
- playerChar = "O"
- end
- else
- if fakeDir == 0 then
- playerChar = "^"
- elseif fakeDir == 1 then
- playerChar = ">"
- elseif fakeDir == 2 then
- playerChar = "v"
- elseif fakeDir == 3 then
- playerChar = "<"
- else
- playerChar = "O"
- end
- end
- write(playerChar)
- end
- if not spoofMode then
- sleep(refreshSleep)
- else
- sleep(0)
- end
- end
- end
- local commands = {
- "(L)abel/dist",
- "Optio(n)s",
- "E(x)it",
- }
- function renderCommands()
- commandXYPoses = {} --Allows me to click on the commands with captureMouseInput()
- if not isConnected and not monitorMode then
- term.setCursorPos(2,1)
- if colormode then
- term.setTextColor(colors.gray)
- else
- term.setTextColor(colors.black)
- end
- gpsNotFoundString = "GPS not found."
- term.clearLine()
- write(gpsNotFoundString)
- end
- startX = 2
- if not monitorMode then
- startY = corner2[2] + 1
- else
- startY = scr_y - 3
- end
- commandX = startX
- commandY = startY + 1
- if displayStuffs then
- term.setCursorPos(commandX,commandY)
- if colormode then
- term.setTextColor(mapColors[6])
- term.setBackgroundColor(mapColors[7])
- else
- term.setTextColor(colors.black)
- if grayAllowed then
- term.setBackgroundColor(colors.lightGray)
- else
- term.setBackgroundColor(colors.white)
- end
- end
- term.clearLine()
- for f = 1, #commands do
- comPosX, comPosY = term.getCursorPos()
- if scr_x - comPosX <= string.len(commands[f]) + 1 then
- term.setCursorPos(startX,comPosY+1)
- term.clearLine()
- comPosX, comPosY = term.getCursorPos()
- end
- write(commands[f])
- table.insert(commandXYPoses, {comPosX, comPosY})
- if not monitorMode then
- if f ~= #commands then
- write(", ")
- end
- else
- if f < 2 then
- write(", ")
- end
- end
- end
- drawScaleIndicator()
- end
- return
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- renderCommands()
- function displayHelp()
- term.setCursorPos(1,2)
- setDefaultColors()
- if colormode then
- term.setTextColor(colors.orange)
- end
- print("GPS Minimap program by EldidiStroyrr.")
- setDefaultColors()
- local helpItems = {
- "'map cc' clears config.",
- "'map cw' clears waypoints.",
- "'map oc' opens config",
- "Do 'map update <main/beta>' to update.",
- "Do 'map help' for help. Duh.",
- "Pressing numpad '+' or '-' will zoom by 0.1",
- }
- local starterX, starterY = term.getCursorPos()
- local yOffset = 0
- for a = 1, #helpItems do
- term.setCursorPos(2,(a-1)+starterY+yOffset)
- if colormode or grayAllowed then
- term.setTextColor(colors.lightGray)
- else
- term.setTextColor(colors.white)
- end
- write("*")
- setDefaultColors()
- local curX1, curY1 = term.getCursorPos()
- print(tostring(helpItems[a]))
- local curX2, curY2 = term.getCursorPos()
- yOffset = yOffset + ((curY2 - curY1) - 1)
- end
- sleep(0.1)
- if colormode or grayAllowed then
- term.setTextColor(colors.lightGray)
- end
- print("")
- print("Press a key to continue.")
- sleep(0)
- local event, key = os.pullEvent("key")
- return
- end
- function doesColorExist(color)
- if type(color) == "string" then
- local colors = set({"white","orange","magneta","lightBlue","yellow","lime","pink","gray","lightGray","cyan","purple","blue","brown","green","red","black"})
- if string.sub(color, 1, 7) == "colors." then
- if colors[string.sub(color, 8)] == true then
- return true
- else
- return false
- end
- else
- if colors[color] == true then
- return true
- else
- return false
- end
- end
- else
- local colors = set({colors.white,colors.orange,colors.magneta,colors.lightBlue,colors.yellow,colors.lime,colors.pink,colors.gray,colors.lightGray,colors.cyan,colors.purple,colors.blue,colors.brown,colors.green,colors.red,colors.black})
- if colors[color] == true then
- return true
- else
- return false
- end
- end
- end
- function setWaypoint()
- term.setCursorPos(1,2)
- setDefaultColors()
- defaultNewPointName = "way" --Not used, in favor of a way to cancel.
- print("Set waypoint.")
- print("Call it what?")
- sleep(0)
- write(">")
- newName = tostring(read())
- if newName == "" then
- print("Cancelling.")
- sleep(0.2)
- return
- end
- print("What X? (default: current xyz)")
- write(">")
- newX = tonumber(read())
- if newX == nil then
- if isConnected then
- newX = posX
- newY = posY
- newZ = posZ
- else
- print("Since you aren't connected to GPS, I can't set waypoints to where you are.")
- yield()
- os.pullEvent("key")
- return
- end
- else
- print("What Y? (default: here)")
- write(">")
- newY = tonumber(read())
- if newY == nil then
- newY = posY
- end
- print("What Z? (default: here)")
- write(">")
- newZ = tonumber(read())
- if newZ == nil then
- newZ = posZ
- end
- end
- print("What color?")
- write(">")
- newColor = tostring(read())
- if not doesColorExist(newColor) then
- print("Not a color. Defaulting to 'yellow'")
- sleep(0.2)
- newColor = nil
- else
- newColor = stringToColor(newColor)
- end
- setConfig(newName, "add", newX, newY, newZ, newColor)
- refreshOtherConfig()
- print("Waypoint '" .. newName .. "' set!")
- getConfig()
- sleep(0.2)
- end
- function setScale()
- term.setCursorPos(1,2)
- setDefaultColors()
- print("Set scale factor. Currently " .. scaleFactor .. ".")
- repeat
- yield()
- newScale = nil
- write(">")
- newScaleRaw = read()
- if tostring(newScaleRaw) == "" then
- print("Cancelling.")
- sleep(0.2)
- return
- end
- newScale = tonumber(newScaleRaw)
- if newScale == nil then
- print("That's not a number!")
- end
- until type(newScale) == "number"
- scaleFactor = newScale
- print("Scale factor set to " .. scaleFactor .. ".")
- refreshOtherConfig()
- getConfig()
- sleep(0.2)
- return true
- end
- function deleteWaypoint()
- term.setCursorPos(1,2)
- setDefaultColors()
- print("Delete what waypoint?")
- if colormode then
- term.setTextColor(colors.orange)
- end
- for a = 1, #waypoints do
- point = waypoints[a]
- print(" -'" .. point[1] .. "'")
- end
- if colormode then
- term.setTextColor(colors.white)
- end
- sleep(0)
- write(">")
- delName = tostring(read())
- for a = 1, #waypoints do
- point = waypoints[a]
- if point[1] == delName then
- setConfig(delName, "delete")
- print("Deleted '" .. delName .. "'.")
- refreshOtherConfig()
- getConfig()
- sleep(0.2)
- return true
- end
- end
- print("Invalid waypoint '" .. delName .. "'!")
- sleep(0.2)
- return false
- end
- function renameWaypoint()
- term.setCursorPos(1,2)
- setDefaultColors()
- print("Rename which waypoint?")
- if colormode then
- term.setTextColor(colors.orange)
- end
- for a = 1, #fileWaypoints do
- point = fileWaypoints[a]
- print(" -'" .. point[1] .. "'")
- end
- if colormode then
- term.setTextColor(colors.white)
- end
- write(">")
- sleep(0)
- local renName = tostring(read())
- print("Rename to what?")
- write(">")
- renOutput = tostring(read())
- for a = 1, #fileWaypoints do
- local point = fileWaypoints[a]
- if point[1] == renName then
- setConfig(renName, "rename", renOutput)
- print("Renamed '" .. renName .. "' to '" .. renOutput .. "'.")
- refreshOtherConfig()
- getConfig()
- sleep(0.2)
- return true
- end
- end
- print("Invalid waypoint '" .. renName .. "'!")
- sleep(0.2)
- return false
- end
- function redrawSceen()
- drawBorder()
- end
- function inspectWaypoint()
- term.clear()
- term.setCursorPos(1,2)
- print("Inspect which waypoint?")
- print("(get x,y,z,etc.):")
- print(string.rep("-",scr_x))
- if colormode then
- term.setTextColor(colors.orange)
- end
- for a = 1, #waypoints do
- point = waypoints[a]
- print(" -'" .. point[1] .. "'")
- end
- if colormode then
- term.setTextColor(colors.white)
- end
- sleep(0)
- write(">")
- local inspName = tostring(read())
- for a = 1, #waypoints do
- local point = waypoints[a]
- if point[1] == inspName then
- term.clear()
- term.setCursorPos(1,2)
- print("Info of '"..inspName.."':")
- print(string.rep("-",scr_x))
- print("X = "..point[2].." (you = "..posX..")")
- print("Y = "..point[3].." (you = "..posY..")")
- print("Z = "..point[4].." (you = "..posZ..")")
- print("Distance = "..math.sqrt((point[2]-posX)^2+(point[3]-posY)^2+(point[4]-posZ)^2))
- if type(point[7]) == "number" and point[7] ~= -1 then
- write("Type = ")
- if point[7] == 1 then
- print("Pocket")
- elseif point[7] == 2 then
- print("Turtle")
- elseif point[7] == 3 then
- print("PC")
- end
- write("\n")
- end
- if point[3] < posY then
- print("It is below you.")
- elseif point[3] > posY then
- print("It is above you.")
- else
- print("Your altitudes are equal.")
- end
- sleep(0.1)
- os.pullEvent("key")
- return true
- end
- end
- print("No such waypoint! Cancelling.")
- sleep(0.3)
- return false
- end
- local function displayTurtleControls()
- term.setCursorPos(1,2)
- print("Turtle Control Scheme:")
- for a = 1, scr_x do write("-") end
- print("")
- print(" Q W E U I O P <up")
- print(" A S D J K L ; <front")
- print(" TAB M , . / <down")
- print("")
- print(" Q = down, E = up")
- print(" WASD = move")
- print(" U J M = hit 7 8 9 red")
- print(" I K , = place 4 5 6 stone")
- print(" O L . = dig 1 2 3 ctrl")
- print(" P ; / = inspect")
- write(" TAB = refuel")
- sleep(0.1)
- os.pullEvent("key")
- return
- end
- function choice(input)
- repeat
- event, key = os.pullEvent("key")
- if type(key) == "number" then key = keys.getName(key) end
- if key == nil then key = " " end
- until string.find(input, key)
- return key
- end
- function waypointSettings()
- displayStuffs = false
- setDefaultColors()
- sleep(0)
- term.setCursorPos(1,2)
- print(" Map Options:")
- term.setCursorPos(1,4)
- if colormode then
- term.setTextColor(colors.orange)
- end
- print(" * (C)reate Waypoint")
- print(" * (D)elete Waypoint")
- print(" * (R)ename Waypoint")
- print(" * Edit C(o)nfig")
- print(" * (S)et Scale")
- print(" * Show (H)elp")
- if turtleMode then print(" * Show (t)urtle controls") end
- if turtleMode then print(" * Send turtle to (p)oint") end
- print(" * (I)nspect waypoint")
- write(" * E(x)it")
- if turtleMode then
- key = choice("cdroshtpix")
- else
- key = choice("cdroshix")
- end
- if key == "d" then
- currentLocation = "deleteWaypoint"
- setDefaultColors() displayStuffs = false
- term.clear()
- sleep(0)
- deleteWaypoint()
- term.clear()
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- redrawSceen()
- return
- end
- if key == "r" then
- currentLocation = "renameWaypoint"
- setDefaultColors()
- term.clear()
- sleep(0)
- renameWaypoint()
- term.clear()
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- redrawSceen()
- return
- end
- if key == "s" then
- currentLocation = "setScale"
- setDefaultColors()
- term.clear()
- sleep(0)
- setScale()
- term.clear()
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- redrawSceen()
- drawScaleIndicator()
- return
- end
- if key == "o" then
- currentLocation = "editConfig"
- setDefaultBackgroundColor()
- term.clear()
- sleep(0.1)
- shell.run("edit " .. mapConfigFile)
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- getConfig()
- setDefaultColors()
- term.clear()
- redrawSceen()
- return
- end
- if key == "c" then
- currentLocation = "setWaypoint"
- setDefaultColors()
- term.clear()
- sleep(0)
- setWaypoint()
- term.clear()
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- redrawSceen()
- end
- if key == "h" then
- currentLocation = "displayHelp"
- setDefaultColors()
- term.clear()
- sleep(0)
- displayHelp()
- term.clear()
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- clearMap()
- drawBorder()
- renderCommands()
- end
- if key == "i" then
- currentLocation = "inspectWaypoint"
- setDefaultColors()
- term.clear()
- sleep(0)
- inspectWaypoint()
- term.clear()
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- clearMap()
- drawBorder()
- renderCommands()
- end
- if key == "t" and turtleMode then
- currentLocation = "displayTurtleControls"
- setDefaultColors()
- term.clear()
- sleep(0)
- displayTurtleControls()
- term.clear()
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- displayStuffs = true
- clearMap()
- drawBorder()
- renderCommands()
- end
- if key == "p" and turtleMode then
- currentLocation = "turtleToPoint"
- setDefaultColors()
- term.clear()
- term.setCursorPos(1,2)
- if isConnected then
- print("Go to coordinates or waypoint?")
- print("[c/w/X]")
- repeat
- sleep(0)
- event, key = os.pullEvent("key")
- if type(key) == "number" then key = keys.getName(key) end
- if key == nil then key = " " end
- until string.find("cwx", key)
- print("")
- local destinationX, destinationY, destinationZ
- if key == "c" then
- print("Enter destination...")
- print("...X:")
- sleep(0)
- destinationX = tonumber(read())
- if destinationX == nil then
- print("Not a number! Cancelling.")
- sleep(0.2)
- flashScreen(1)
- return
- end
- print("...Y:")
- sleep(0)
- destinationY = tonumber(read())
- if destinationY == nil then
- print("Not a number! Cancelling.")
- sleep(0.2)
- flashScreen(1)
- return
- end
- print("...Z:")
- sleep(0)
- destinationZ = tonumber(read())
- if destinationZ == nil then
- print("Not a number! Cancelling.")
- sleep(0.2)
- flashScreen(1)
- return
- end
- term.clear()
- term.setCursorPos(1,2)
- write("Going...")
- local result, bool = printOutput(goToCoordinates(destinationX, destinationY, destinationZ))
- if not bool == false then
- print("done!")
- sleep(0.2)
- else
- sleep(0.1)
- print("Press a key to continue")
- os.pullEvent("key")
- end
- elseif key == "w" then
- print("Which waypoint?")
- if colormode then
- term.setTextColor(colors.orange)
- end
- for a = 1, #waypoints do
- point = waypoints[a]
- print(" -'" .. point[1] .. "'")
- end
- if colormode then
- term.setTextColor(colors.white)
- end
- sleep(0)
- local destWaypoint = tostring(read())
- if destWaypoint == "" then
- print("Cancelling.")
- sleep(0.1)
- flashScreen(1)
- return
- end
- write("Going...")
- printOutput(goToCoordinates(tostring(destWaypoint)))
- print("finished.")
- sleep(0.2)
- end
- else
- print("You are not connected to a GPS server, so you cannot send turtles.")
- print("Press a key to continue")
- sleep(0)
- os.pullEvent("key")
- end
- currentLocation = "renderMap"
- flashScreen(1)
- term.clear()
- sleep(0)
- displayStuffs = true
- clearMap()
- drawBorder()
- renderCommands()
- redrawMap = true
- end
- if key == "x" then
- currentLocation = "renderMap"
- sleep(0)
- flashScreen(1)
- return
- end
- currentLocation = "renderMap"
- return
- end
- function refuelTurtle(amount)
- local originalSlot = turtle.getSelectedSlot()
- for a = 1, 16 do
- turtle.select(a)
- if turtle.refuel(0) then
- turtle.refuel(amount)
- turtle.select(originalSlot)
- return "refuelled " .. amount
- end
- end
- turtle.select(originalSlot)
- return "can't refuel " .. amount
- end
- function goToCoordinates(destX, destY, destZ)
- if not turtleMode then
- return "turtleMode is not true"
- end
- if destY == nil then
- local pointName = destX
- for a = 1, #waypoints do
- point = waypoints[a]
- if point[1] == pointName then
- destX = tonumber(point[2])
- destY = tonumber(point[3])
- destZ = tonumber(point[4])
- end
- end
- if destY == nil then
- return "no such waypoint"
- end
- if turtle then
- if type(turtle.getFuelLevel()) == "number" then
- if math.abs(destX-posX)+math.abs(destY-posY)+math.abs(destZ-posZ) > turtle.getFuelLevel() then
- return "insufficient fuel", false
- end
- end
- printOutput("going to waypoint '" .. pointName .. "'")
- end
- else
- if turtle then
- if type(turtle.getFuelLevel()) == "number" then
- if math.abs(destX-posX)+math.abs(destY-posY)+math.abs(destZ-posZ) > turtle.getFuelLevel() then
- return "insufficient fuel", false
- end
- end
- printOutput("going to " .. destX .. "," .. destY .. "," .. destZ .. "...")
- end
- end
- --Credit to PhyscoKillerMonkey for the goto script.
- gox = tonumber(destX)
- goy = tonumber(destY)
- goz = tonumber(destZ)
- digBlocks = true
- goneUp = 0 --dir and goneUp are used to keep track of position
- dir = 0
- getPos()
- getDir()
- if goy > cy then
- moveY()
- moveX()
- moveZ()
- else
- moveX()
- moveZ()
- moveY()
- end
- --End of script by PhyscoKillerMonkey.
- return "went to coordinates " .. destX .. "," .. destY .. "," .. destZ .. "."
- end
- local function turtleTurnLeft()
- if direction == "north" then direction = "west"
- elseif direction == "west" then direction = "south"
- elseif direction == "south" then direction = "east"
- elseif direction == "east" then direction = "north" end
- printOutput(mapturt.turnLeft())
- end
- local function turtleTurnRight()
- if direction == "north" then direction = "east"
- elseif direction == "east" then direction = "south"
- elseif direction == "south" then direction = "west"
- elseif direction == "west" then direction = "north" end
- printOutput(mapturt.turnRight())
- end
- local function textingPrompt()
- term.setCursorPos(1,1)
- term.clearLine()
- write(">")
- sleep(0)
- local message = read()
- if message == "" then
- return false
- else
- local modem = peripheral.find("modem")
- if not modem then
- return false
- end
- local msg = {networkName,message}
- for a = 1, #mapProtocol do
- modem.transmit(mapProtocol[a],mapProtocol[a],msg)
- end
- return true
- end
- end
- local function keyPress() --Captures keypresses when normally viewing the map.
- recording = false
- displayStuffs = true
- while true do
- currentLocation = "renderMap"
- local event, key = os.pullEvent("key")
- if type(key) == "number" then key = tostring(keys.getName(key)) end
- if spoofMode and not turtleMode then
- if key == "left" then
- fakeX = fakeX + spoofStep
- refreshOtherConfig()
- sleep(0)
- end
- if key == "right" then
- fakeX = fakeX - spoofStep
- refreshOtherConfig()
- sleep(0)
- end
- if key == "down" then
- fakeZ = fakeZ - spoofStep
- refreshOtherConfig()
- sleep(0)
- end
- if key == "up" then
- fakeZ = fakeZ + spoofStep
- refreshOtherConfig()
- sleep(0)
- end
- end
- if currentlyConnected or (currentlyConnected == false and isConnected == false) then
- if key == "space" then
- recording = not recording
- end
- if key == "l" then
- if labelMode == true then
- labelMode = false
- elseif labelMode == false then
- labelMode = true
- end
- refreshOtherConfig()
- drawBorder()
- clearMap()
- redrawMap = true
- end
- if key == "t" then
- currentLocation = "textingPrompt"
- displayStuffs = false
- setDefaultColors()
- textingPrompt()
- sleep(0)
- displayStuffs = true
- clearMap()
- drawBorder()
- renderCommands()
- redrawMap = true
- end
- if key == "n" then
- currentLocation = "waypointSettings"
- displayStuffs = false
- setDefaultColors()
- term.clear()
- sleep(0)
- os.queueEvent("gpsRequest") --To make sure the line animation in the settings works.
- waypointSettings()
- currentLocation = "renderMap"
- term.clear()
- sleep(0)
- displayStuffs = true
- clearMap()
- drawBorder()
- renderCommands()
- redrawMap = true
- if turtleMode then printOutput("turtleMode activated!") end
- end
- if key == "numPadAdd" or key == "add" then
- scaleFactor = scaleFactor + 0.01
- refreshOtherConfig()
- clearMap()
- drawBorder()
- drawScaleIndicator()
- redrawMap = true
- elseif (key == "minus" or key == "numPadSubtract") and scaleFactor > 0.01 then
- scaleFactor = scaleFactor - 0.01
- refreshOtherConfig()
- clearMap()
- drawBorder()
- drawScaleIndicator()
- redrawMap = true
- end
- if turtleMode then --Used for turtle control, and is helpful with Lyqyd's NSH.
- if turtle then
- if key == "w" then printOutput(mapturt.forward()) end
- if key == "s" then printOutput(mapturt.back()) end
- if key == "a" then
- if keyAgoesRight then
- turtleTurnRight()
- else
- turtleTurnLeft()
- end
- end
- if key == "d" then
- if keyAgoesRight then
- turtleTurnLeft()
- else
- turtleTurnRight()
- end
- end
- if key == "q" then printOutput(mapturt.down()) end
- if key == "e" then printOutput(mapturt.up()) end
- if key == "i" then printOutput(turtle.placeUp()) end
- if key == "k" then printOutput(turtle.place()) end
- if key == "comma" then printOutput(turtle.placeDown()) end
- if key == "o" then printOutput(turtle.digUp()) end
- if key == "l" then printOutput(turtle.dig()) end
- if key == "period" then printOutput(turtle.digDown()) end
- if key == "p" then
- bool, inspection = turtle.inspectUp()
- inspection = {inspection["name"], inspection["metadata"]}
- printOutput(inspection)
- end
- if key == "semiColon" then
- bool, inspection = turtle.inspect()
- inspection = {inspection["name"], inspection["metadata"]}
- printOutput(inspection)
- end
- if key == "slash" then
- bool, inspection = turtle.inspectDown()
- inspection = {inspection["name"], inspection["metadata"]}
- printOutput(inspection)
- end
- if key == "u" then printOutput(turtle.attackUp()) end
- if key == "j" then printOutput(turtle.attack()) end
- if key == "m" then printOutput(turtle.attackDown()) end
- if key == "tab" then printOutput(refuelTurtle(1)) end
- if key == "numPad8" then
- local rsSide = "front"
- if redstone.getOutput(rsSide) == false then
- redstone.setOutput(rsSide, true)
- printOutput(rsSide .. " RS on")
- else
- redstone.setOutput(rsSide, false)
- printOutput(rsSide .. " RS off")
- end
- end
- if key == "numPad2" then
- local rsSide = "back"
- if redstone.getOutput(rsSide) == false then
- redstone.setOutput(rsSide, true)
- printOutput(rsSide .. " RS on")
- else
- redstone.setOutput(rsSide, false)
- printOutput(rsSide .. " RS off")
- end
- end
- if key == "numPad4" then
- local rsSide = "left"
- if redstone.getOutput(rsSide) == false then
- redstone.setOutput(rsSide, true)
- printOutput(rsSide .. " RS on")
- else
- redstone.setOutput(rsSide, false)
- printOutput(rsSide .. " RS off")
- end
- end
- if key == "numPad6" then
- local rsSide = "right"
- if redstone.getOutput(rsSide) == false then
- redstone.setOutput(rsSide, true)
- printOutput(rsSide .. " RS on")
- else
- redstone.setOutput(rsSide, false)
- printOutput(rsSide .. " RS off")
- end
- end
- if key == "numPad7" then
- local rsSide = "top"
- if redstone.getOutput(rsSide) == false then
- redstone.setOutput(rsSide, true)
- printOutput(rsSide .. " RS on")
- else
- redstone.setOutput(rsSide, false)
- printOutput(rsSide .. " RS off")
- end
- end
- if key == "numPad9" then
- local rsSide = "bottom"
- if redstone.getOutput(rsSide) == false then
- redstone.setOutput(rsSide, true)
- printOutput(rsSide .. " RS on")
- else
- redstone.setOutput(rsSide, false)
- printOutput(rsSide .. " RS off")
- end
- end
- else
- printOutput("Not a turtle.")
- end
- end
- end
- if key == "x" then
- yield()
- return
- end
- end
- end
- local function captureMouseInput()
- while true do
- event, param1, x, y = os.pullEvent()
- if currentLocation == "renderMap" then --Very important.
- if event == "mouse_scroll" and y == scaleY and (x >= scaleX and x <= (7+scaleX+#string.sub(scaleFactor, 1, 12))) then
- if param1 == -1 then
- scaleFactor = scaleFactor + 0.01
- elseif param1 == 1 then
- if scaleFactor > 0.01 then
- scaleFactor = scaleFactor - 0.01
- else
- scaleFactor = 0.01
- end
- end
- refreshOtherConfig()
- clearMap()
- drawBorder()
- drawScaleIndicator()
- redrawMap = true
- elseif (event == "mouse_click" and param1 == 1) or (event == "monitor_touch") then
- for a = 1, #commands do
- if y == commandXYPoses[a][2] and (x >= commandXYPoses[a][1] and x <= (#commands[a]+commandXYPoses[a][1])) then
- commandID = a
- break
- end
- end
- --I know the key event is supposed to return a number...
- if commandID == 1 then os.queueEvent("key", "l") end
- if commandID == 2 then os.queueEvent("key", "n") end
- if commandID == 3 then os.queueEvent("key", "x") end
- commandID = nil
- end
- elseif (currentLocation == "waypointSettings" and ((event == "mouse_click" and param1 == 1)) or (event == "monitor_touch")) then
- if y == 4 then os.queueEvent("key", "c") end -- Create waypoint
- if y == 5 then os.queueEvent("key", "d") end -- Delete waypoint
- if y == 6 then os.queueEvent("key", "r") end -- Rename waypoint
- if y == 7 then os.queueEvent("key", "o") end -- Edit config
- if y == 8 then os.queueEvent("key", "s") end -- Set scale
- if y == 9 then os.queueEvent("key", "h") end -- Show help
- if turtleMode then
- if y == 10 then os.queueEvent("key", "t") end -- Turtle controls
- if y == 11 then os.queueEvent("key", "p") end -- Send turtle to point
- if y == 12 then os.queueEvent("key", "i") end -- Inspect waypoint
- if y == 13 then os.queueEvent("key", "x") end -- Exit
- else
- if y == 10 then os.queueEvent("key", "i") end -- Inspect waypoint
- if y == 11 then os.queueEvent("key", "x") end -- Exit
- end
- end
- end
- end
- local function drawAnimations()
- local spinwheel = {"/","-","\\","|"}
- while true do
- if currentLocation == "waypointSettings" then
- sleep(0.1)
- repeat
- term.setTextColor(colors.white)
- drawMovingLine(3, 12, 0, 2)
- until currentLocation ~= "waypointSettings"
- end
- if currentLocation == "renderMap" then
- for a = 1, #spinwheel do
- if currentLocation ~= "renderMap" then break end
- event, status = os.pullEvent("gpsRequest")
- if currentLocation == "renderMap" then
- if colormode then
- if turtleMode then term.setBackgroundColor(colors.lightGray) end
- if status == true then
- term.setTextColor(colors.green)
- else
- term.setTextColor(colors.orange)
- end
- else
- if grayAllowed then
- if turtleMode then term.setBackgroundColor(colors.lightGray) end
- if status == true then
- term.setTextColor(colors.lightGray)
- else
- term.setTextColor(colors.gray)
- end
- else
- if status == true then
- term.setTextColor(colors.black)
- else
- term.setTextColor(colors.white)
- end
- end
- end
- term.setCursorPos(scr_x,1)
- setDefaultBackgroundColor()
- write(spinwheel[a])
- if currentlyConnected then
- term.setCursorPos(1,1)
- term.setTextColor(colors.white)
- write("X="..math.floor(posX).." Y="..math.floor(posY).." Z="..math.floor(posZ))
- end
- else
- break
- end
- end
- end
- sleep(0)
- end
- end
- local function waitForResize()
- while true do
- scr_x, scr_y = term.getSize()
- event = os.pullEvent()
- if event == "monitor_resize" or event == "term_resize" and displayStuffs == true then
- scr_x, scr_y = term.getSize()
- if scr_x > 16 or scr_y > 10 then --Determines if Map is being ran on a single monitor block.
- monitorMode = false
- else
- monitorMode = true
- end
- mon = peripheral.find("monitor")
- if mon then
- if monitorTextScale ~= 0.5 then
- mon.setTextScale(0.5)
- else
- mon.setTextScale(1)
- end
- if not monitorMode then
- mon.setTextScale(monitorTextScale)
- else
- mon.setTextScale(0.5)
- end
- end
- setDefaultColors()
- term.clear()
- defineMapBorders()
- drawBorder()
- clearMap()
- renderCommands()
- redrawMap = true
- end
- end
- end
- local function broadcastMapData()
- local compType
- if pocket then
- compType = 1
- elseif turtle then
- compType = 2
- else
- compType = 3
- end
- while true do
- if broadcastData then
- local data = {
- name = networkName,
- x = posX,
- y = posY,
- z = posZ,
- isFake = spoofMode,
- comp = compType,
- ver = mapVersion,
- dirChar = playerChar,
- }
- local modem = peripheral.find("modem")
- if modem then
- for a = 1, #mapProtocol do
- modem.open(mapProtocol[a])
- modem.transmit(mapProtocol[a],mapProtocol[a],data)
- end
- end
- end
- sleep(0)
- end
- end
- local function _rawListenForMapData() --Thanks, Bomb Bloke!
- otherWaypoints = {}
- while true do
- local scr_x, scr_y = term.getSize()
- local modem = peripheral.find("modem")
- if modem then
- for a = 1, #mapProtocol do
- modem.open(mapProtocol[a])
- end
- end
- local event, side, sendChan, repChan, data, distance = os.pullEvent("modem_message")
- if (type(data) == "table") then
- if (type(data.x) == "number") and (type(data.y) == "number") and (type(data.z) == "number") and (type(data.name) == "string") and (type(data.dirChar) == "string") then
- otherWaypoints[data.name] = {data.x,data.y,data.z,colors.red,data.dirChar}
- if data.comp then
- table.insert(otherWaypoints[data.name],data.comp)
- else
- table.insert(otherWaypoints[data.name],-1)
- end
- elseif #data == 2 then
- if (type(data[1]) == "string") and (type(data[2]) == "string") then
- finalMessage = string.sub("<"..data[1].."> "..data[2],1,(scr_x*2)-1)
- printOutput(finalMessage)
- end
- end
- end
- end
- end
- local function listenForMapData()
- netWayPoints = {}
- while true do
- parallel.waitForAny(function() sleep(0.3) end, _rawListenForMapData)
- local seppoint = seperateMethods(otherWaypoints)
- local oldNetWayPoints = newWayPoints
- netWayPoints = {}
- for a = 1, #seppoint do
- table.insert(netWayPoints,{seppoint[a][1],table.unpack(seppoint[a][2])})
- end
- local file = fs.open(mapNetworkWaypointsFile,"w")
- file.write(textutils.serialize(netWayPoints))
- file.close()
- getConfig()
- if (oldNetWayPoints ~= netWayPoints) and displayStuffs then
- hadCleared = true
- redrawMap = true
- end
- end
- end
- getConfig()
- local mon = peripheral.find("monitor")
- if mon then
- if not monitorMode then
- mon.setTextScale(monitorTextScale)
- else
- mon.setTextScale(0.5)
- end
- end
- if spoofMode then --Used if spoofMode == true, if not then these are set in the event that it is later set true.
- if not fakeDir then
- print("Spoof mode is activated.")
- print("Enter current X:")
- repeat
- fakeX = tonumber(read())
- until fakeX
- print("Enter current Y:")
- repeat
- fakeY = tonumber(read())
- until fakeY
- print("Enter current Z:")
- repeat
- fakeZ = tonumber(read())
- until fakeZ
- print("Enter direction ('f' in F3 mode):")
- repeat
- fakeDir = tonumber(read())
- until fakeDir
- refreshOtherConfig()
- end
- else
- fakeX = 0
- fakeY = 66
- fakeZ = 0
- fakeDir = 0 --Look at variable 'f' in DEBUG mode in minecraft. (F3)
- end
- mapturt = { -- I redefine the turtle moving functions to simplify things.
- ["forward"] = function() turtle.forward() fakeX=fakeX-(math.sin(90*fakeDir)) fakeZ=fakeZ+(math.cos(90*fakeDir)) refreshOtherConfig() end,
- ["back"] = function() turtle.back() fakeX=fakeX+(math.sin(90*fakeDir)) fakeZ=fakeZ-(math.cos(90*fakeDir)) refreshOtherConfig() end,
- ["up"] = function() turtle.up() fakeY=fakeY+1 refreshOtherConfig() end,
- ["down"] = function() turtle.down() fakeY=fakeY-1 refreshOtherConfig() end,
- ["turnLeft"] = function() turtle.turnLeft() fakeDir=rollOver(fakeDir-1,4) refreshOtherConfig() end,
- ["turnRight"] = function() turtle.turnRight() fakeDir=rollOver(fakeDir+1,4) refreshOtherConfig() end,
- }
- --[[The following...huge...tables are the title screens for advanced, grayscale, and monochrome computers.
- In order to edit these, you need to somehow convert it back to the default paint format, then use oeed's Sketch--]]--why do I have a function for this again...? For the screen resizing!
- if displayTitle then
- displayTitleScreen() --New title screens for norm/adv/gray computers in 1.3.4!
- end
- if autoUpdate then
- write("Automagically updating Map...") --Yes I know I misspelled that, that was on purpose.
- updateMapProgram()
- print("up to date!")
- end
- flashScreen(1)
- local parallelFunctions = { --Look, I wanted to simplify it...
- renderMap,
- keyPress,
- captureMouseInput,
- waitForResize,
- drawAnimations,
- listenForMapData,
- broadcastMapData,
- }
- parallel.waitForAny(table.unpack(parallelFunctions))
- end --This end is to close the runMapProgramAlready() function, so don't remove it.
- function handleMapErrorMessage(errorMsg)
- local errorMessage = errorMsg
- local interjects = {
- "Oh nose!",
- "Golly gee!",
- "Eh, shit.",
- "Holy Spaghetti and Meatballs, Batman!",
- "Holy Rusted Metal, Batman!",
- "Jiminy!",
- "Leaping leptons!",
- "Cripes!",
- "Khaaaaaaannnnn!!",
- "GURU MEDITATION",
- "It appears that",
- "Exclamation!",
- "Holy Hamburger, Batman!",
- "Holy Priceless Collection of Etruscan Snoods, Batman!",
- "Holy Uncanny Photographic Mental Processes, Batman!",
- "Aw shucks!",
- "Holy Contributing to the Delinquency of Minors, Batman!",
- "Holy Remote Control Robot, Batman!",
- "Holy Euphemism!",
- "Holy Hardest Metal In The World, Batman!",
- "Holy Astringent Plum-like Fruit, Batman!",
- "Holy Greetings Cards, Batman!",
- "Holy One Track Bat Computer Mind, Batman!",
- "Sweet Zombie Jesus!",
- "Holy Batshit, Robin!",
- "Holy Mongolian Clusterfuck!",
- "Holy jumping mother o'God in a side-car with chocolate jimmies and a lobster bib!",
- "string.rep(\"NEIN \",1000)",
- "Oh, how sad.",
- "NYEH HEH HEH!!!!", --This error message fills you with DETERMINATION.
- "One of us messed up.",
- "Holy balls!",
- "ASS!",
- "You piece of shit!",
- "Damn it, Jim!",
- "Ohhh nooo...",
- "Funny splash text!",
- }
- if colormode then
- table.insert(interjects,"It's so red!")
- else
- if grayAllowed then
- table.insert(interjects,"It's so gray!")
- else
- table.insert(interjects,"It's so white!")
- end
- end
- local interjection = interjects[math.random(1, #interjects)]
- local message = {
- interjection,
- "Map v" .. mapVersion .. " has gotten",
- "an error:",
- "",
- tostring(errorMessage),
- }
- if colormode then
- term.setBackgroundColor(colors.red)
- else
- if grayAllowed then
- term.setBackgroundColor(colors.gray)
- else
- term.setBackgroundColor(colors.white)
- end
- end
- term.clear()
- scr_x, scr_y = term.getSize()
- term.setCursorPos(1,1)
- for y = 1, 2 do
- for x = 1, scr_x do
- if x % 2 == 0 then
- if colormode then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightGray)
- else
- if grayAllowed then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightGray)
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- end
- write("x")
- else
- if colormode then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.orange)
- else
- if grayAllowed then
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.gray)
- else
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- end
- end
- write("X")
- end
- end
- term.setCursorPos(1,scr_y)
- end
- midPoint = {
- scr_x / 2,
- scr_y / 2,
- }
- local yoffset = 0
- for a = 1, #message do
- term.setCursorPos(midPoint[1]-math.floor(#message[a]/2)+1,a+3+yoffset)
- if a == 5 then
- if colormode then
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.white)
- else
- if grayAllowed then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- end
- end
- else
- if colormode then
- term.setBackgroundColor(colors.red)
- term.setTextColor(colors.white)
- else
- if grayAllowed then
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- else
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- end
- end
- end
- if #message[a] > scr_x then
- for b = 1, math.ceil(#message[a]/scr_x) do
- local curPosX, curPosY = term.getCursorPos()
- local subString = string.sub(message[a],((b-1)*scr_x)+1,(b*scr_x))
- if #subString < scr_x then
- term.setCursorPos(midPoint[1]-math.ceil(#string.sub(message[a], scr_x)/2),a+2+yoffset)
- else
- term.setCursorPos(1,a+2+yoffset+(b-1))
- end
- print(subString)
- if b ~= math.ceil(#message[a]/scr_x) then
- yoffset = yoffset + 1
- end
- end
- else
- print(message[a])
- end
- end
- if colormode then
- term.setBackgroundColor(colors.yellow)
- term.setTextColor(colors.black)
- else
- if grayAllowed then
- term.setBackgroundColor(colors.lightGray)
- term.setTextColor(colors.black)
- else
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- end
- end
- local msg = " E(x)it, or (R)estart? "
- term.setCursorPos(math.ceil(midPoint[1]-(#msg/2)),scr_y-2)
- print(msg)
- local event, key
- repeat
- sleep(0.1) --To prevent premature keypresses.
- event, key = os.pullEvent("char") --We don't need any key output other than letters.
- key = string.lower(key) --In case shift+key returns a capital key.
- until string.find("xr", key)
- local message = nil
- if key == "x" then
- return false
- elseif key == "r" then
- return true
- else
- return false
- end
- error("How did you get here??")
- end
- if nothing then return end
- while true do
- local status, error = pcall(runMapProgramAlready) --Finally, good error handling.
- if status == false then
- local outcome = handleMapErrorMessage(error)
- if outcome == false then
- break
- end
- else
- break
- end
- end
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- print("Thanks for using Map v" .. mapVersion .. "!")
- print("(code: " .. pastebinIDList[mapRelease] .. ")")
- if math.random(1,64)==64 then print("May you live in interesting times!") end
- sleep(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement