MarcosKoco

GPS

Jun 12th, 2021 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.99 KB | None | 0 0
  1. local Modem = {}
  2. local WirelessModemFound = false
  3. local Cor
  4.  
  5. function SaveCor()
  6.    
  7.     local file = fs.open("/.Cor.Cor", "w")
  8.     file.write(textutils.serialize(Cor))
  9.     file.close()
  10.    
  11. end
  12.  
  13. if fs.exists("/.Cor.Cor") then
  14.    
  15.     Cor = {}
  16.     local file = fs.open("/.Cor.Cor", "r")
  17.     Cor = textutils.unserialize(file.readAll())
  18.     file.close()
  19.    
  20. end
  21.  
  22. if term.isColor then
  23.    
  24.     term.clear()
  25.     term.setCursorPos(1,1)
  26.     print("Color Mode !!! ")
  27.    
  28.     local GPS_IMAGE = paintutils.loadImage('GPS_IMAGE.nfp')
  29.     paintutils.drawImage(GPS_IMAGE, 1, 1) -- Change 1 and 1 to the co-ords of where you want the top corner of the image to be.
  30.    
  31.     local Pers = peripheral.getNames()
  32.  
  33.     for i,name in pairs(Pers) do
  34.        
  35.         for j,method in pairs(peripheral.getMethods(name)) do
  36.            
  37.             if (method == 'isWireless') then
  38.                
  39.                 Modem = peripheral.wrap(name)
  40.                
  41.                 if (Modem.isWireless()) then
  42.                    
  43.                     WirelessModemFound = true
  44.                    
  45.                     break
  46.                
  47.                 else
  48.                    
  49.                     Modem = {}
  50.                    
  51.                 end
  52.                
  53.             end
  54.            
  55.         end
  56.        
  57.         if (WirelessModemFound) then
  58.            
  59.             break
  60.            
  61.         end
  62.        
  63.     end
  64.  
  65.     if not(WirelessModemFound) then
  66.        
  67.         term.clear()
  68.         term.setCursorPos(1,1)
  69.         term.setBackgroundColor(colors.red)
  70.         term.setTextColor(colors.black)
  71.         print("No Wireless Modem Found !!! ")
  72.         term.setBackgroundColor(colors.black)
  73.         term.setTextColor(colors.white)
  74.         error()
  75.        
  76.     else
  77.        
  78.         if not(Cor) then
  79.            
  80.             term.clear()
  81.             paintutils.drawImage(GPS_IMAGE, 1, 1)
  82.             term.setCursorPos(1,1)
  83.             print("Give in cordinates? Y/N")
  84.            
  85.             local event, key, isheld = os.pullEvent("key")
  86.            
  87.             if key == keys.y then
  88.                
  89.                 term.clear()
  90.                 paintutils.drawImage(GPS_IMAGE, 1, 1)
  91.                 term.setCursorPos(1,1)
  92.                 Cor = {}
  93.                 write("X corditnate: ")
  94.                 Cor.x = tonumber(read())
  95.                 write("Y corditnate: ")
  96.                 Cor.y = tonumber(read())
  97.                 write("Z corditnate: ")
  98.                 Cor.z = tonumber(read())
  99.                 SaveCor()
  100.                 term.clear()
  101.                 paintutils.drawImage(GPS_IMAGE, 1, 1)
  102.                 term.setCursorPos(1,1)
  103.                 shell.run("gps", "host", Cor.x, Cor.y, Cor.z)
  104.                
  105.             else
  106.                
  107.                 Cor = {}
  108.                 term.clear()
  109.                 paintutils.drawImage(GPS_IMAGE, 1, 1)
  110.                 term.setCursorPos(1,1)
  111.                 shell.run("gps", "host", Cor.x, Cor.y, Cor.z)
  112.                
  113.             end
  114.            
  115.         else
  116.            
  117.             term.clear()
  118.             paintutils.drawImage(GPS_IMAGE, 1, 1)
  119.             term.setCursorPos(1,1)
  120.             shell.run("gps", "host", Cor.x, Cor.y, Cor.z)
  121.            
  122.         end
  123.        
  124.     end
  125.    
  126. else
  127.    
  128.     term.clear()
  129.     term.setCursorPos(1,1)
  130.     print("Colorless Mode !!! ")
  131.    
  132.     local Pers = peripheral.getNames()
  133.  
  134.     for i,name in pairs(Pers) do
  135.        
  136.         for j,method in pairs(peripheral.getMethods(name)) do
  137.            
  138.             if (method == 'isWireless') then
  139.                
  140.                 Modem = peripheral.wrap(name)
  141.                
  142.                 if (Modem.isWireless()) then
  143.                    
  144.                     WirelessModemFound = true
  145.                    
  146.                     break
  147.                
  148.                 else
  149.                    
  150.                     Modem = {}
  151.                    
  152.                 end
  153.                
  154.             end
  155.            
  156.         end
  157.        
  158.         if (WirelessModemFound) then
  159.            
  160.             break
  161.            
  162.         end
  163.        
  164.     end
  165.  
  166.     if not(WirelessModemFound) then
  167.        
  168.         term.clear()
  169.         term.setCursorPos(1,1)
  170.         term.setBackgroundColor(colors.white)
  171.         term.setTextColor(colors.black)
  172.         print("No Wireless Modem Found !!! ")
  173.         term.setBackgroundColor(colors.black)
  174.         term.setTextColor(colors.white)
  175.         error()
  176.        
  177.     else
  178.        
  179.         if not(Cor) then
  180.            
  181.             term.clear()
  182.             term.setCursorPos(1,1)
  183.             print("Give in cordinates? Y/N")
  184.            
  185.             local event, key, isheld = os.pullEvent("key")
  186.            
  187.             if key == keys.y then
  188.                
  189.                 Cor = {}
  190.                 write("X corditnate: ")
  191.                 Cor.x = tonumber(read())
  192.                 write("Y corditnate: ")
  193.                 Cor.y = tonumber(read())
  194.                 write("Z corditnate: ")
  195.                 Cor.z = tonumber(read())
  196.                 SaveCor()
  197.                 term.clear()
  198.                 term.setCursorPos(1,1)
  199.                 shell.run("gps", "host", Cor.x, Cor.y, Cor.z)
  200.                
  201.                
  202.             else
  203.                
  204.                 Cor = {}
  205.                 term.clear()
  206.                 term.setCursorPos(1,1)
  207.                 shell.run("gps", "host", Cor.x, Cor.y, Cor.z)
  208.                
  209.             end
  210.            
  211.         else
  212.            
  213.             term.clear()
  214.             term.setCursorPos(1,1)
  215.             shell.run("gps", "host", Cor.x, Cor.y, Cor.z)
  216.            
  217.         end
  218.        
  219.     end
  220.    
  221. end
  222.  
Add Comment
Please, Sign In to add comment