Advertisement
infiniteblock

Untitled

Feb 3rd, 2021
1,153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.64 KB | None | 0 0
  1. local uri = ""
  2. local sides = peripheral.getNames()
  3. local shipcores = {}
  4. for _, side in pairs(sides) do
  5.     if peripheral.getType(side) == "warpdriveShipController" then
  6.         print("Wrapping " .. side)
  7.         table.insert(shipcores, peripheral.wrap(side))
  8.     elseif peripheral.getType(side) == "modem" then
  9.         rednet.open(side)
  10.     end
  11. end
  12. while true do
  13.     for _, shipcore in pairs(shipcores) do
  14.         local name = shipcore.name()
  15.         file = name:gsub(" ","")
  16.         local shipdim = shipcore.isInHyperspace() and "Hyperspace"or"Space/Planet"
  17.         timeout = 10
  18.         local pos = shipcore.getLocalPosition()
  19.         local x, y, z = shipcore.getLocalPosition()
  20.         repeat
  21.             sleep(0.05)
  22.             timeout = timeout - 1
  23.         until pos ~= nil or timeout < 0
  24.         if timeout < 0 then
  25.             print(name.." Position Error")
  26.         else
  27.             text = x.." "..y.." "..z
  28.             oldText = ""
  29.             local mass = shipcore.getShipSize()
  30.             local energyStored, energyMax, energyUnits = shipcore.getEnergyStatus()
  31.             if fs.exists("disk/ships/"..file) then
  32.                 local f = fs.open("disk/ships/"..file,"r")
  33.                 oldText = f.readAll()
  34.                 f.close()
  35.        end
  36.             if string.match(oldText, x) and string.match(oldText, z) then
  37.                 print(name.." No Movement.")
  38.        
  39.             else
  40.                 stt = "disk/ships/"..file
  41.                 local f2 = fs.open(stt,"w")
  42.                 f2.write("Shipname: "..name.."\n")
  43.                 if energyMax <= 2057142 then core = "Shuttle" elseif energyMax <= 41142857 then core = "Corvette" else core = "Frigate"
  44.                 end
  45.                 f2.write("Type: "..core.."\n")
  46.                 f2.write("Dimension: "..shipdim.."\n")
  47.                 f2.write("Location: "..text.."\n")
  48.                 f2.write("Energy: "..energyStored.." "..energyUnits.."\n")
  49.                 f2.write("Tons: "..mass.."\n")
  50.                 print(name.." Movment Detected")
  51.                 http.post(uri,"{\"content\":\"```yaml\\nShipname: "..name.." \\nType: "..core.." \\nDimension: "..shipdim.." \\nLocation: "..text.."\\nEnergy: "..energyStored.." "..energyUnits.."\\nTons: "..mass.."```\"}",{['content-type']="application/json"})
  52.                 output ="\1672".."CoreNET: ".."\1674".."Movement Detected.\nShipname: "..name.." \nType: "..core.." \nDimension: "..shipdim.." \nLocation: "..text.."\nEnergy: "..energyStored.." "..energyUnits.."\nTons: "..mass
  53.                 rednet.broadcast(output)
  54.                 f2.close()
  55.             end
  56.         end
  57.         sleep(5)
  58.     end
  59. end
  60. os.reboot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement