Advertisement
jaklsfjlsak

福瑞导航 寻路

May 26th, 2025 (edited)
426
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.93 KB | None | 0 0
  1. on = redstone.getAnalogInput(lever)
  2.  
  3.     if on > 6 then
  4.       w.statusshowWarning("AutoPilot: Disabled")
  5.       sleep(3)
  6.     elseif on < 5 then
  7.       if fs.exists(navdatafile) then
  8.         local h = fs.open(navdatafile, "r")
  9.         local text = h.readAll()
  10.         navdata = textutils.unserialize(text)
  11.         h.close()
  12.  
  13.         for , core in ipairs(cores) do
  14.       local wrap = core.wrapper
  15.  
  16.         while true do
  17.           local status, isEnabled, state, energy = wrap.state()
  18.           if state ~= "COOLING" then break end
  19.           w.status_showWarning("Waiting Ship is in " .. state .. " mode")
  20.           sleep(5)
  21.         end
  22.  
  23.     while true do
  24.             local status, isEnabled, state, energy = wrap.state()
  25.             if state ~= "-NotDetected-" then break end
  26.             w.status_showWarning("Waiting to connect to core(s)...")
  27.             sleep(5)
  28.         end
  29.     end
  30.         --------------------------------------AUTO PILOT
  31.         for i=1,#navdata do
  32.           local move = navdata[i]
  33.  
  34.           w.status_showSuccess("Executing Jump. There are "..#navdata.." Jump(s) left.")
  35.           http.post(uri,"{"content":"
  36. yaml\\nAutopilot: Executing next node There are "..#navdata.." node(s) left to execute.
  37. "}",{['content-type']="application/json"})
  38.           table.remove(navdata,1)
  39.           if fs.exists(navbackup) then
  40.             fs.delete(navbackup)
  41.             fs.copy(navdatafile, navbackup)
  42.           end
  43.           if #navdata > 0 then
  44.             local text = textutils.serialize(navdata)
  45.             local h = fs.open(navdatafile, "w")
  46.             h.write(text)
  47.             h.close()
  48.           else
  49.             fs.delete(navdatafile)
  50.           end
  51.           ship.command("MANUAL", false)
  52.           ship.movement(move[1],move[2],move[3])
  53.           ship.rotationSteps(0)
  54.           ship.command("MANUAL", true)
  55.           sleep(10)
  56.           for i=50,0,-1 do
  57.             w.status_showWarning("Waiting for the ship to jump..."..i.."   ")
  58.             sleep(1)
  59.           end
  60.           number = #navdata + 1
  61.           http.post(uri,"{"content":"
  62. yaml\\nAutoPilot: Failed Executing node "..number..".
  63. "}",{['content-type']="application/json"})
  64.           fs.delete(navdatafile)
  65.           fs.copy(navbackup, navdatafile)
  66.           w.status_showWarning("AutoPilot: Failed Executing node " .. number)
  67.           if failping >= 0 then
  68.             http.post(uri,"{"content":""..name..""}",{['content-type']="application/json"})
  69.           end
  70.           sleep(3)
  71.           os.reboot()
  72.         end
  73.  
  74.         --------------------------------------AUTO PILOT
  75.       end
  76.     end
  77.  
  78.     -- while true do
  79.         -- local status, isEnabled, state, energy = ship.state()
  80.         -- if state == "COOLING" then
  81.             -- w.status_showWarning("Waiting Ship is in " .. state .. " mode")
  82.             -- sleep(5)
  83.         -- elseif state == "-NotDetected-" then
  84.             -- w.statusshowWarning("Waiting to connect to core(s)...")
  85.             -- sleep(5)
  86.         -- else
  87.             -- break
  88.         -- end
  89.     -- end
  90.  
  91.     for , core in ipairs(cores) do
  92.       local wrap = core.wrapper
  93.  
  94.         while true do
  95.           local status, isEnabled, state, energy = wrap.state()
  96.           if state ~= "COOLING" then break end
  97.           w.status_showWarning("Waiting Ship is in " .. state .. " mode")
  98.           sleep(5)
  99.         end
  100.  
  101.     while true do
  102.             local status, isEnabled, state, energy = wrap.state()
  103.             if state ~= "-NotDetected-" then break end
  104.             w.status_showWarning("Waiting to connect to core(s)...")
  105.             sleep(5)
  106.         end
  107.     end
  108.  
  109.     local success, message = pcall(w.run)
  110.     if not success then
  111.       print("failed with message")
  112.       print(message)
  113.       w.sleep(5)
  114.       print("rebooting...")
  115.       w.reboot()
  116.     else
  117.       if ship ~= nil then
  118.         ship.command("OFFLINE", true)
  119.         ship.enable(false)
  120.       end
  121.  
  122.       w.close()
  123.     end
  124. =================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement