Advertisement
LDDestroier

GPS Minimap 1.3.9

Jun 5th, 2015
2,409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 87.83 KB | None | 0 0
  1. --[[
  2.    'Map' (GPS Minimap) by EldidiStroyrr (LDDestroier)
  3.  
  4.     Get with
  5.    pastebin get x9ajKSc0 map
  6.      or
  7.     std pb x9ajKSc0 map
  8.     std ld map map
  9.  
  10.     This is a stable release. You fool!
  11. --]]
  12.  
  13. local mapRelease = "main"
  14. local pastebinIDList = {
  15.     main = "x9ajKSc0",
  16.     beta = "KJ4t2DM9",
  17. }
  18. mapVersion = "1.3.9" --Version of Map. Must be string.
  19. os.pullEvent = os.pullEventRaw
  20. local scr_x, scr_y = term.getSize()
  21. local parentDir = fs.combine("",fs.getDir(shell.getRunningProgram()))
  22. local configDir = fs.combine(parentDir,".map")
  23. if fs.isReadOnly(configDir) then
  24.     configDir = ".map"
  25. end
  26. if not fs.isDir(configDir) then
  27.     if fs.exists(configDir) then fs.delete(configDir) end
  28.     fs.makeDir(configDir)
  29. end
  30. if fs.isReadOnly(shell.resolve(shell.getRunningProgram())) then --In case Map is located in a write-protected directory.
  31.     waypointDir = fs.combine(fs.getName(configDir),"waypoints")
  32.     mapConfigFile = fs.combine(fs.getName(configDir),"config")
  33.     pathDir = fs.combine(fs.getName(configDir),"paths")
  34. else
  35.     waypointDir = "/" .. fs.combine(configDir, "waypoints")
  36.     mapConfigFile = "/" .. fs.combine(configDir, "config")
  37.     pathDir = fs.combine(configDir,"paths")
  38. end
  39. if not fs.exists(waypointDir) then fs.makeDir(waypointDir) end
  40. if not fs.exists(pathDir) then fs.makeDir(pathDir) end
  41. defaultWaypointFile = "waypoints" --The name of the waypoint file that is written to.
  42. mapNetworkWaypointsFile = fs.combine(waypointDir,"networkPoints")
  43. local mapName
  44. local function updateMapProgram(url)
  45.     if not fs.isReadOnly(shell.resolve(shell.getRunningProgram())) then
  46.         mapName = fs.combine("",shell.getRunningProgram())
  47.     else
  48.         mapName = shell.getRunningProgram()
  49.     end
  50.     local updateFile
  51.     if url then
  52.         updateFile = http.get(url)
  53.     else
  54.         updateFile = http.get("http://pastebin.com/raw.php?i=" .. pastebinIDList[mapRelease])
  55.     end
  56.     if updateFile then
  57.         updateFile = updateFile.readAll()
  58.     else
  59.         error("Could not connect.")
  60.     end
  61.     local file = fs.open(mapName, "w")
  62.     file.write(updateFile)
  63.     file.close()
  64.     return fs.getSize(mapName)
  65. end
  66.  
  67. local function setColormode()
  68.     if term.isColor() and colorLimit >= 2 then
  69.         colormode = true
  70.         grayAllowed = true
  71.     else
  72.         colormode = false
  73.         if _VERSION and colorLimit >= 1 then
  74.             grayAllowed = true
  75.         else
  76.             grayAllowed = false
  77.         end
  78.     end
  79. end
  80.  
  81. local nothing = false
  82. local tArg = {...}
  83. if tArg[1] ~= nil then
  84.     if tArg[1] == "cc" then
  85.         if fs.exists(mapConfigFile) then
  86.             fs.delete(mapConfigFile)
  87.             print("Config cleared.")
  88.         else
  89.             print("No config to clear.")
  90.         end
  91.         fakeX = nil
  92.         fakeY = nil
  93.         fakeZ = nil
  94.         fakeDir = nil
  95.         return
  96.     elseif tArg[1] == "cw" then
  97.         if fs.exists(waypointDir) then
  98.             fs.delete(waypointDir)
  99.             print("Waypoints cleared.")
  100.         else
  101.             print("No waypoints to clear.")
  102.         end
  103.         return
  104.     elseif tArg[1] == "oc" then
  105.         shell.run("edit "..mapConfigFile)
  106.         print("Config updated.")
  107.         return
  108.     elseif tArg[1] == "nothing" then
  109.         nothing = true
  110.     elseif tArg[1] == "update" then
  111.         local file = tArg[2]
  112.         local updateURL
  113.         if not tArg[2] then
  114.             updateURL = pastebinIDList[mapRelease]
  115.         else
  116.             if pastebinIDList[file] then
  117.                 updateURL = pastebinIDList[file]
  118.             else
  119.                 print("Invalid update source.")
  120.                 return false
  121.             end
  122.         end
  123.         write("Updating " .. shell.getRunningProgram() .. "...")
  124.         local mapName = shell.getRunningProgram()
  125.         local fileSize = updateMapProgram("http://pastebin.com/raw.php?i=" .. updateURL)
  126.         print("done (got " .. fs.getSize(mapName) .. " bytes)")
  127.         write("Updated from "..mapVersion)
  128.         shell.run(fs.getName(shell.getRunningProgram()),"nothing")
  129.         if mapVersion then
  130.             print(" to "..mapVersion)
  131.         else
  132.             print("...whatever.")
  133.         end
  134.         return true
  135.     elseif tArg[1] == "help" then
  136.         local helpText = [[
  137. 'map update' Updates program.
  138. 'map fast' Runs term.redirect(term.native()).
  139. 'map cw' Deletes waypoints.
  140. 'map cc' Deletes config.
  141. 'map oc' Opens config.
  142. 'map nothing' gets config, but doesn't run
  143. Config path: ']]..mapConfigFile..[['
  144. Waypoint directory: ']]..waypointDir..[[']]
  145.         print(helpText)
  146.         return true
  147.     elseif tArg[1] == "fast" then
  148.         term.redirect(term.native())
  149.     end
  150. end
  151. local function runMapProgramAlready() --This is to allow me to run pcall on the program.
  152. function numberToColor(input)
  153.     if type(input) == "number" then
  154.         for k,v in pairs(colors) do
  155.             if input == v then
  156.                 return "colors."..k
  157.             end
  158.         end
  159.     elseif type(input) == "table" then
  160.         local output = {}
  161.         for a = 1, #input do
  162.             for k,v in pairs(colors) do
  163.                 if input[a] == v then
  164.                     table.insert(output,"colors."..k)
  165.                 end
  166.             end
  167.         end
  168.         return output
  169.     end
  170.     return false
  171. end
  172. local function yield()
  173.     os.queueEvent("yield")
  174.     os.pullEvent("yield")
  175. end
  176. local function seperateMethods(input)
  177.     local output={}
  178.     for key,value in pairs(input) do
  179.         table.insert(output, {key,value})
  180.     end
  181.     return output
  182. end
  183. local function defineMapBorders()
  184.     local mapCorners
  185.     if not monitorMode then
  186.         mapCorners = { --Top left corner, bottom right corner
  187.             {
  188.                 2,
  189.                 2,
  190.             },
  191.             {
  192.                 scr_x - 1,
  193.                 scr_y - 6,
  194.             }
  195.         }
  196.     else
  197.         mapCorners = {
  198.             {
  199.                 1,
  200.                 1,
  201.             },
  202.             {
  203.                 scr_x,
  204.                 scr_y - 3,
  205.             }
  206.         }
  207.     end
  208.     corner1 = mapCorners[1]
  209.     corner2 = mapCorners[2]
  210.     midPoint = {
  211.         math.floor((corner1[1] + corner2[1]) / 2),
  212.         math.floor((corner1[2] + corner2[2]) / 2)
  213.     }
  214.     mapDimensions = {
  215.         corner2[1] - corner1[1],
  216.         corner2[2] - corner1[2]
  217.     }
  218. end
  219. defineMapBorders()
  220. --[[ In case adding this to the config messes something up, I want to easily fix it.
  221.     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.
  222.         colors.gray,      --Background color (default: colors.gray)
  223.         colors.white,     --Border color (default: colors.white)
  224.         colors.yellow,    --Waypoint color (default: colors.yellow)
  225.         colors.red,       --Offscreen waypoint arrow color (default: colors.red)
  226.         colors.lightBlue, --Direction indicator color (default: colors.lightBlue)
  227.         colors.black,     --Command list text color (default: colors.black)
  228.         colors.lightGray, --Command list background color (default: colors.lightGray)
  229.         colors.red,       --Background color if not connected to GPS server (default: colors.red)
  230.         colors.black,     --Map background color (default: colors.black)
  231.     }
  232.    
  233.     directionSensitivity = 0.15 --This is used to prevent the arrow on the middle of the screen from going crazy.
  234. --]]
  235. displayStuffs = true
  236. currentlyConnected = false --We don't know, so assume false because of glitch with numpad
  237. isConnected = false --We still don't know, and it's just safer to assume false because of visual bugs
  238. arrows = {
  239.     ">",
  240.     "v",
  241.     "<",
  242.     "^"
  243. }
  244. 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.
  245. playerChar = youChar
  246. function displayTitleScreen()
  247.     term.clear()
  248.     term.setCursorPos(1,1)
  249.     if colormode then
  250.         paintutils.drawImage(mapTitleScreen_adv, 1, 1)
  251.     else
  252.         if grayAllowed then
  253.             paintutils.drawImage(mapTitleScreen_gray, 1, 1)
  254.         else
  255.             paintutils.drawImage(mapTitleScreen_norm, 1, 1)
  256.         end
  257.     end
  258.     if colormode then
  259.         term.setTextColor(colors.black)
  260.         term.setBackgroundColor(colors.lightBlue)
  261.     else
  262.         if grayAllowed then
  263.             term.setTextColor(colors.black)
  264.             term.setBackgroundColor(colors.white)
  265.         else
  266.             term.setTextColor(colors.black)
  267.             term.setBackgroundColor(colors.white)
  268.         end
  269.     end
  270.     term.setCursorPos(5,4)
  271.     print("Version " .. mapVersion)
  272.     term.setCursorPos(5,3)
  273.     print("Made by EldidiStroyrr")
  274.     sleep(0.1)
  275.     repeat
  276.         event, param1 = os.pullEvent()
  277.     until event == "key" or event == "mouse_click" or event == "monitor_touch"
  278. end
  279. function refreshOtherConfig()
  280.     local file = fs.open(mapConfigFile, "w")
  281.     local mapSettings = {
  282.         {
  283.             "spoofMode = " .. tostring(spoofMode),
  284.             "boolean, set true if testing program in emulator. Replaces gps movement detection with arrow keys. Default: false",
  285.         },
  286.         {
  287.             "broadcastData = " .. tostring(broadcastData),
  288.             "boolean, set true if you want other people to see your location. Default: true",
  289.         },
  290.         {
  291.             "networkName = '" .. tostring(networkName) .. "'",
  292.             "string, what your name appears as for other Map clients. Default: 'mapuser'..math.random(1,9999)",
  293.         },
  294.         {
  295.             "mapProtocol = " .. textutils.serialize(mapProtocol),
  296.             "table, list of modem protocols of the data broadcasted to other clients. Default: {10666}",
  297.         },
  298.         {
  299.             "scaleFactor = " .. tostring(scaleFactor),
  300.             "number, the zoom factor for the minimap. Lower means wider range. Does not affect GPS range. Default: 0.25",
  301.         },
  302.         {
  303.             "displayTitle = " .. tostring(displayTitle),
  304.             "boolean, whether or not to display the title screen. I find it kind of garish, but I already did the work. Default: false",
  305.         },
  306.         {
  307.             "labelMode = " .. tostring(labelMode),
  308.             "boolean, true if waypoint labels are their names, false if their distances. Default: true",
  309.         },
  310.         {
  311.             "waypointChar = '" .. tostring(waypointChar) .. "'",
  312.             "string, the character that waypoints on the map are represented by. Default: '*'",
  313.         },
  314.         {
  315.             "blankChar = '" .. tostring(blankChar) .. "'",
  316.             "string, the blank character that the inside of the map is made of. Default: ' '",
  317.         },
  318.         {
  319.             "refreshSleep = " .. tostring(refreshSleep),
  320.             "number, the delay between each GPS request. Default: 0.4",
  321.         },
  322.         {
  323.             "autoUpdate = " .. tostring(autoUpdate),
  324.             "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",
  325.         },
  326.         {
  327.             "turtleMode = " .. tostring(turtleMode),
  328.             "boolean, whether Map should be tuned to turtle controlling. Especially useful if used in conjunction with Lyqyd's NSH. Default: false",
  329.         },
  330.         {
  331.             "keyAgoesRight = " .. tostring(keyAgoesRight),
  332.             "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",
  333.         },
  334.         {
  335.             "spoofStep = " .. tostring(spoofStep),
  336.             "number, amount you move in one keypress in spoof mode. Used to move faster. Default: 1",
  337.         },
  338.         {
  339.             "mapColors = " .. string.gsub( textutils.serialize(numberToColor(mapColors)), "\"", "" ),
  340.             "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}",
  341.         },
  342.         {
  343.             "directionSensitivity = " .. tostring(directionSensitivity),
  344.             "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",
  345.         },
  346.         {
  347.             "monitorTextScale = " .. tostring(monitorTextScale),
  348.             "number, this determines what scale factor the text has if Map is being ran on a monitor. Default: 0.5",
  349.         },
  350.         {
  351.             "fakeX = " .. tostring(fakeX),
  352.             "number, this is the last recorded X position of the turtle/PDA. Is used in spoofMode, and updates when using turtleMode. Default: 0",
  353.         },
  354.         {
  355.             "fakeY = " .. tostring(fakeY),
  356.             "number, same as fakeX but for Y. Default: 66",
  357.         },
  358.         {
  359.             "fakeZ = " .. tostring(fakeZ),
  360.             "number, same as fakeX but for Z. Default: 0",
  361.         },
  362.         {
  363.             "fakeDir = " .. tostring(fakeDir),
  364.             "number, equal to 'f' in Debug mode in Minecraft (F3), range=0-3. Default: nil",
  365.         },
  366.         {
  367.             "doFlash = " .. tostring(doFlash),
  368.             "boolean, whether or not to do the flash animation when starting map up or exiting a menu. Default: false",
  369.         },
  370.         {
  371.             "colorLimit = " .. tostring(colorLimit),
  372.             "number, artificially limits the color palate. (0=monochrome,1=grayscale,2=colors). Default: 2",
  373.         },
  374.     }
  375.     file.writeLine("-" .. "- Do not break the format of this config.")
  376.     file.writeLine("-" .. "- This is for EldidiStroyrr/LDDestroier's 'Map' (GPS Minimap). Do 'map cc' to fix broken config.")
  377.     file.writeLine("-" .. "- This config has been last used on version " .. mapVersion .. ", for reference.")
  378.     for a = 1, #mapSettings do
  379.         file.writeLine(mapSettings[a][1] .. "  -" .. "-" .. mapSettings[a][2])
  380.     end
  381.     file.writeLine("")
  382.     file.close()
  383. end
  384.  
  385. function getConfig(mode)
  386.     if not fs.exists(fs.combine(waypointDir, defaultWaypointFile)) or (not fs.isDir(waypointDir)) then
  387.         if fs.exists("/.waypoints") and (not fs.isDir("/.waypoints")) then
  388.             fs.move("/.waypoints", "/waypoints")
  389.             fs.makeDir(waypointDir)
  390.             fs.move("/waypoints", fs.combine(waypointDir, defaultWaypointFile))
  391.         else
  392.             fs.makeDir(waypointDir)
  393.             file = fs.open(fs.combine(waypointDir, defaultWaypointFile), "w")
  394.             file.write({})
  395.             file.close()
  396.         end
  397.     end
  398.     local wayFiles = fs.list(waypointDir)
  399.     waypoints = {}
  400.     fileWaypoints = {}
  401.     for a = 1, #wayFiles do
  402.         if not fs.isDir(fs.combine(waypointDir, wayFiles[a])) then
  403.             file = fs.open(fs.combine(waypointDir, wayFiles[a]), "r")
  404.             contents = file.readAll()
  405.             contents = textutils.unserialize(contents)
  406.             file.close()
  407.             for b = 1, #contents do
  408.                 table.insert(waypoints, contents[b])
  409.                 if wayFiles[a] == defaultWaypointFile then
  410.                     table.insert(fileWaypoints, contents[b])
  411.                 end
  412.             end
  413.         end
  414.     end
  415.    
  416.     --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.
  417.     local modem = peripheral.find("modem")
  418.     if modem and mapProtocol then
  419.         for a = 1, #mapProtocol do
  420.             modem.close(mapProtocol[a])
  421.         end
  422.     end
  423.     spoofMode = false
  424.     broadcastData = true
  425.     scaleFactor = 0.25
  426.     networkName = "mapuser"..math.random(1,9999)
  427.     mapProtocol = {10666}
  428.     displayTitle = false
  429.     labelMode = true
  430.     waypointChar = '*'
  431.     blankChar = ' '
  432.     refreshSleep = 0.4
  433.     autoUpdate = false
  434.     if turtle then
  435.         turtleMode = true
  436.     else
  437.         turtleMode = false
  438.     end
  439.     keyAgoesRight = false --Useless and probably cauyses problems..but whatever
  440.     spoofStep = 1
  441.     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.
  442.         colors.gray, --Background color outside map square
  443.         colors.white, --Border color
  444.         colors.yellow, --Default waypoint color
  445.         colors.red, --Off-screen waypoint text color
  446.         colors.lightBlue, --Player color
  447.         colors.black, --Command screen text color
  448.         colors.lightGray, --Command screen background color
  449.         colors.red, --Background color if not connected to a GPS server
  450.         colors.black, --Background color inside map square
  451.     }
  452.     directionSensitivity = 0.15 --This is used to prevent the arrow on the middle of the screen from going crazy.
  453.     monitorTextScale = 0.5 --This determines what scale factor the text has if Map is being ran on a monitor.
  454.     fakeX = 0
  455.     fakeY = 66
  456.     fakeZ = 0
  457.     fakeDir = 0
  458.     doFlash = fals
  459.     colorLimit = 2
  460.    
  461.     shell.run(mapConfigFile) --Get the existing config options.
  462.     setColormode()
  463.    
  464.     if not type(networkName) == "string" then networkName = "mapuser"..math.random(1,9999) end
  465.     if not type(mapProtocol) == "table" then mapProtocol = {10666} end
  466.    
  467.     refreshOtherConfig() --Set the config file to what the variables are.
  468.    
  469.     if scr_x > 16 or scr_y > 10 then --Determines if Map is being ran on a single monitor block.
  470.         monitorMode = false
  471.     else
  472.         monitorMode = true
  473.     end
  474.     if not monitorTextScale then --This whole bit is for monitors, should you be arsed to use them with this.
  475.         monitorTextScale = 0.5
  476.     end
  477.     if monitorTextScale < 0.5 then
  478.         monitorTextScale = 0.5
  479.     elseif monitorTextScale > 5 then
  480.         monitorTextScale = 5
  481.     end
  482.     if type(monitorTextScale) ~= "number" then
  483.         monitorTextScale = 0.5
  484.     end
  485.  
  486.     local mon = peripheral.find("monitor")
  487.     if mon then
  488.         if not monitorMode then
  489.             mon.setTextScale(monitorTextScale)
  490.         else
  491.             mon.setTextScale(0.5)
  492.         end
  493.     end
  494.     if mode == "waypoint" then
  495.         return fileWaypoints
  496.     else
  497.         return contents
  498.     end
  499. end
  500. getConfig()
  501. function set(list) --Used to check if a phrase is in a table. Straight from StackOverflow, by Jon Ericson.
  502.     local set = {}
  503.     for _, l in ipairs(list) do
  504.         set[l] = true
  505.     end
  506.     return set
  507. end
  508. function stringToColor(color)
  509.     local stringColors = {"white","orange","magneta","lightBlue","yellow","lime","pink","gray","lightGray","cyan","purple","blue","brown","green","red","black"}
  510.     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}
  511.     if string.sub(color, 1, 7) == "colors." then
  512.         color = string.sub(color, 8)
  513.     end
  514.     for a = 1, #stringColors do
  515.         if string.lower(color) == string.lower(stringColors[a]) then
  516.             return numberColors[a]
  517.         end
  518.     end
  519.     return false
  520. end
  521. function setConfig(pointname, mode, x, y, z, derf)
  522.     config = getConfig("waypoint")
  523.     file = fs.open(fs.combine(waypointDir, defaultWaypointFile), "w")
  524.     if mode == "delete" then
  525.         for a = 1, #config do
  526.             point = config[a]
  527.             if point[1] == pointname then
  528.                 table.remove(config, a)
  529.                 file.writeLine(textutils.serialize(config))
  530.                 file.close()
  531.                 getConfig()
  532.                 return true
  533.             end
  534.         end
  535.         file.close()
  536.         return false
  537.     elseif mode == "add" then
  538.         if x == nil or y == nil or z == nil then
  539.             file.close()
  540.             return false
  541.         end
  542.         table.insert(config, {pointname, x, y, z, derf})
  543.         file.writeLine(textutils.serialize(config))
  544.         file.close()
  545.         getConfig()
  546.         return true
  547.     elseif mode == "rename" then
  548.         for a = 1, #config do
  549.             point = config[a]
  550.             if point[1] == pointname then
  551.                 table.remove(point, 1)
  552.                 table.insert(point, 1, x)
  553.                 file.writeLine(textutils.serialize(config))
  554.                 file.close()
  555.                 getConfig()
  556.                 return true
  557.             end
  558.         end
  559.         file.close()
  560.         return false
  561.     end
  562.     file.close()
  563. end
  564. local function round(num, idp)
  565.     local mult=10^(idp or 0)
  566.     return math.floor(num * mult + 0.5 ) / mult
  567. end
  568. local function setDefaultBackgroundColor()
  569.     if isConnected then
  570.         if colormode then
  571.             term.setBackgroundColor(mapColors[1])
  572.         else
  573.             if grayAllowed then
  574.                 term.setBackgroundColor(colors.gray)
  575.             else
  576.                 term.setBackgroundColor(colors.black)
  577.             end
  578.         end
  579.     else
  580.         if colormode then
  581.             term.setBackgroundColor(mapColors[8])
  582.         else
  583.             term.setBackgroundColor(colors.white)
  584.         end
  585.     end
  586. end
  587. local function setDefaultTextColor()
  588.     if colormode then
  589.         term.setTextColor(mapColors[2])
  590.     else
  591.         if isConnected then
  592.             term.setTextColor(colors.white)
  593.         else
  594.             term.setTextColor(colors.black)
  595.         end
  596.     end
  597. end
  598. local function setDefaultColors()
  599.     setDefaultTextColor()
  600.     setDefaultBackgroundColor()
  601. end
  602. local recordBuffer = {}
  603. if not oldCoord_x then
  604.     oldCoord_x, oldCoord_y, oldCoord_z = 0,0,0
  605.     posX, posY, posZ = 0,0,0
  606. end
  607. local function savePath(path)
  608.     if not path then return false, "you need a table." end
  609.     local pathpath
  610.     setDefaultColors()
  611.     term.clear()
  612.     term.setCursorPos(1,2)
  613.     print("Save path as: (blank for cancel)")
  614.     repeat
  615.         write(">")
  616.         pathpath = read()
  617.         if pathpath == "" then
  618.             print("Cancelling.")
  619.             sleep(0.2)
  620.             return false
  621.         end
  622.         if fs.exists(fs.combine(pathDir,pathpath)) then
  623.             pathpath = ""
  624.             print("That already exists.")
  625.         end
  626.     until pathpath ~= ""
  627.     pathpath = fs.combine(pathDir,pathpath)
  628.     local file = fs.open(pathpath,"w")
  629.     file.writeLine(textutils.serialize(path))
  630.     file.close()
  631.     print("Okay!")
  632.     sleep(0.2)
  633.     return true
  634. end
  635. local function getCoordinates()
  636.     if spoofMode then
  637.         isConnected = true
  638.         currentlyConnected = true
  639.         os.queueEvent("gpsRequest", true)
  640.         return {fakeX, fakeY, fakeZ}
  641.     else
  642.         oldCoord_x, oldCoord_y, oldCoord_z = coord_x, coord_y, coord_z
  643.         coord_x, coord_y, coord_z = gps.locate(5)
  644.         if (coord_x == nil) and isConnected then
  645.             currentlyConnected = false
  646.             os.queueEvent("gpsRequest", false)
  647.             if displayStuffs then
  648.                 term.setCursorPos(1,1)
  649.                 if colormode then
  650.                     term.setTextColor(colors.lightGray)
  651.                 else
  652.                     term.setTextColor(colors.white)
  653.                 end
  654.             end
  655.             if isConnected then
  656.                 if displayStuffs then
  657.                     term.clearLine()
  658.                     print("GPS not found...searching")
  659.                 end
  660.                 for a = 1, 5 do
  661.                     coord_x, coord_y, coord_z = gps.locate(1)
  662.                     if coord_x == nil then os.queueEvent("gpsRequest", false) end
  663.                 end
  664.                 if displayStuffs then
  665.                     if coord_x == nil then
  666.                         term.clearLine()
  667.                     end
  668.                 end
  669.             end
  670.         end
  671.         if coord_x == nil then
  672.             isConnected = false
  673.             os.queueEvent("gpsRequest", false)
  674.             return nil
  675.         else
  676.             isConnected = true
  677.             currentlyConnected = true
  678.             os.queueEvent("gpsRequest", true)
  679.             fakeX, fakeY, fakeZ = coord_x, coord_y, coord_z
  680.             if recording then
  681.                 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
  682.                     table.insert(recordBuffer,{math.floor(coord_x),math.floor(coord_y),math.floor(coord_z)})
  683.                 end
  684.             else
  685.                 if #recordBuffer > 0 then
  686.                     currentLocation = "savePath"
  687.                     displayStuffs = false
  688.                     savePath(recordBuffer)
  689.                     displayStuffs = true
  690.                     redrawMap = true
  691.                     renderCommands()
  692.                     currentLocation = "renderMap"
  693.                 end
  694.                 recordBuffer = {}
  695.             end
  696.             return {coord_x, coord_y, coord_z}
  697.         end
  698.     end
  699. end
  700.  
  701. local function rollOver(input, max)
  702.     return math.floor(input % max)
  703. end
  704.  
  705. local function drawMovingLine(ypos, size, speed, spacesize)
  706.     for a = 1, size do
  707.         if currentLocation == "waypointSettings" then
  708.             term.setCursorPos(1,ypos)
  709.             if colormode then
  710.                 term.setTextColor(colors.orange)
  711.             else
  712.                 if grayAllowed then
  713.                     term.setTextColor(colors.lightGray)
  714.                 else
  715.                     if isConnected then
  716.                         term.setTextColor(colors.white)
  717.                     else
  718.                         term.setTextColor(colors.black)
  719.                     end
  720.                 end
  721.             end
  722.             for x = 1, scr_x do
  723.                 if rollOver(x - a, size) < spacesize then
  724.                     write(" ")
  725.                 else
  726.                     write("-")
  727.                 end
  728.             end
  729.             sleep(speed)
  730.         end
  731.     end
  732. end
  733.  
  734. function flashScreen(times)
  735.     if (not times) or (type(times) ~= "number") then
  736.         times = 1
  737.     end
  738.     if colormode or grayAllowed then
  739.         flashes = {
  740.             colors.black,
  741.             colors.gray,
  742.             colors.lightGray,
  743.             colors.white,
  744.             colors.lightGray,
  745.             colors.black,
  746.         }
  747.     else
  748.         flashes = {
  749.             colors.black,
  750.             colors.white,
  751.         }
  752.     end
  753.     if doFlash then
  754.         for a = 1, times do
  755.             for b = 1, #flashes do
  756.                 term.setBackgroundColor(flashes[b])
  757.                 term.clear()
  758.                 sleep(0)
  759.             end
  760.         end
  761.     end
  762.     flashes = nil
  763.     setDefaultColors()
  764. end
  765.  
  766. --These functions were made by PhyscoKillerMonkey. It's subject to change...
  767. local function forward()
  768.     while not mapturt.forward() do
  769. --      print("Can't move, checking fuel")
  770.         if turtle.getFuelLevel() == 0 then
  771.             turtle.select(1)
  772.             turtle.refuel(1)
  773.         end
  774.         if digBlocks then
  775.             turtle.dig()
  776.         else
  777.             mapturt.up()
  778.             goneUp = goneUp + 1
  779.             cy = cy + 1
  780.         end
  781.     end
  782.     if dir == 0 then cz = cz + 1
  783.     elseif dir == 1 then cx = cx - 1
  784.     elseif dir == 2 then cz = cz - 1
  785.     elseif dir == 3 then cx = cx + 1 end
  786.     while goneUp > 0 and not turtle.detectDown() do
  787.         mapturt.down()
  788.         goneUp = goneUp - 1
  789.         cy = cy - 1
  790.     end
  791. end
  792. local function up()
  793.     while not mapturt.up() do
  794. --      print("Can't move, checking fuel")
  795.         if turtle.getFuelLevel() == 0 then
  796.             turtle.select(1)
  797.             turtle.refuel(1)
  798.         end
  799.         if digBlocks then
  800.             turtle.digUp()
  801.         end
  802.     end
  803.     cy = cy + 1
  804. end
  805. local function down()
  806.     while not mapturt.down() do
  807. --      print("Can't move, checking fuel")
  808.         if turtle.getFuelLevel() == 0 then
  809.             turtle.select(1)
  810.             turtle.refuel(1)
  811.         end
  812.         if digBlocks then
  813.             turtle.digDown()
  814.         end
  815.     end
  816.     cy = cy - 1
  817. end
  818. local function getPos()
  819. --  print("Getting position")
  820.     local cx, cy, cz = gps.locate(5)
  821.     print(cx, cy, cz)
  822. end
  823. local function getDir()
  824. --  print("Getting direction")
  825.     getPos()
  826.     local ox, oy, oz = cx, cy, cz
  827.     forward()
  828.     getPos()
  829.     if oz > cz then dir = 0
  830.     elseif oz < cz then dir = 2
  831.     elseif ox < cx then dir = 1
  832.     elseif ox > cx then dir = 3 end
  833.     --print(dir)
  834.     mapturt.back()
  835.     getPos()
  836. end
  837. local function turn(d)
  838. --  getDir()
  839. --  print("Aligning")
  840. --  print(dir, d)
  841.     while dir ~= d do
  842.         mapturt.turnRight()
  843.         dir = dir + 1
  844.         if dir == 4 then dir = 0 end
  845.     end
  846. end
  847. local function moveX()
  848. --  print("Moving X")
  849. --  getPos()
  850.     if gox > cx then
  851.         turn(1)
  852.         for x = 1, gox - cx do
  853.             forward()
  854.             cx = cx + 1
  855.         end
  856.     elseif gox < cx then
  857.         turn(3)
  858.         for x = 1, cx - gox do
  859.             forward()
  860.             cx = cx - 1
  861.         end
  862.     end
  863. end
  864. local function moveZ()
  865. --  print("Moving Z")
  866. --  getPos()
  867.     if goz > cz then
  868.         turn(2)
  869.         for z = 1, goz - cz do
  870.             forward()
  871.             cz = cz + 1
  872.         end
  873.     elseif goz < cz then
  874.         turn(0)
  875.         for z = 1, cz - goz do
  876.             forward()
  877.             cz = cz - 1
  878.         end
  879.     end
  880. end
  881. local function moveY()
  882. --  print("Moving Y")
  883. --  getPos()
  884.     if goy > cy then
  885.         for z = 1, goy - cy do
  886.             up()
  887.             cy = cy + 1
  888.         end
  889.     elseif goy < cy then
  890.         for z = 1, cy - goy do
  891.             down()
  892.             cy = cy - 1
  893.         end
  894.     end
  895. end
  896.  
  897. function clearMap()
  898.     if displayStuffs then
  899.         if not doGrid then
  900.             setDefaultTextColor()
  901.             if colormode then
  902.                 term.setBackgroundColor(mapColors[9])
  903.             else
  904.                 term.setBackgroundColor(colors.black)
  905.             end
  906.             local mapLengthInner = (corner2[1]) - (corner1[1]) - 1
  907.             local longBlankChar1 = string.rep(blankChar, mapLengthInner)
  908.             for y = corner1[2] + 1, corner2[2] - 1 do
  909.                 term.setCursorPos(corner1[1]+1,y)
  910.                 if y == math.floor(midPoint[2]) then
  911.                     write(string.rep(blankChar, math.ceil(mapLengthInner/2)-1))
  912.                     term.setCursorPos(midPoint[1]+1,y)
  913.                     write(string.rep(blankChar, math.floor(mapLengthInner/2)))
  914.                 else
  915.                     write(longBlankChar1)
  916.                 end
  917.             end
  918.             setDefaultColors()
  919.             for y = corner1[2], corner2[2] do
  920.                 term.setCursorPos(corner1[1]-1,y)
  921.                 write(" ") --I do " " because 'blankChar' is for the inside of the map.
  922.             end
  923.             for y = corner1[2], corner2[2] do
  924.                 term.setCursorPos(corner2[1]+1,y)
  925.                 write(" ") --Same here.
  926.             end
  927.             if isConnected then
  928.                 term.setCursorPos(1,corner1[2]-1)
  929.                 term.clearLine()
  930.             end
  931.         end
  932.     end
  933.     return
  934. end
  935. local commandXYPoses
  936. function drawBorder()
  937.     defineMapBorders()
  938.     if displayStuffs then
  939.         if colormode then
  940.             term.setTextColor(colors.lightGray)
  941.             term.setBackgroundColor(mapColors[2])
  942.         else
  943.             if isConnected then
  944.                 term.setTextColor(colors.white)
  945.                 term.setBackgroundColor(colors.white)
  946.             else
  947.                 if grayAllowed then
  948.                     term.setTextColor(colors.white)
  949.                     term.setBackgroundColor(colors.gray)
  950.                 else
  951.                     term.setTextColor(colors.white)
  952.                     term.setBackgroundColor(colors.black)
  953.                 end
  954.             end
  955.         end
  956.         local mapLength = corner2[1] - corner1[1]
  957.         local mapHeight = corner2[2] - corner1[2]
  958.         local longMapChar = string.rep(" ", mapLength)
  959.         local longMapCharHalf = string.rep(" ", math.floor(mapLength/2))
  960.         term.setCursorPos(corner1[1],corner1[2])
  961.         write(longMapCharHalf)
  962.         term.setCursorPos(midPoint[1]+1,corner1[2])
  963.         write(longMapCharHalf)
  964.         term.setCursorPos(corner1[1],corner2[2])
  965.         write(longMapChar)
  966.         for b = corner1[2], corner2[2] do
  967.             term.setCursorPos(corner1[1],b)
  968.             if b ~= midPoint[2] then
  969.                 write(" ")
  970.             else
  971.                 write("X")
  972.             end
  973.         end
  974.         for b = corner1[2], corner2[2] do
  975.             term.setCursorPos(corner2[1],b)
  976.             write(" ")
  977.         end
  978.        
  979.         term.setCursorPos(midPoint[1],corner1[2])
  980.         write("Z")
  981. --      term.setCursorPos(corner1[1],midPoint[2])
  982. --      write("X")
  983.         setDefaultColors()
  984.     end
  985.     return
  986. end
  987.  
  988. function drawScaleIndicator()
  989.     if math.floor(scaleFactor*100000) == 0 then
  990.         scaleFactor = 0.01
  991.     end
  992.     if displayStuffs then
  993.         scaleX = corner1[1] + 1
  994.         if not monitorMode then
  995.             scaleY = corner2[2] + 1
  996.         else
  997.             scaleY = scr_y - 2
  998.         end
  999.         term.setCursorPos(scaleX,scaleY)
  1000.         setDefaultColors()
  1001.         term.clearLine()
  1002.         if isConnected then
  1003.             term.setTextColor(colors.white)
  1004.         else
  1005.             if colormode then
  1006.                 term.setTextColor(colors.white)
  1007.             else
  1008.                 if grayAllowed then
  1009.                     term.setTextColor(colors.gray)
  1010.                 else
  1011.                     term.setTextColor(colors.black)
  1012.                 end
  1013.             end
  1014.         end
  1015.         write("Scale: ")
  1016.         if colormode then
  1017.             term.setTextColor(colors.orange)
  1018.         else
  1019.             if grayAllowed then
  1020.                 term.setTextColor(colors.lightGray)
  1021.             else
  1022.                 if isConnected then
  1023.                     term.setTextColor(colors.white)
  1024.                 else
  1025.                     term.setTextColor(colors.black)
  1026.                 end
  1027.             end
  1028.         end
  1029.         if not monitorMode then
  1030.             write(table.concat({string.sub(scaleFactor, 1, 12),"x"}))
  1031.         else
  1032.             write(table.concat({string.sub(scaleFactor, 1, 6),"x"}))
  1033.         end
  1034.     end
  1035. end
  1036.  
  1037. local function printOutput(commie)
  1038.     local oldCurX, oldCurY = term.getCursorPos()
  1039.     if type(commie) == "table" then
  1040.         for a = 1, #commie do
  1041.             term.setCursorPos(2,scr_y-(#commie-a))
  1042.             if colormode then
  1043.                 term.setTextColor(colors.gray)
  1044.                 term.setBackgroundColor(colors.lightGray)
  1045.             else
  1046.                 term.setTextColor(colors.black)
  1047.                 term.setBackgroundColor(colors.white)
  1048.             end
  1049.             term.clearLine()
  1050.             write(tostring(commie[a]))
  1051.         end
  1052.     else
  1053.         setDefaultColors()
  1054.         term.setCursorPos(1,scr_y-1)
  1055.         term.clearLine()
  1056.         term.setCursorPos(2,scr_y)
  1057.         if colormode then
  1058.             term.setTextColor(colors.gray)
  1059.             term.setBackgroundColor(colors.lightGray)
  1060.         else
  1061.             term.setTextColor(colors.black)
  1062.             term.setBackgroundColor(colors.white)
  1063.         end
  1064.         term.clearLine()
  1065.         write(tostring(commie))
  1066.         if turtle then
  1067.             if type(turtle.getFuelLevel()) ~= "string" then
  1068.                 if turtle.getFuelLevel() < 1 then
  1069.                     write(" (out of fuel)")
  1070.                 else
  1071.                     write(" (fuel:" .. turtle.getFuelLevel() .. ")")
  1072.                 end
  1073.             else
  1074.                 write(" (fuel:" .. turtle.getFuelLevel() .. ")")
  1075.             end
  1076.         end
  1077.     end
  1078.     term.setCursorPos(oldCurX,oldCurY)
  1079.     setDefaultColors()
  1080.     return commie
  1081. end
  1082.  
  1083. local renderMap = function()
  1084.     getCoordinates()
  1085.     setDefaultColors()
  1086.     term.clear()
  1087.     drawBorder()
  1088.     clearMap()
  1089.     redrawMap = true
  1090.     renderCommands()
  1091.     changedDirection = false
  1092.     if turtleMode then printOutput("turtleMode activated!") end
  1093.     local poses
  1094.     while true do
  1095.         if displayStuffs then
  1096.             wasConnected = true
  1097.             repeat
  1098.                 poses = getCoordinates()
  1099.                 if not isConnected then
  1100.                     if displayStuffs then
  1101.                         if colormode then
  1102.                             term.setBackgroundColor(mapColors[8])
  1103.                         else
  1104.                             term.setBackgroundColor(colors.white)
  1105.                         end
  1106.                         term.clear()
  1107.                         drawBorder()
  1108.                         renderCommands()
  1109.                     end
  1110.                     repeat
  1111.                         poses = getCoordinates()
  1112.                         sleep(0)
  1113.                     until isConnected
  1114.                     if displayStuffs then
  1115.                         setDefaultColors()
  1116.                         term.clear()
  1117.                         renderCommands()
  1118.                         drawBorder()
  1119.                     end
  1120.                 end
  1121.             until isConnected
  1122.             if displayStuffs then
  1123.                 setDefaultColors()
  1124.             end
  1125.         end
  1126.         oldCoord_x = posX
  1127.         oldCoord_y = posY
  1128.         oldCoord_z = posZ
  1129.         posX = poses[1]
  1130.         posY = poses[2]
  1131.         posZ = poses[3]
  1132.         if oldCoord_x ~= nil then
  1133.             if math.abs(oldCoord_x - posX) > directionSensitivity or math.abs(oldCoord_z - posZ) > directionSensitivity and not (turtleMode and changedDirection and turtle) then
  1134.                 if math.abs(oldCoord_x - posX) > math.abs(oldCoord_z - posZ) and oldCoord_x - posX > 0 then
  1135.                     direction_long = "east"
  1136.                     direction = "east"
  1137.                     changedDirection = true
  1138.                 elseif math.abs(oldCoord_x - posX) > math.abs(oldCoord_z - posZ) and oldCoord_x - posX < 0 then
  1139.                     direction_long = "west"
  1140.                     direction = "west"
  1141.                     changedDirection = true
  1142.                 elseif math.abs(oldCoord_z - posZ) > math.abs(oldCoord_x - posX) and oldCoord_z - posZ > 0 then
  1143.                     direction_lat = "south"
  1144.                     direction = "south"
  1145.                     changedDirection = true
  1146.                 elseif math.abs(oldCoord_z - posZ) > math.abs(oldCoord_x - posX) and oldCoord_z - posZ < 0 then
  1147.                     direction_lat = "north"
  1148.                     direction = "north"
  1149.                     changedDirection = true
  1150.                 end
  1151.             end
  1152.         end
  1153.         if displayStuffs then
  1154.             setDefaultColors()
  1155.             if ((oldCoord_x ~= posX or oldCoord_z ~= posZ) or hadCleared) and displayStuffs then
  1156.                 drawBorder()
  1157.                 clearMap()
  1158.                 hadCleared = false
  1159.             end
  1160.             if oldCoord_x ~= posX or oldCoord_z ~= posZ or oldCoord_y ~= posY or redrawMap == true then
  1161.             redrawMap = false
  1162.             for a = 1, #waypoints do
  1163.                 point = waypoints[a]
  1164.                 wayX = point[2]
  1165.                 wayY = point[3]
  1166.                 wayZ = point[4]
  1167.                 waypointColor = point[5]
  1168.                 waypointNewchar = point[6]
  1169.                
  1170.                 oldItemX = itemX
  1171.                 oldItemZ = itemZ
  1172.                
  1173.                 itemX = math.floor((midPoint[1] + (posX - math.floor(wayX)) * scaleFactor))
  1174.                 itemZ = math.floor((midPoint[2] + (posZ - math.floor(wayZ)) * scaleFactor))
  1175.                 term.setCursorPos(itemX,itemZ)
  1176.                 if itemX >= corner1[1] and itemX <= corner2[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
  1177.                     if not (itemX == math.floor(midPoint[1]) and itemZ == math.floor(midPoint[2])) then
  1178.                         if isConnected then
  1179.                             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
  1180.                                 term.setCursorPos(itemX,itemZ)
  1181.                                 if colormode then
  1182.                                     if waypointColor then
  1183.                                         term.setTextColor(waypointColor)
  1184.                                     else
  1185.                                         term.setTextColor(mapColors[3])
  1186.                                     end
  1187.                                     term.setBackgroundColor(mapColors[2])
  1188.                                 else
  1189.                                     if grayAllowed then
  1190.                                         term.setTextColor(colors.gray)
  1191.                                         term.setBackgroundColor(colors.white)
  1192.                                     else
  1193.                                         term.setTextColor(colors.black)
  1194.                                         term.setBackgroundColor(colors.white)
  1195.                                     end
  1196.                                 end
  1197.                             else
  1198.                                 if colormode then
  1199.                                     if waypointColor then
  1200.                                         term.setTextColor(waypointColor)
  1201.                                     else
  1202.                                         term.setTextColor(mapColors[3])
  1203.                                     end
  1204.                                     term.setBackgroundColor(mapColors[9])
  1205.                                 else
  1206.                                     term.setTextColor(colors.white)
  1207.                                     term.setBackgroundColor(colors.black)
  1208.                                 end
  1209.                             end
  1210.                             if not waypointNewchar then
  1211.                                 write(waypointChar)
  1212.                             else
  1213.                                 write(tostring(waypointNewchar))
  1214.                             end
  1215.                         else
  1216.                             if colormode then
  1217.                                 term.setTextColor(mapColors[8])
  1218.                             else
  1219.                                 term.setTextColor(colors.black)
  1220.                             end
  1221.                         end
  1222.                     end
  1223.                 else
  1224.                     if colormode then
  1225.                         if waypointColor then
  1226.                             term.setTextColor(waypointColor)
  1227.                         else
  1228.                             term.setTextColor(mapColors[4])
  1229.                         end
  1230.                         term.setBackgroundColor(mapColors[2])
  1231.                     else
  1232.                         term.setTextColor(colors.black)
  1233.                         term.setBackgroundColor(colors.white)
  1234.                     end
  1235.                     if itemX <= corner1[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
  1236.                         term.setCursorPos(corner1[1],itemZ)
  1237.                         write("<")
  1238.                     elseif itemX <= corner1[1] and itemZ <= corner1[2] then
  1239.                         term.setCursorPos(corner1[1],corner1[2])
  1240.                         if (itemX+corner1[1]) * -1 >= (itemZ+corner1[2]) * -1 then
  1241.                             write("<")
  1242.                         else
  1243.                             write("^")
  1244.                         end
  1245.                     elseif itemX <= corner1[1] and itemZ >= corner2[2] then
  1246.                         term.setCursorPos(corner1[1],corner2[2])
  1247.                         if (itemX+corner1[1]) * -1 >= (itemZ-corner2[2]) then
  1248.                             write("<")
  1249.                         else
  1250.                             write("v")
  1251.                         end
  1252.                     elseif itemX >= corner2[1] and itemZ <= corner2[2] and itemZ >= corner1[2] then
  1253.                         term.setCursorPos(corner2[1],itemZ)
  1254.                         write(">")
  1255.                     elseif itemX >= corner2[1] and itemZ <= corner1[2] then
  1256.                         term.setCursorPos(corner2[1],corner1[2])
  1257.                         if (itemX-corner1[1]) >= (itemZ+corner1[2]) * -1 then
  1258.                             write(">")
  1259.                         else
  1260.                             write("^")
  1261.                         end
  1262.                     elseif itemX >= corner2[1] and itemZ >= corner2[2] then
  1263.                         term.setCursorPos(corner2[1],corner2[2])
  1264.                         if (itemX-corner2[1]) >= (itemZ-corner2[2]) then
  1265.                             write(">")
  1266.                         else
  1267.                             write("v")
  1268.                         end
  1269.                     elseif itemX >= corner1[1] and itemX <= corner2[1] and itemZ <= corner1[2] then
  1270.                         term.setCursorPos(itemX,corner1[2])
  1271.                         write("^")
  1272.                     elseif itemX >= corner1[1] and itemX <= corner2[1] and itemZ >= corner2[2] then
  1273.                         term.setCursorPos(itemX,corner2[2])
  1274.                         write("v")
  1275.                     end
  1276.                    
  1277.                     if colormode then
  1278.                         term.setTextColor(mapColors[3])
  1279.                     else
  1280.                         term.setTextColor(colors.white)
  1281.                         term.setBackgroundColor(colors.black)
  1282.                     end
  1283.                 end
  1284.                 setDefaultColors()
  1285.                 if itemZ < corner2[2] + 2 then
  1286.                     if labelMode == true then
  1287.                         pointName = point[1]
  1288.                         pointMidX = math.ceil(itemX - (#pointName / 2))
  1289.                         pointMidZ = itemZ - 1
  1290.                         term.setCursorPos(pointMidX,pointMidZ)
  1291.                     elseif labelMode == false then
  1292.                         pointName = tostring(round(math.sqrt((point[2]-posX)^2 + (point[3]-posY)^2 + (point[4]-posZ)^2), 2))
  1293.                         pointMidX = itemX - math.floor(#pointName / 2)
  1294.                         pointMidZ = itemZ - 1
  1295.                         term.setCursorPos(pointMidX,pointMidZ)
  1296.                     end
  1297.                     if pointMidX + #pointName >= scr_x then
  1298.                         subLength = (scr_x - pointMidX) + 1
  1299.                         subName = string.sub(pointName, 1, subLength)
  1300.                         if pointMidX <= scr_x + 1 then
  1301.                             pointName = subName
  1302.                         end
  1303.                     end
  1304.                     if pointMidX <= scr_x then
  1305.                         for i = 1, #pointName do
  1306.                             labelPosX, labelPosY = term.getCursorPos()
  1307.                             term.setCursorPos(labelPosX,labelPosY)
  1308.                             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
  1309.                                 if colormode then
  1310.                                     term.setTextColor(mapColors[1])
  1311.                                     term.setBackgroundColor(mapColors[2])
  1312.                                 else
  1313.                                     if grayAllowed then
  1314.                                         term.setTextColor(colors.gray)
  1315.                                         term.setBackgroundColor(colors.white)
  1316.                                     else
  1317.                                         term.setTextColor(colors.black)
  1318.                                         term.setBackgroundColor(colors.white)
  1319.                                     end
  1320.                                 end
  1321.                             else
  1322.                                 if colormode then
  1323.                                     term.setBackgroundColor(mapColors[9])
  1324.                                     if wayY >= posY then
  1325.                                         term.setTextColor(mapColors[3])
  1326.                                     else
  1327.                                         term.setTextColor(colors.lightGray)
  1328.                                     end
  1329.                                 else
  1330.                                     if grayAllowed then
  1331.                                         term.setBackgroundColor(colors.black)                          
  1332.                                         if wayY >= posY then
  1333.                                             term.setTextColor(colors.white)
  1334.                                         else
  1335.                                             term.setTextColor(colors.lightGray)
  1336.                                         end
  1337.                                     else
  1338.                                         if wayY >= posY then
  1339.                                             term.setTextColor(colors.white)
  1340.                                             term.setBackgroundColor(colors.black)
  1341.                                         else
  1342.                                             term.setTextColor(colors.white)
  1343.                                             term.setBackgroundColor(colors.black)
  1344.                                         end
  1345.                                     end
  1346.                                 end
  1347.                             end
  1348.                             if (labelPosX == 1 or labelPosX == scr_x or labelPosY-1 % corner2[2] == 0) then
  1349.                                 term.setBackgroundColor(mapColors[1])
  1350.                             end
  1351.                             write(string.sub(pointName, i, i))
  1352.                         end
  1353.                     end
  1354.                 end
  1355.                 setDefaultColors()
  1356.             end
  1357.             end --Do not remove this end.
  1358.             term.setCursorPos(midPoint[1],midPoint[2])
  1359.             if colormode then
  1360.                 if recording then
  1361.                     term.setTextColor(colors.white)
  1362.                 else
  1363.                     term.setTextColor(mapColors[5])
  1364.                 end
  1365.                 term.setBackgroundColor(mapColors[9])
  1366.             else
  1367.                 if grayAllowed then
  1368.                     if recording then
  1369.                         term.setTextColor(colors.black)
  1370.                     else
  1371.                         term.setTextColor(colors.lightGray)
  1372.                     end
  1373.                     if isConnected then
  1374.                         term.setBackgroundColor(colors.black)
  1375.                     else
  1376.                         term.setBackgroundColor(colors.white)
  1377.                     end
  1378.                 else
  1379.                     if recording then
  1380.                         term.setTextColor(colors.black)
  1381.                     else
  1382.                         term.setTextColor(colors.white)
  1383.                     end
  1384.                     if isConnected then
  1385.                         term.setBackgroundColor(colors.black)
  1386.                     else
  1387.                         term.setBackgroundColor(colors.white)
  1388.                     end
  1389.                 end
  1390.             end
  1391.             if not turtleMode then
  1392.                 if direction == "east" then
  1393.                     playerChar = ">"
  1394.                 elseif direction == "west" then
  1395.                     playerChar = "<"
  1396.                 elseif direction == "south" then
  1397.                     playerChar = "v"
  1398.                 elseif direction == "north" then
  1399.                     playerChar = "^"
  1400.                 else
  1401.                     playerChar = "O"
  1402.                 end
  1403.             else
  1404.                 if fakeDir == 0 then
  1405.                     playerChar = "^"
  1406.                 elseif fakeDir == 1 then
  1407.                     playerChar = ">"
  1408.                 elseif fakeDir == 2 then
  1409.                     playerChar = "v"
  1410.                 elseif fakeDir == 3 then
  1411.                     playerChar = "<"
  1412.                 else
  1413.                     playerChar = "O"
  1414.                 end
  1415.             end
  1416.             write(playerChar)
  1417.         end
  1418.         if not spoofMode then
  1419.             sleep(refreshSleep)
  1420.         else
  1421.             sleep(0)
  1422.         end
  1423.     end
  1424. end
  1425.  
  1426. local commands = {
  1427.     "(L)abel/dist",
  1428.     "Optio(n)s",
  1429.     "E(x)it",
  1430. }
  1431.  
  1432. function renderCommands()
  1433.     commandXYPoses = {} --Allows me to click on the commands with captureMouseInput()
  1434.     if not isConnected and not monitorMode then
  1435.         term.setCursorPos(2,1)
  1436.         if colormode then
  1437.             term.setTextColor(colors.gray)
  1438.         else
  1439.             term.setTextColor(colors.black)
  1440.         end
  1441.         gpsNotFoundString = "GPS not found."
  1442.         term.clearLine()
  1443.         write(gpsNotFoundString)
  1444.     end
  1445.     startX = 2
  1446.     if not monitorMode then
  1447.         startY = corner2[2] + 1
  1448.     else
  1449.         startY = scr_y - 3
  1450.     end
  1451.     commandX = startX
  1452.     commandY = startY + 1
  1453.     if displayStuffs then
  1454.         term.setCursorPos(commandX,commandY)
  1455.         if colormode then
  1456.             term.setTextColor(mapColors[6])
  1457.             term.setBackgroundColor(mapColors[7])
  1458.         else
  1459.             term.setTextColor(colors.black)
  1460.             if grayAllowed then
  1461.                 term.setBackgroundColor(colors.lightGray)
  1462.             else
  1463.                 term.setBackgroundColor(colors.white)
  1464.             end
  1465.         end
  1466.         term.clearLine()
  1467.         for f = 1, #commands do
  1468.             comPosX, comPosY = term.getCursorPos()
  1469.             if scr_x - comPosX <= string.len(commands[f]) + 1 then
  1470.                 term.setCursorPos(startX,comPosY+1)
  1471.                 term.clearLine()
  1472.                 comPosX, comPosY = term.getCursorPos()
  1473.             end
  1474.             write(commands[f])
  1475.             table.insert(commandXYPoses, {comPosX, comPosY})
  1476.             if not monitorMode then
  1477.                 if f ~= #commands then
  1478.                     write(", ")
  1479.                 end
  1480.             else
  1481.                 if f < 2 then
  1482.                     write(", ")
  1483.                 end
  1484.             end
  1485.         end
  1486.         drawScaleIndicator()
  1487.     end
  1488.     return
  1489. end
  1490. term.setBackgroundColor(colors.black)
  1491. term.clear()
  1492. renderCommands()
  1493. function displayHelp()
  1494.     term.setCursorPos(1,2)
  1495.     setDefaultColors()
  1496.     if colormode then
  1497.         term.setTextColor(colors.orange)
  1498.     end
  1499.     print("GPS Minimap program by EldidiStroyrr.")
  1500.     setDefaultColors()
  1501.     local helpItems = {
  1502.         "'map cc' clears config.",
  1503.         "'map cw' clears waypoints.",
  1504.         "'map oc' opens config",
  1505.         "Do 'map update <main/beta>' to update.",
  1506.         "Do 'map help' for help. Duh.",
  1507.         "Pressing numpad '+' or '-' will zoom by 0.1",
  1508.     }
  1509.     local starterX, starterY = term.getCursorPos()
  1510.     local yOffset = 0
  1511.     for a = 1, #helpItems do
  1512.         term.setCursorPos(2,(a-1)+starterY+yOffset)
  1513.         if colormode or grayAllowed then
  1514.             term.setTextColor(colors.lightGray)
  1515.         else
  1516.             term.setTextColor(colors.white)
  1517.         end
  1518.         write("*")
  1519.         setDefaultColors()
  1520.         local curX1, curY1 = term.getCursorPos()
  1521.         print(tostring(helpItems[a]))
  1522.         local curX2, curY2 = term.getCursorPos()
  1523.         yOffset = yOffset + ((curY2 - curY1) - 1)
  1524.     end
  1525.     sleep(0.1)
  1526.     if colormode or grayAllowed then
  1527.         term.setTextColor(colors.lightGray)
  1528.     end
  1529.     print("")
  1530.     print("Press a key to continue.")
  1531.     sleep(0)
  1532.     local event, key = os.pullEvent("key")
  1533.     return
  1534. end
  1535. function doesColorExist(color)
  1536.     if type(color) == "string" then
  1537.         local colors = set({"white","orange","magneta","lightBlue","yellow","lime","pink","gray","lightGray","cyan","purple","blue","brown","green","red","black"})
  1538.         if string.sub(color, 1, 7) == "colors." then
  1539.             if colors[string.sub(color, 8)] == true then
  1540.                 return true
  1541.             else
  1542.                 return false
  1543.             end
  1544.         else
  1545.             if colors[color] == true then
  1546.                 return true
  1547.             else
  1548.                 return false
  1549.             end
  1550.         end
  1551.     else
  1552.         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})
  1553.         if colors[color] == true then
  1554.             return true
  1555.         else
  1556.             return false
  1557.         end
  1558.     end
  1559. end
  1560. function setWaypoint()
  1561.     term.setCursorPos(1,2)
  1562.     setDefaultColors()
  1563.     defaultNewPointName = "way" --Not used, in favor of a way to cancel.
  1564.     print("Set waypoint.")
  1565.     print("Call it what?")
  1566.     sleep(0)
  1567.     write(">")
  1568.     newName = tostring(read())
  1569.     if newName == "" then
  1570.         print("Cancelling.")
  1571.         sleep(0.2)
  1572.         return
  1573.     end
  1574.     print("What X? (default: current xyz)")
  1575.     write(">")
  1576.     newX = tonumber(read())
  1577.     if newX == nil then
  1578.         if isConnected then
  1579.             newX = posX
  1580.             newY = posY
  1581.             newZ = posZ
  1582.         else
  1583.             print("Since you aren't connected to GPS, I can't set waypoints to where you are.")
  1584.             yield()
  1585.             os.pullEvent("key")
  1586.             return
  1587.         end
  1588.     else
  1589.         print("What Y? (default: here)")
  1590.         write(">")
  1591.         newY = tonumber(read())
  1592.         if newY == nil then
  1593.             newY = posY
  1594.         end
  1595.         print("What Z? (default: here)")
  1596.         write(">")
  1597.         newZ = tonumber(read())
  1598.         if newZ == nil then
  1599.             newZ = posZ
  1600.         end
  1601.     end
  1602.     print("What color?")
  1603.     write(">")
  1604.     newColor = tostring(read())
  1605.     if not doesColorExist(newColor) then
  1606.         print("Not a color. Defaulting to 'yellow'")
  1607.         sleep(0.2)
  1608.         newColor = nil
  1609.     else
  1610.         newColor = stringToColor(newColor)
  1611.     end
  1612.     setConfig(newName, "add", newX, newY, newZ, newColor)
  1613.     refreshOtherConfig()
  1614.     print("Waypoint '" .. newName .. "' set!")
  1615.     getConfig()
  1616.     sleep(0.2)
  1617. end
  1618. function setScale()
  1619.     term.setCursorPos(1,2)
  1620.     setDefaultColors()
  1621.     print("Set scale factor. Currently " .. scaleFactor .. ".")
  1622.     repeat
  1623.         yield()
  1624.         newScale = nil
  1625.         write(">")
  1626.         newScaleRaw = read()
  1627.         if tostring(newScaleRaw) == "" then
  1628.             print("Cancelling.")
  1629.             sleep(0.2)
  1630.             return
  1631.         end
  1632.         newScale = tonumber(newScaleRaw)
  1633.         if newScale == nil then
  1634.             print("That's not a number!")
  1635.         end
  1636.     until type(newScale) == "number"
  1637.     scaleFactor = newScale
  1638.     print("Scale factor set to " .. scaleFactor .. ".")
  1639.     refreshOtherConfig()
  1640.     getConfig()
  1641.     sleep(0.2)
  1642.     return true
  1643. end
  1644.  
  1645. function deleteWaypoint()
  1646.     term.setCursorPos(1,2)
  1647.     setDefaultColors()
  1648.     print("Delete what waypoint?")
  1649.     if colormode then
  1650.         term.setTextColor(colors.orange)
  1651.     end
  1652.     for a = 1, #waypoints do
  1653.         point = waypoints[a]
  1654.         print(" -'" .. point[1] .. "'")
  1655.     end
  1656.     if colormode then
  1657.         term.setTextColor(colors.white)
  1658.     end
  1659.     sleep(0)
  1660.     write(">")
  1661.     delName = tostring(read())
  1662.     for a = 1, #waypoints do
  1663.         point = waypoints[a]
  1664.         if point[1] == delName then
  1665.             setConfig(delName, "delete")
  1666.             print("Deleted '" .. delName .. "'.")
  1667.             refreshOtherConfig()
  1668.             getConfig()
  1669.             sleep(0.2)
  1670.             return true
  1671.         end
  1672.     end
  1673.     print("Invalid waypoint '" .. delName .. "'!")
  1674.     sleep(0.2)
  1675.     return false
  1676. end
  1677. function renameWaypoint()
  1678.     term.setCursorPos(1,2)
  1679.     setDefaultColors()
  1680.     print("Rename which waypoint?")
  1681.     if colormode then
  1682.         term.setTextColor(colors.orange)
  1683.     end
  1684.     for a = 1, #fileWaypoints do
  1685.         point = fileWaypoints[a]
  1686.         print(" -'" .. point[1] .. "'")
  1687.     end
  1688.     if colormode then
  1689.         term.setTextColor(colors.white)
  1690.     end
  1691.     write(">")
  1692.     sleep(0)
  1693.     local renName = tostring(read())
  1694.     print("Rename to what?")
  1695.     write(">")
  1696.     renOutput = tostring(read())
  1697.     for a = 1, #fileWaypoints do
  1698.         local point = fileWaypoints[a]
  1699.         if point[1] == renName then
  1700.             setConfig(renName, "rename", renOutput)
  1701.             print("Renamed '" .. renName .. "' to '" .. renOutput .. "'.")
  1702.             refreshOtherConfig()
  1703.             getConfig()
  1704.             sleep(0.2)
  1705.             return true
  1706.         end
  1707.     end
  1708.     print("Invalid waypoint '" .. renName .. "'!")
  1709.     sleep(0.2)
  1710.     return false
  1711. end
  1712. function redrawSceen()
  1713.     drawBorder()
  1714. end
  1715. function inspectWaypoint()
  1716.     term.clear()
  1717.     term.setCursorPos(1,2)
  1718.     print("Inspect which waypoint?")
  1719.     print("(get x,y,z,etc.):")
  1720.     print(string.rep("-",scr_x))
  1721.     if colormode then
  1722.         term.setTextColor(colors.orange)
  1723.     end
  1724.     for a = 1, #waypoints do
  1725.         point = waypoints[a]
  1726.         print(" -'" .. point[1] .. "'")
  1727.     end
  1728.     if colormode then
  1729.         term.setTextColor(colors.white)
  1730.     end
  1731.     sleep(0)
  1732.     write(">")
  1733.     local inspName = tostring(read())
  1734.     for a = 1, #waypoints do
  1735.         local point = waypoints[a]
  1736.         if point[1] == inspName then
  1737.             term.clear()
  1738.             term.setCursorPos(1,2)
  1739.             print("Info of '"..inspName.."':")
  1740.             print(string.rep("-",scr_x))
  1741.             print("X = "..point[2].." (you = "..posX..")")
  1742.             print("Y = "..point[3].." (you = "..posY..")")
  1743.             print("Z = "..point[4].." (you = "..posZ..")")
  1744.             print("Distance = "..math.sqrt((point[2]-posX)^2+(point[3]-posY)^2+(point[4]-posZ)^2))
  1745.             if type(point[7]) == "number" and point[7] ~= -1 then
  1746.                 write("Type = ")
  1747.                 if point[7] == 1 then
  1748.                     print("Pocket")
  1749.                 elseif point[7] == 2 then
  1750.                     print("Turtle")
  1751.                 elseif point[7] == 3 then
  1752.                     print("PC")
  1753.                 end
  1754.                 write("\n")
  1755.             end
  1756.             if point[3] < posY then
  1757.                 print("It is below you.")
  1758.             elseif point[3] > posY then
  1759.                 print("It is above you.")
  1760.             else
  1761.                 print("Your altitudes are equal.")
  1762.             end
  1763.             sleep(0.1)
  1764.             os.pullEvent("key")
  1765.             return true
  1766.         end
  1767.     end
  1768.     print("No such waypoint! Cancelling.")
  1769.     sleep(0.3)
  1770.     return false
  1771. end
  1772. local function displayTurtleControls()
  1773.     term.setCursorPos(1,2)
  1774.     print("Turtle Control Scheme:")
  1775.     for a = 1, scr_x do write("-") end
  1776.     print("")
  1777.     print(" Q W E  U I O P <up")
  1778.     print(" A S D  J K L ; <front")
  1779.     print(" TAB    M , . / <down")
  1780.     print("")
  1781.     print(" Q = down, E = up")
  1782.     print(" WASD = move")
  1783.     print(" U J M = hit   7 8 9 red")
  1784.     print(" I K , = place 4 5 6 stone")
  1785.     print(" O L . = dig   1 2 3 ctrl")
  1786.     print(" P ; / = inspect")
  1787.     write(" TAB = refuel")
  1788.     sleep(0.1)
  1789.     os.pullEvent("key")
  1790.     return
  1791. end
  1792. function choice(input)
  1793.     repeat
  1794.         event, key = os.pullEvent("key")
  1795.         if type(key) == "number" then key = keys.getName(key) end
  1796.         if key == nil then key = " " end
  1797.     until string.find(input, key)
  1798.     return key
  1799. end
  1800. function waypointSettings()
  1801.     displayStuffs = false
  1802.     setDefaultColors()
  1803.     sleep(0)
  1804.     term.setCursorPos(1,2)
  1805.     print(" Map Options:")
  1806.     term.setCursorPos(1,4)
  1807.     if colormode then
  1808.         term.setTextColor(colors.orange)
  1809.     end
  1810.     print(" * (C)reate Waypoint")
  1811.     print(" * (D)elete Waypoint")
  1812.     print(" * (R)ename Waypoint")
  1813.     print(" * Edit C(o)nfig")
  1814.     print(" * (S)et Scale")
  1815.     print(" * Show (H)elp")
  1816.     if turtleMode then print(" * Show (t)urtle controls") end
  1817.     if turtleMode then print(" * Send turtle to (p)oint") end
  1818.     print(" * (I)nspect waypoint")
  1819.     write(" * E(x)it")
  1820.     if turtleMode then
  1821.         key = choice("cdroshtpix")
  1822.     else
  1823.         key = choice("cdroshix")
  1824.     end
  1825.     if key == "d" then
  1826.         currentLocation = "deleteWaypoint"
  1827.         setDefaultColors()      displayStuffs = false
  1828.         term.clear()
  1829.         sleep(0)
  1830.         deleteWaypoint()
  1831.         term.clear()
  1832.         currentLocation = "renderMap"
  1833.         sleep(0)
  1834.         flashScreen(1)
  1835.         displayStuffs = true
  1836.         redrawSceen()
  1837.         return
  1838.     end
  1839.     if key == "r" then
  1840.         currentLocation = "renameWaypoint"
  1841.         setDefaultColors()
  1842.         term.clear()
  1843.         sleep(0)
  1844.         renameWaypoint()
  1845.         term.clear()
  1846.         currentLocation = "renderMap"
  1847.         sleep(0)
  1848.         flashScreen(1)
  1849.         displayStuffs = true
  1850.         redrawSceen()
  1851.         return
  1852.     end
  1853.     if key == "s" then
  1854.         currentLocation = "setScale"
  1855.         setDefaultColors()
  1856.         term.clear()
  1857.         sleep(0)
  1858.         setScale()
  1859.         term.clear()
  1860.         currentLocation = "renderMap"
  1861.         sleep(0)
  1862.         flashScreen(1)
  1863.         displayStuffs = true
  1864.         redrawSceen()
  1865.         drawScaleIndicator()
  1866.         return
  1867.     end
  1868.     if key == "o" then
  1869.         currentLocation = "editConfig"
  1870.         setDefaultBackgroundColor()
  1871.         term.clear()
  1872.         sleep(0.1)
  1873.         shell.run("edit " .. mapConfigFile)
  1874.         currentLocation = "renderMap"
  1875.         sleep(0)
  1876.         flashScreen(1)
  1877.         displayStuffs = true
  1878.         getConfig()
  1879.         setDefaultColors()
  1880.         term.clear()
  1881.         redrawSceen()
  1882.         return
  1883.     end
  1884.     if key == "c" then
  1885.         currentLocation = "setWaypoint"
  1886.         setDefaultColors()
  1887.         term.clear()
  1888.         sleep(0)
  1889.         setWaypoint()
  1890.         term.clear()
  1891.         currentLocation = "renderMap"
  1892.         sleep(0)
  1893.         flashScreen(1)
  1894.         displayStuffs = true
  1895.         redrawSceen()
  1896.     end
  1897.     if key == "h" then
  1898.         currentLocation = "displayHelp"
  1899.         setDefaultColors()
  1900.         term.clear()
  1901.         sleep(0)
  1902.         displayHelp()
  1903.         term.clear()
  1904.         currentLocation = "renderMap"
  1905.         sleep(0)
  1906.         flashScreen(1)
  1907.         displayStuffs = true
  1908.         clearMap()
  1909.         drawBorder()
  1910.         renderCommands()
  1911.     end
  1912.     if key == "i" then
  1913.         currentLocation = "inspectWaypoint"
  1914.         setDefaultColors()
  1915.         term.clear()
  1916.         sleep(0)
  1917.         inspectWaypoint()
  1918.         term.clear()
  1919.         currentLocation = "renderMap"
  1920.         sleep(0)
  1921.         flashScreen(1)
  1922.         displayStuffs = true
  1923.         clearMap()
  1924.         drawBorder()
  1925.         renderCommands()
  1926.     end
  1927.     if key == "t" and turtleMode then
  1928.         currentLocation = "displayTurtleControls"
  1929.         setDefaultColors()
  1930.         term.clear()
  1931.         sleep(0)
  1932.         displayTurtleControls()
  1933.         term.clear()
  1934.         currentLocation = "renderMap"
  1935.         sleep(0)
  1936.         flashScreen(1)
  1937.         displayStuffs = true
  1938.         clearMap()
  1939.         drawBorder()
  1940.         renderCommands()
  1941.     end
  1942.     if key == "p" and turtleMode then
  1943.         currentLocation = "turtleToPoint"
  1944.         setDefaultColors()
  1945.         term.clear()
  1946.         term.setCursorPos(1,2)
  1947.         if isConnected then
  1948.             print("Go to coordinates or waypoint?")
  1949.             print("[c/w/X]")
  1950.             repeat
  1951.                 sleep(0)
  1952.                 event, key = os.pullEvent("key")
  1953.                 if type(key) == "number" then key = keys.getName(key) end
  1954.                 if key == nil then key = " " end
  1955.             until string.find("cwx", key)
  1956.             print("")
  1957.             local destinationX, destinationY, destinationZ
  1958.             if key == "c" then
  1959.                 print("Enter destination...")
  1960.                 print("...X:")
  1961.                 sleep(0)
  1962.                 destinationX = tonumber(read())
  1963.                 if destinationX == nil then
  1964.                     print("Not a number! Cancelling.")
  1965.                     sleep(0.2)
  1966.                     flashScreen(1)
  1967.                     return
  1968.                 end
  1969.                 print("...Y:")
  1970.                 sleep(0)
  1971.                 destinationY = tonumber(read())
  1972.                 if destinationY == nil then
  1973.                     print("Not a number! Cancelling.")
  1974.                     sleep(0.2)
  1975.                     flashScreen(1)
  1976.                     return
  1977.                 end
  1978.                 print("...Z:")
  1979.                 sleep(0)
  1980.                 destinationZ = tonumber(read())
  1981.                 if destinationZ == nil then
  1982.                     print("Not a number! Cancelling.")
  1983.                     sleep(0.2)
  1984.                     flashScreen(1)
  1985.                     return
  1986.                 end
  1987.                 term.clear()
  1988.                 term.setCursorPos(1,2)
  1989.                 write("Going...")
  1990.                 local result, bool = printOutput(goToCoordinates(destinationX, destinationY, destinationZ))
  1991.                 if not bool == false then
  1992.                     print("done!")
  1993.                     sleep(0.2)
  1994.                 else
  1995.                     sleep(0.1)
  1996.                     print("Press a key to continue")
  1997.                     os.pullEvent("key")
  1998.                 end
  1999.             elseif key == "w" then
  2000.                 print("Which waypoint?")
  2001.                 if colormode then
  2002.                     term.setTextColor(colors.orange)
  2003.                 end
  2004.                 for a = 1, #waypoints do
  2005.                     point = waypoints[a]
  2006.                     print(" -'" .. point[1] .. "'")
  2007.                 end
  2008.                 if colormode then
  2009.                     term.setTextColor(colors.white)
  2010.                 end
  2011.                 sleep(0)
  2012.                 local destWaypoint = tostring(read())
  2013.                 if destWaypoint == "" then
  2014.                     print("Cancelling.")
  2015.                     sleep(0.1)
  2016.                     flashScreen(1)
  2017.                     return
  2018.                 end
  2019.                 write("Going...")
  2020.                 printOutput(goToCoordinates(tostring(destWaypoint)))
  2021.                 print("finished.")
  2022.                 sleep(0.2)
  2023.             end
  2024.         else
  2025.             print("You are not connected to a GPS server, so you cannot send turtles.")
  2026.             print("Press a key to continue")
  2027.             sleep(0)
  2028.             os.pullEvent("key")
  2029.         end
  2030.         currentLocation = "renderMap"
  2031.         flashScreen(1)
  2032.         term.clear()
  2033.         sleep(0)
  2034.         displayStuffs = true
  2035.         clearMap()
  2036.         drawBorder()
  2037.         renderCommands()
  2038.         redrawMap = true
  2039.     end
  2040.     if key == "x" then
  2041.         currentLocation = "renderMap"
  2042.         sleep(0)
  2043.         flashScreen(1)
  2044.         return
  2045.     end
  2046.     currentLocation = "renderMap"
  2047.     return
  2048. end
  2049. function refuelTurtle(amount)
  2050.     local originalSlot = turtle.getSelectedSlot()
  2051.     for a = 1, 16 do
  2052.         turtle.select(a)
  2053.         if turtle.refuel(0) then
  2054.             turtle.refuel(amount)
  2055.             turtle.select(originalSlot)
  2056.             return "refuelled " .. amount
  2057.         end
  2058.     end
  2059.     turtle.select(originalSlot)
  2060.     return "can't refuel " .. amount
  2061. end
  2062. function goToCoordinates(destX, destY, destZ)
  2063.     if not turtleMode then
  2064.         return "turtleMode is not true"
  2065.     end
  2066.     if destY == nil then
  2067.         local pointName = destX
  2068.         for a = 1, #waypoints do
  2069.             point = waypoints[a]
  2070.             if point[1] == pointName then
  2071.                 destX = tonumber(point[2])
  2072.                 destY = tonumber(point[3])
  2073.                 destZ = tonumber(point[4])
  2074.             end
  2075.         end
  2076.         if destY == nil then
  2077.             return "no such waypoint"
  2078.         end
  2079.         if turtle then
  2080.             if type(turtle.getFuelLevel()) == "number" then
  2081.                 if math.abs(destX-posX)+math.abs(destY-posY)+math.abs(destZ-posZ) > turtle.getFuelLevel() then
  2082.                     return "insufficient fuel", false
  2083.                 end
  2084.             end
  2085.             printOutput("going to waypoint '" .. pointName .. "'")
  2086.         end
  2087.     else
  2088.         if turtle then
  2089.             if type(turtle.getFuelLevel()) == "number" then
  2090.                 if math.abs(destX-posX)+math.abs(destY-posY)+math.abs(destZ-posZ) > turtle.getFuelLevel() then
  2091.                     return "insufficient fuel", false
  2092.                 end
  2093.             end
  2094.             printOutput("going to " .. destX .. "," .. destY .. "," .. destZ .. "...")
  2095.         end
  2096.     end
  2097.     --Credit to PhyscoKillerMonkey for the goto script.
  2098.     gox = tonumber(destX)
  2099.     goy = tonumber(destY)
  2100.     goz = tonumber(destZ)
  2101.     digBlocks = true
  2102.     goneUp = 0 --dir and goneUp are used to keep track of position
  2103.     dir = 0
  2104.     getPos()
  2105.     getDir()
  2106.     if goy > cy then
  2107.         moveY()
  2108.         moveX()
  2109.         moveZ()
  2110.     else
  2111.         moveX()
  2112.         moveZ()
  2113.         moveY()
  2114.     end
  2115.     --End of script by PhyscoKillerMonkey.
  2116.     return "went to coordinates " .. destX .. "," .. destY .. "," .. destZ .. "."
  2117. end
  2118. local function turtleTurnLeft()
  2119.     if direction == "north" then direction = "west"
  2120.     elseif direction == "west" then direction = "south"
  2121.     elseif direction == "south" then direction = "east"
  2122.     elseif direction == "east" then direction = "north" end
  2123.     printOutput(mapturt.turnLeft())
  2124. end
  2125. local function turtleTurnRight()
  2126.     if direction == "north" then direction = "east"
  2127.     elseif direction == "east" then direction = "south"
  2128.     elseif direction == "south" then direction = "west"
  2129.     elseif direction == "west" then direction = "north" end
  2130.     printOutput(mapturt.turnRight())
  2131. end
  2132. local function textingPrompt()
  2133.     term.setCursorPos(1,1)
  2134.     term.clearLine()
  2135.     write(">")
  2136.     sleep(0)
  2137.     local message = read()
  2138.     if message == "" then
  2139.         return false
  2140.     else
  2141.         local modem = peripheral.find("modem")
  2142.         if not modem then
  2143.             return false
  2144.         end
  2145.         local msg = {networkName,message}
  2146.         for a = 1, #mapProtocol do
  2147.             modem.transmit(mapProtocol[a],mapProtocol[a],msg)
  2148.         end
  2149.         return true
  2150.     end
  2151. end
  2152. local function keyPress() --Captures keypresses when normally viewing the map.
  2153.     recording = false
  2154.     displayStuffs = true
  2155.     while true do
  2156.         currentLocation = "renderMap"
  2157.         local event, key = os.pullEvent("key")
  2158.         if type(key) == "number" then key = tostring(keys.getName(key)) end
  2159.         if spoofMode and not turtleMode then
  2160.             if key == "left" then
  2161.                 fakeX = fakeX + spoofStep
  2162.                 refreshOtherConfig()
  2163.                 sleep(0)
  2164.             end
  2165.             if key == "right" then
  2166.                 fakeX = fakeX - spoofStep
  2167.                 refreshOtherConfig()
  2168.                 sleep(0)
  2169.             end
  2170.             if key == "down" then
  2171.                 fakeZ = fakeZ - spoofStep
  2172.                 refreshOtherConfig()
  2173.                 sleep(0)
  2174.             end
  2175.             if key == "up" then
  2176.                 fakeZ = fakeZ + spoofStep
  2177.                 refreshOtherConfig()
  2178.                 sleep(0)
  2179.             end
  2180.         end
  2181.         if currentlyConnected or (currentlyConnected == false and isConnected == false) then
  2182.             if key == "space" then
  2183.                 recording = not recording
  2184.             end
  2185.             if key == "l" then
  2186.                 if labelMode == true then
  2187.                     labelMode = false
  2188.                 elseif labelMode == false then
  2189.                     labelMode = true
  2190.                 end
  2191.                 refreshOtherConfig()
  2192.                 drawBorder()
  2193.                 clearMap()
  2194.                 redrawMap = true
  2195.             end
  2196.             if key == "t" then
  2197.                 currentLocation = "textingPrompt"
  2198.                 displayStuffs = false
  2199.                 setDefaultColors()
  2200.                 textingPrompt()
  2201.                 sleep(0)
  2202.                 displayStuffs = true
  2203.                 clearMap()
  2204.                 drawBorder()
  2205.                 renderCommands()
  2206.                 redrawMap = true
  2207.             end
  2208.             if key == "n" then
  2209.                 currentLocation = "waypointSettings"
  2210.                 displayStuffs = false
  2211.                 setDefaultColors()
  2212.                 term.clear()
  2213.                 sleep(0)
  2214.                 os.queueEvent("gpsRequest") --To make sure the line animation in the settings works.
  2215.                 waypointSettings()
  2216.                 currentLocation = "renderMap"
  2217.                 term.clear()
  2218.                 sleep(0)
  2219.                 displayStuffs = true
  2220.                 clearMap()
  2221.                 drawBorder()
  2222.                 renderCommands()
  2223.                 redrawMap = true
  2224.                 if turtleMode then printOutput("turtleMode activated!") end
  2225.             end
  2226.             if key == "numPadAdd" or key == "add" then
  2227.                 scaleFactor = scaleFactor + 0.01
  2228.                 refreshOtherConfig()
  2229.                 clearMap()
  2230.                 drawBorder()
  2231.                 drawScaleIndicator()
  2232.                 redrawMap = true
  2233.             elseif (key == "minus" or key == "numPadSubtract") and scaleFactor > 0.01 then
  2234.                 scaleFactor = scaleFactor - 0.01
  2235.                 refreshOtherConfig()
  2236.                 clearMap()
  2237.                 drawBorder()
  2238.                 drawScaleIndicator()
  2239.                 redrawMap = true
  2240.             end
  2241.        
  2242.             if turtleMode then --Used for turtle control, and is helpful with Lyqyd's NSH.
  2243.                 if turtle then
  2244.                     if key == "w" then printOutput(mapturt.forward()) end
  2245.                     if key == "s" then printOutput(mapturt.back()) end
  2246.                     if key == "a" then
  2247.                         if keyAgoesRight then
  2248.                             turtleTurnRight()
  2249.                         else
  2250.                             turtleTurnLeft()
  2251.                         end
  2252.                     end
  2253.                     if key == "d" then
  2254.                         if keyAgoesRight then
  2255.                             turtleTurnLeft()
  2256.                         else
  2257.                             turtleTurnRight()
  2258.                         end
  2259.                     end
  2260.    
  2261.                     if key == "q" then printOutput(mapturt.down()) end
  2262.                     if key == "e" then printOutput(mapturt.up()) end
  2263.                    
  2264.                     if key == "i" then printOutput(turtle.placeUp()) end
  2265.                     if key == "k" then printOutput(turtle.place()) end
  2266.                     if key == "comma" then printOutput(turtle.placeDown()) end
  2267.                    
  2268.                     if key == "o" then printOutput(turtle.digUp()) end
  2269.                     if key == "l" then printOutput(turtle.dig()) end
  2270.                     if key == "period" then printOutput(turtle.digDown()) end
  2271.                    
  2272.                     if key == "p" then
  2273.                         bool, inspection = turtle.inspectUp()
  2274.                         inspection = {inspection["name"], inspection["metadata"]}
  2275.                         printOutput(inspection)
  2276.                     end
  2277.                     if key == "semiColon" then
  2278.                         bool, inspection = turtle.inspect()
  2279.                         inspection = {inspection["name"], inspection["metadata"]}
  2280.                         printOutput(inspection)
  2281.                     end
  2282.                     if key == "slash" then
  2283.                         bool, inspection = turtle.inspectDown()
  2284.                         inspection = {inspection["name"], inspection["metadata"]}
  2285.                         printOutput(inspection)
  2286.                     end
  2287.                    
  2288.                     if key == "u" then printOutput(turtle.attackUp()) end
  2289.                     if key == "j" then printOutput(turtle.attack()) end
  2290.                     if key == "m" then printOutput(turtle.attackDown()) end
  2291.  
  2292.                     if key == "tab" then printOutput(refuelTurtle(1)) end
  2293.                    
  2294.                     if key == "numPad8" then
  2295.                         local rsSide = "front"
  2296.                         if redstone.getOutput(rsSide) == false then
  2297.                             redstone.setOutput(rsSide, true)
  2298.                             printOutput(rsSide .. " RS on")
  2299.                         else
  2300.                             redstone.setOutput(rsSide, false)
  2301.                             printOutput(rsSide .. " RS off")
  2302.                         end
  2303.                     end
  2304.                     if key == "numPad2" then
  2305.                         local rsSide = "back"
  2306.                         if redstone.getOutput(rsSide) == false then
  2307.                             redstone.setOutput(rsSide, true)
  2308.                             printOutput(rsSide .. " RS on")
  2309.                         else
  2310.                             redstone.setOutput(rsSide, false)
  2311.                             printOutput(rsSide .. " RS off")
  2312.                         end
  2313.                     end
  2314.                     if key == "numPad4" then
  2315.                         local rsSide = "left"
  2316.                         if redstone.getOutput(rsSide) == false then
  2317.                             redstone.setOutput(rsSide, true)
  2318.                             printOutput(rsSide .. " RS on")
  2319.                         else
  2320.                             redstone.setOutput(rsSide, false)
  2321.                             printOutput(rsSide .. " RS off")
  2322.                         end
  2323.                     end
  2324.                     if key == "numPad6" then
  2325.                         local rsSide = "right"
  2326.                         if redstone.getOutput(rsSide) == false then
  2327.                             redstone.setOutput(rsSide, true)
  2328.                             printOutput(rsSide .. " RS on")
  2329.                         else
  2330.                             redstone.setOutput(rsSide, false)
  2331.                             printOutput(rsSide .. " RS off")
  2332.                         end
  2333.                     end
  2334.                     if key == "numPad7" then
  2335.                         local rsSide = "top"
  2336.                         if redstone.getOutput(rsSide) == false then
  2337.                             redstone.setOutput(rsSide, true)
  2338.                             printOutput(rsSide .. " RS on")
  2339.                         else
  2340.                             redstone.setOutput(rsSide, false)
  2341.                             printOutput(rsSide .. " RS off")
  2342.                         end
  2343.                     end
  2344.                     if key == "numPad9" then
  2345.                         local rsSide = "bottom"
  2346.                         if redstone.getOutput(rsSide) == false then
  2347.                             redstone.setOutput(rsSide, true)
  2348.                             printOutput(rsSide .. " RS on")
  2349.                         else
  2350.                             redstone.setOutput(rsSide, false)
  2351.                             printOutput(rsSide .. " RS off")
  2352.                         end
  2353.                     end
  2354.                 else
  2355.                     printOutput("Not a turtle.")
  2356.                 end
  2357.             end
  2358.         end
  2359.         if key == "x" then
  2360.             yield()
  2361.             return
  2362.         end
  2363.     end
  2364. end
  2365. local function captureMouseInput()
  2366.     while true do
  2367.         event, param1, x, y = os.pullEvent()
  2368.         if currentLocation == "renderMap" then --Very important.
  2369.             if event == "mouse_scroll" and y == scaleY and (x >= scaleX and x <= (7+scaleX+#string.sub(scaleFactor, 1, 12))) then
  2370.                 if param1 == -1 then
  2371.                     scaleFactor = scaleFactor + 0.01
  2372.                 elseif param1 == 1 then
  2373.                     if scaleFactor > 0.01 then
  2374.                         scaleFactor = scaleFactor - 0.01
  2375.                     else
  2376.                         scaleFactor = 0.01
  2377.                     end
  2378.                 end
  2379.                 refreshOtherConfig()
  2380.                 clearMap()
  2381.                 drawBorder()
  2382.                 drawScaleIndicator()
  2383.                 redrawMap = true
  2384.             elseif (event == "mouse_click" and param1 == 1) or (event == "monitor_touch") then
  2385.                 for a = 1, #commands do
  2386.                     if y == commandXYPoses[a][2] and (x >= commandXYPoses[a][1] and x <= (#commands[a]+commandXYPoses[a][1])) then
  2387.                         commandID = a
  2388.                         break
  2389.                     end
  2390.                 end
  2391.                 --I know the key event is supposed to return a number...
  2392.                 if commandID == 1 then os.queueEvent("key", "l") end
  2393.                 if commandID == 2 then os.queueEvent("key", "n") end
  2394.                 if commandID == 3 then os.queueEvent("key", "x") end
  2395.                 commandID = nil
  2396.             end
  2397.         elseif (currentLocation == "waypointSettings" and ((event == "mouse_click" and param1 == 1)) or (event == "monitor_touch")) then
  2398.             if y == 4 then os.queueEvent("key", "c") end -- Create waypoint
  2399.             if y == 5 then os.queueEvent("key", "d") end -- Delete waypoint
  2400.             if y == 6 then os.queueEvent("key", "r") end -- Rename waypoint
  2401.             if y == 7 then os.queueEvent("key", "o") end -- Edit config
  2402.             if y == 8 then os.queueEvent("key", "s") end -- Set scale
  2403.             if y == 9 then os.queueEvent("key", "h") end -- Show help
  2404.             if turtleMode then
  2405.                 if y == 10 then os.queueEvent("key", "t") end -- Turtle controls
  2406.                 if y == 11 then os.queueEvent("key", "p") end -- Send turtle to point
  2407.                 if y == 12 then os.queueEvent("key", "i") end -- Inspect waypoint
  2408.                 if y == 13 then os.queueEvent("key", "x") end -- Exit
  2409.             else
  2410.                 if y == 10 then os.queueEvent("key", "i") end -- Inspect waypoint
  2411.                 if y == 11 then os.queueEvent("key", "x") end -- Exit
  2412.             end
  2413.         end
  2414.     end
  2415. end
  2416. local function drawAnimations()
  2417.     local spinwheel = {"/","-","\\","|"}
  2418.     while true do
  2419.         if currentLocation == "waypointSettings" then
  2420.             sleep(0.1)
  2421.             repeat
  2422.                 term.setTextColor(colors.white)
  2423.                 drawMovingLine(3, 12, 0, 2)
  2424.             until currentLocation ~= "waypointSettings"
  2425.         end
  2426.         if currentLocation == "renderMap" then
  2427.             for a = 1, #spinwheel do
  2428.                 if currentLocation ~= "renderMap" then break end
  2429.                 event, status = os.pullEvent("gpsRequest")
  2430.                 if currentLocation == "renderMap" then
  2431.                     if colormode then
  2432.                         if turtleMode then term.setBackgroundColor(colors.lightGray) end
  2433.                         if status == true then
  2434.                             term.setTextColor(colors.green)
  2435.                         else
  2436.                             term.setTextColor(colors.orange)
  2437.                         end
  2438.                     else
  2439.                         if grayAllowed then
  2440.                             if turtleMode then term.setBackgroundColor(colors.lightGray) end
  2441.                             if status == true then
  2442.                                 term.setTextColor(colors.lightGray)
  2443.                             else
  2444.                                 term.setTextColor(colors.gray)
  2445.                             end
  2446.                         else
  2447.                             if status == true then
  2448.                                 term.setTextColor(colors.black)
  2449.                             else
  2450.                                 term.setTextColor(colors.white)
  2451.                             end
  2452.                         end
  2453.                     end
  2454.                     term.setCursorPos(scr_x,1)
  2455.                     setDefaultBackgroundColor()
  2456.                     write(spinwheel[a])
  2457.                     if currentlyConnected then
  2458.                         term.setCursorPos(1,1)
  2459.                         term.setTextColor(colors.white)
  2460.                         write("X="..math.floor(posX).." Y="..math.floor(posY).." Z="..math.floor(posZ))
  2461.                     end
  2462.                 else
  2463.                     break
  2464.                 end
  2465.             end
  2466.         end
  2467.         sleep(0)
  2468.     end
  2469. end
  2470. local function waitForResize()
  2471.     while true do
  2472.         scr_x, scr_y = term.getSize()
  2473.         event = os.pullEvent()
  2474.         if event == "monitor_resize" or event == "term_resize" and displayStuffs == true then
  2475.             scr_x, scr_y = term.getSize()
  2476.             if scr_x > 16 or scr_y > 10 then --Determines if Map is being ran on a single monitor block.
  2477.                 monitorMode = false
  2478.             else
  2479.                 monitorMode = true
  2480.             end
  2481.             mon = peripheral.find("monitor")
  2482.             if mon then
  2483.                 if monitorTextScale ~= 0.5 then
  2484.                     mon.setTextScale(0.5)
  2485.                 else
  2486.                     mon.setTextScale(1)
  2487.                 end
  2488.                 if not monitorMode then
  2489.                     mon.setTextScale(monitorTextScale)
  2490.                 else
  2491.                     mon.setTextScale(0.5)
  2492.                 end
  2493.             end
  2494.             setDefaultColors()
  2495.             term.clear()
  2496.             defineMapBorders()
  2497.             drawBorder()
  2498.             clearMap()
  2499.             renderCommands()
  2500.             redrawMap = true
  2501.         end
  2502.     end
  2503. end
  2504. local function broadcastMapData()
  2505.     local compType
  2506.     if pocket then
  2507.         compType = 1
  2508.     elseif turtle then
  2509.         compType = 2
  2510.     else
  2511.         compType = 3
  2512.     end
  2513.     while true do
  2514.         if broadcastData then
  2515.             local data = {
  2516.                 name = networkName,
  2517.                 x = posX,
  2518.                 y = posY,
  2519.                 z = posZ,
  2520.                 isFake = spoofMode,
  2521.                 comp = compType,
  2522.                 ver = mapVersion,
  2523.                 dirChar = playerChar,
  2524.             }
  2525.             local modem = peripheral.find("modem")
  2526.             if modem then
  2527.                 for a = 1, #mapProtocol do
  2528.                     modem.open(mapProtocol[a])
  2529.                     modem.transmit(mapProtocol[a],mapProtocol[a],data)
  2530.                 end
  2531.             end
  2532.         end
  2533.         sleep(0)
  2534.     end
  2535. end
  2536. local function _rawListenForMapData() --Thanks, Bomb Bloke!
  2537.     otherWaypoints = {}
  2538.     while true do
  2539.         local scr_x, scr_y = term.getSize()
  2540.         local modem = peripheral.find("modem")
  2541.         if modem then
  2542.             for a = 1, #mapProtocol do
  2543.                 modem.open(mapProtocol[a])
  2544.             end
  2545.         end
  2546.         local event, side, sendChan, repChan, data, distance = os.pullEvent("modem_message")
  2547.         if (type(data) == "table") then
  2548.             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
  2549.                 otherWaypoints[data.name] = {data.x,data.y,data.z,colors.red,data.dirChar}
  2550.                 if data.comp then
  2551.                     table.insert(otherWaypoints[data.name],data.comp)
  2552.                 else
  2553.                     table.insert(otherWaypoints[data.name],-1)
  2554.                 end
  2555.             elseif #data == 2 then
  2556.                 if (type(data[1]) == "string") and (type(data[2]) == "string") then
  2557.                     finalMessage = string.sub("<"..data[1].."> "..data[2],1,(scr_x*2)-1)
  2558.                     printOutput(finalMessage)
  2559.                 end
  2560.             end
  2561.         end
  2562.     end
  2563. end
  2564. local function listenForMapData()
  2565.     netWayPoints = {}
  2566.     while true do
  2567.         parallel.waitForAny(function() sleep(0.3) end, _rawListenForMapData)
  2568.         local seppoint = seperateMethods(otherWaypoints)
  2569.         local oldNetWayPoints = newWayPoints
  2570.         netWayPoints = {}
  2571.         for a = 1, #seppoint do
  2572.             table.insert(netWayPoints,{seppoint[a][1],table.unpack(seppoint[a][2])})
  2573.         end
  2574.         local file = fs.open(mapNetworkWaypointsFile,"w")
  2575.         file.write(textutils.serialize(netWayPoints))
  2576.         file.close()
  2577.         getConfig()
  2578.         if (oldNetWayPoints ~= netWayPoints) and displayStuffs then
  2579.             hadCleared = true
  2580.             redrawMap = true
  2581.         end
  2582.     end
  2583. end
  2584. getConfig()
  2585. local mon = peripheral.find("monitor")
  2586. if mon then
  2587.     if not monitorMode then
  2588.         mon.setTextScale(monitorTextScale)
  2589.     else
  2590.         mon.setTextScale(0.5)
  2591.     end
  2592. end
  2593. if spoofMode then --Used if spoofMode == true, if not then these are set in the event that it is later set true.
  2594.     if not fakeDir then
  2595.         print("Spoof mode is activated.")
  2596.         print("Enter current X:")
  2597.         repeat
  2598.             fakeX = tonumber(read())
  2599.         until fakeX
  2600.         print("Enter current Y:")
  2601.         repeat
  2602.             fakeY = tonumber(read())
  2603.         until fakeY
  2604.         print("Enter current Z:")
  2605.         repeat
  2606.             fakeZ = tonumber(read())
  2607.         until fakeZ
  2608.         print("Enter direction ('f' in F3 mode):")
  2609.         repeat
  2610.             fakeDir = tonumber(read())
  2611.         until fakeDir
  2612.         refreshOtherConfig()
  2613.     end
  2614. else
  2615.     fakeX = 0
  2616.     fakeY = 66
  2617.     fakeZ = 0
  2618.     fakeDir = 0 --Look at variable 'f' in DEBUG mode in minecraft. (F3)
  2619. end
  2620. mapturt = { -- I redefine the turtle moving functions to simplify things.
  2621.     ["forward"] = function() turtle.forward() fakeX=fakeX-(math.sin(90*fakeDir)) fakeZ=fakeZ+(math.cos(90*fakeDir)) refreshOtherConfig() end,
  2622.     ["back"] = function() turtle.back() fakeX=fakeX+(math.sin(90*fakeDir)) fakeZ=fakeZ-(math.cos(90*fakeDir)) refreshOtherConfig() end,
  2623.     ["up"] = function() turtle.up() fakeY=fakeY+1 refreshOtherConfig() end,
  2624.     ["down"] = function() turtle.down() fakeY=fakeY-1 refreshOtherConfig() end,
  2625.     ["turnLeft"] = function() turtle.turnLeft() fakeDir=rollOver(fakeDir-1,4) refreshOtherConfig() end,
  2626.     ["turnRight"] = function() turtle.turnRight() fakeDir=rollOver(fakeDir+1,4) refreshOtherConfig() end,
  2627. }
  2628. --[[The following...huge...tables are the title screens for advanced, grayscale, and monochrome computers.
  2629. 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!
  2630. if displayTitle then
  2631.     displayTitleScreen() --New title screens for norm/adv/gray computers in 1.3.4!
  2632. end
  2633. if autoUpdate then
  2634.     write("Automagically updating Map...") --Yes I know I misspelled that, that was on purpose.
  2635.     updateMapProgram()
  2636.     print("up to date!")
  2637. end
  2638. flashScreen(1)
  2639. local parallelFunctions = { --Look, I wanted to simplify it...
  2640.     renderMap,
  2641.     keyPress,
  2642.     captureMouseInput,
  2643.     waitForResize,
  2644.     drawAnimations,
  2645.     listenForMapData,
  2646.     broadcastMapData,
  2647. }
  2648. parallel.waitForAny(table.unpack(parallelFunctions))
  2649. end --This end is to close the runMapProgramAlready() function, so don't remove it.
  2650. function handleMapErrorMessage(errorMsg)
  2651.     local errorMessage = errorMsg
  2652.     local interjects = {
  2653.         "Oh nose!",
  2654.         "Golly gee!",
  2655.         "Eh, shit.",
  2656.         "Holy Spaghetti and Meatballs, Batman!",
  2657.         "Holy Rusted Metal, Batman!",
  2658.         "Jiminy!",
  2659.         "Leaping leptons!",
  2660.         "Cripes!",
  2661.         "Khaaaaaaannnnn!!",
  2662.         "GURU MEDITATION",
  2663.         "It appears that",
  2664.         "Exclamation!",
  2665.         "Holy Hamburger, Batman!",
  2666.         "Holy Priceless Collection of Etruscan Snoods, Batman!",
  2667.         "Holy Uncanny Photographic Mental Processes, Batman!",
  2668.         "Aw shucks!",
  2669.         "Holy Contributing to the Delinquency of Minors, Batman!",
  2670.         "Holy Remote Control Robot, Batman!",
  2671.         "Holy Euphemism!",
  2672.         "Holy Hardest Metal In The World, Batman!",
  2673.         "Holy Astringent Plum-like Fruit, Batman!",
  2674.         "Holy Greetings Cards, Batman!",
  2675.         "Holy One Track Bat Computer Mind, Batman!",
  2676.         "Sweet Zombie Jesus!",
  2677.         "Holy Batshit, Robin!",
  2678.         "Holy Mongolian Clusterfuck!",
  2679.         "Holy jumping mother o'God in a side-car with chocolate jimmies and a lobster bib!",
  2680.         "string.rep(\"NEIN \",1000)",
  2681.         "Oh, how sad.",
  2682.         "NYEH HEH HEH!!!!", --This error message fills you with DETERMINATION.
  2683.         "One of us messed up.",
  2684.         "Holy balls!",
  2685.         "ASS!",
  2686.         "You piece of shit!",
  2687.         "Damn it, Jim!",
  2688.         "Ohhh nooo...",
  2689.         "Funny splash text!",
  2690.     }
  2691.     if colormode then
  2692.         table.insert(interjects,"It's so red!")
  2693.     else
  2694.         if grayAllowed then
  2695.             table.insert(interjects,"It's so gray!")
  2696.         else
  2697.             table.insert(interjects,"It's so white!")
  2698.         end
  2699.     end
  2700.     local interjection = interjects[math.random(1, #interjects)]
  2701.     local message = {
  2702.         interjection,
  2703.         "Map v" .. mapVersion .. " has gotten",
  2704.         "an error:",
  2705.         "",
  2706.         tostring(errorMessage),
  2707.     }
  2708.     if colormode then
  2709.         term.setBackgroundColor(colors.red)
  2710.     else
  2711.         if grayAllowed then
  2712.             term.setBackgroundColor(colors.gray)
  2713.         else
  2714.             term.setBackgroundColor(colors.white)
  2715.         end
  2716.     end
  2717.     term.clear()
  2718.     scr_x, scr_y = term.getSize()
  2719.     term.setCursorPos(1,1)
  2720.     for y = 1, 2 do
  2721.         for x = 1, scr_x do
  2722.             if x % 2 == 0 then
  2723.                 if colormode then
  2724.                     term.setBackgroundColor(colors.black)
  2725.                     term.setTextColor(colors.lightGray)
  2726.                 else
  2727.                     if grayAllowed then
  2728.                         term.setBackgroundColor(colors.black)
  2729.                         term.setTextColor(colors.lightGray)
  2730.                     else
  2731.                         term.setBackgroundColor(colors.black)
  2732.                         term.setTextColor(colors.white)
  2733.                     end
  2734.                 end
  2735.                 write("x")
  2736.             else
  2737.                 if colormode then
  2738.                     term.setBackgroundColor(colors.white)
  2739.                     term.setTextColor(colors.orange)
  2740.                 else
  2741.                     if grayAllowed then
  2742.                         term.setBackgroundColor(colors.white)
  2743.                         term.setTextColor(colors.gray)
  2744.                     else
  2745.                         term.setBackgroundColor(colors.white)
  2746.                         term.setTextColor(colors.black)
  2747.                     end
  2748.                 end
  2749.                 write("X")
  2750.             end
  2751.         end
  2752.         term.setCursorPos(1,scr_y)
  2753.     end
  2754.     midPoint = {
  2755.         scr_x / 2,
  2756.         scr_y / 2,
  2757.     }
  2758.     local yoffset = 0
  2759.     for a = 1, #message do
  2760.         term.setCursorPos(midPoint[1]-math.floor(#message[a]/2)+1,a+3+yoffset)
  2761.         if a == 5 then
  2762.             if colormode then
  2763.                 term.setBackgroundColor(colors.gray)
  2764.                 term.setTextColor(colors.white)
  2765.             else
  2766.                 if grayAllowed then
  2767.                     term.setBackgroundColor(colors.black)
  2768.                     term.setTextColor(colors.white)
  2769.                 else
  2770.                     term.setBackgroundColor(colors.black)
  2771.                     term.setTextColor(colors.white)
  2772.                 end
  2773.             end
  2774.         else
  2775.             if colormode then
  2776.                 term.setBackgroundColor(colors.red)
  2777.                 term.setTextColor(colors.white)
  2778.             else
  2779.                 if grayAllowed then
  2780.                     term.setBackgroundColor(colors.lightGray)
  2781.                     term.setTextColor(colors.black)
  2782.                 else
  2783.                     term.setBackgroundColor(colors.white)
  2784.                     term.setTextColor(colors.black)
  2785.                 end
  2786.             end
  2787.         end
  2788.         if #message[a] > scr_x then
  2789.             for b = 1, math.ceil(#message[a]/scr_x) do
  2790.                 local curPosX, curPosY = term.getCursorPos()
  2791.                 local subString = string.sub(message[a],((b-1)*scr_x)+1,(b*scr_x))
  2792.                 if #subString < scr_x then
  2793.                     term.setCursorPos(midPoint[1]-math.ceil(#string.sub(message[a], scr_x)/2),a+2+yoffset)
  2794.                 else
  2795.                     term.setCursorPos(1,a+2+yoffset+(b-1))
  2796.                 end
  2797.                 print(subString)
  2798.                 if b ~= math.ceil(#message[a]/scr_x) then
  2799.                     yoffset = yoffset + 1
  2800.                 end
  2801.             end
  2802.         else
  2803.             print(message[a])
  2804.         end
  2805.     end
  2806.     if colormode then
  2807.         term.setBackgroundColor(colors.yellow)
  2808.         term.setTextColor(colors.black)
  2809.     else
  2810.         if grayAllowed then
  2811.             term.setBackgroundColor(colors.lightGray)
  2812.             term.setTextColor(colors.black)
  2813.         else
  2814.             term.setBackgroundColor(colors.white)
  2815.             term.setTextColor(colors.black)
  2816.         end
  2817.     end
  2818.     local msg = " E(x)it, or (R)estart? "
  2819.     term.setCursorPos(math.ceil(midPoint[1]-(#msg/2)),scr_y-2)
  2820.     print(msg)
  2821.     local event, key
  2822.     repeat
  2823.         sleep(0.1) --To prevent premature keypresses.
  2824.         event, key = os.pullEvent("char") --We don't need any key output other than letters.
  2825.         key = string.lower(key) --In case shift+key returns a capital key.
  2826.     until string.find("xr", key)
  2827.     local message = nil
  2828.     if key == "x" then
  2829.         return false
  2830.     elseif key == "r" then
  2831.         return true
  2832.     else
  2833.         return false
  2834.     end
  2835.     error("How did you get here??")
  2836. end
  2837. if nothing then return end
  2838. while true do
  2839.     local status, error = pcall(runMapProgramAlready) --Finally, good error handling.
  2840.     if status == false then
  2841.         local outcome = handleMapErrorMessage(error)
  2842.         if outcome == false then
  2843.             break
  2844.         end
  2845.     else
  2846.         break
  2847.     end
  2848. end
  2849. term.setTextColor(colors.white)
  2850. term.setBackgroundColor(colors.black)
  2851. term.clear()
  2852. term.setCursorPos(1,1)
  2853. print("Thanks for using Map v" .. mapVersion .. "!")
  2854. print("(code: " .. pastebinIDList[mapRelease] .. ")")
  2855. if math.random(1,64)==64 then print("May you live in interesting times!") end
  2856. sleep(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement